Squashed Turtles
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Squashed Turtles
So: having looked at other people's ways of implementing Turtle Graphics in LiveCode I have decided to
be bloody-minded (as usual) and implement them in my way: which, in theory at least, seems extremely simple.
However I have run up against something a bit odd:
I attempted to get the "Turtle" to draw a pentagon, and performed a
"set the angle of widget "TURTLE" to 72" and, so on by increments of 72 five times
but, as can clearly be seen from the snapshots; everything is squashed . . .
be bloody-minded (as usual) and implement them in my way: which, in theory at least, seems extremely simple.
However I have run up against something a bit odd:
I attempted to get the "Turtle" to draw a pentagon, and performed a
"set the angle of widget "TURTLE" to 72" and, so on by increments of 72 five times
but, as can clearly be seen from the snapshots; everything is squashed . . .
Re: Squashed Turtles
Could it be that the drag speed varies depending on the angle?
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
There is no drag.
Even if I do wear a kllt!
1. The widget has its angle set.
2. The widget is moved.
3. A graphic is created which draws a line from the old location to the new location of the widget.
Even if I do wear a kllt!
1. The widget has its angle set.
2. The widget is moved.
3. A graphic is created which draws a line from the old location to the new location of the widget.
Last edited by richmond62 on Sun Feb 26, 2017 3:07 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Squashed Turtles
Your angles are certainly not all equal to 72 degrees.
Please post the script, so we can look at it. Else it's just guessing.
Please post the script, so we can look at it. Else it's just guessing.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Squashed Turtles
Well... you *did* create a pentagon, so I'd say "mission accomplished".
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Squashed Turtles
Although Mark is right, as always:
Watch the angles, in case you wish to turtle along a regular pentagon.
Watch the angles, in case you wish to turtle along a regular pentagon.
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
This may only give you an idea of the inner workings of my mind rather than anything else.
Only the 2 buttons outlined in red do any good.
Only the 2 buttons outlined in red do any good.
- Attachments
-
- Turtle1.livecode.zip
- Here's the stack
- (6.29 KiB) Downloaded 282 times
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Squashed Turtles
Richmond,
you compute too much in between!! In principle you have/need two commands
= one sets the angle of your widget,
= one moves the widget a given length in the given direction
(the length is the radius of a circle around current location).
I tried to write this as follows close to your style
(for the card's script, at about 20 lines for the two commands).
Hope this is the easy way you try to build upon.
Using this for example a regular Pentagon is drawn as follows.
you compute too much in between!! In principle you have/need two commands
= one sets the angle of your widget,
= one moves the widget a given length in the given direction
(the length is the radius of a circle around current location).
I tried to write this as follows close to your style
(for the card's script, at about 20 lines for the two commands).
Code: Select all
-- AA is the FROM-angle (optional)
-- K is the CHANGE (pos=rightTurn or neg=leftTurn) to that angle
on turnBY K, AA
if AA is empty then put the angle of widget "TURTLE" into AA
add K to AA; put AA mod 360 into AA; if AA < 0 then add 360 to AA
set the angle of widget "TURTLE" to AA
end turnBY
-- x0 and y0 are the start points (optional)
-- R is the length to go forward in the turtle's path
on forwardzBy R,x0,y0
if x0 is empty then put item 1 of the loc of widget "TURTLE" into x0
if y0 is empty then put item 2 of the loc of widget "TURTLE" into y0
if there is no grc "TurtleCurve" then createTurtlePath "TurtleCurve"
put the angle of widget "TURTLE" into AA
add 90 to AA --> so that the angle zero is at high noon
put round(x0 - R*cos(AA*pi/180)) into newX
put round(y0 - R*sin(AA*pi/180)) into newY
put the points of grc "TurtleCurve" into PTS
put cr & (newX,newY) after PTS
put PTS into fld "LYNES" --> in case you wish to edit points
set points of grc "TurtleCurve" to PTS
set hilite of widget "TURTLE" to true -- just for fun
move widget "TURTLE" to line -1 of PTS in 1 second
set hilite of widget "TURTLE" to false
end forwardzBy
on createTurtlePath gg
create grc gg; set style of grc gg to "polygon"
set layer of widget "TURTLE" to "top"
put the width of widget "TURTLE" into twd
set foreColor of grc gg to "yellow" --> adjust here
set lineSize of grc gg to twd --> adjust here
set blendLevel of grc gg to 62 --> adjust here
end createTurtlePath
Using this for example a regular Pentagon is drawn as follows.
Code: Select all
-- PENTAGON: Has 5 turns of 360/5 = 72 degrees and
-- 5 sides of equal length, say L = 200
on mouseUp
if there is no grc "TurtleCurve" then createTurtlePath "TurtleCurve"
set loc of widget "TURTLE" to the loc of this card
set the angle of widget "TURTLE" to 0
set points of grc "TurtleCurve" to the loc of this card -- start point
turnBy 54 -- startangle, half the vertices angle
repeat 5
turnBy 72; forwardzBy 200
end repeat
turnBy -54 -- back to angle zero
end mouseUp
shiftLock happens
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
Thank you very much for the help.
Stack removed as replaced by updated and improved version.
Stack removed as replaced by updated and improved version.
Last edited by richmond62 on Sun Feb 26, 2017 7:57 pm, edited 2 times in total.
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
And so it goes.
Stack removed as replaced by updated and improved version.
Stack removed as replaced by updated and improved version.
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
Ad nauseam.
Stack removed as replaced by updated and improved version.
Stack removed as replaced by updated and improved version.
Last edited by richmond62 on Mon Feb 27, 2017 6:57 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
Pen Up, Pen Down, various niggly things.
Stack removed as replaced by updated and improved version.
Stack removed as replaced by updated and improved version.
-
- Livecode Opensource Backer
- Posts: 9383
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Squashed Turtles
Manually repositionable Turtle.
- Attachments
-
- NLCT.livecode.zip
- Here's the stack.
- (121.66 KiB) Downloaded 282 times