Page 1 of 1

Squashed Turtles

Posted: Sat Feb 25, 2017 9:23 pm
by richmond62
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:
Screen Shot 2017-02-25 at 10.17.35 pm.png
Turtle widget hidden
Screen Shot 2017-02-25 at 10.17.35 pm.png (5.1 KiB) Viewed 12133 times
Screen Shot 2017-02-25 at 10.17.46 pm.png
Turtle widget visible
Screen Shot 2017-02-25 at 10.17.46 pm.png (9.02 KiB) Viewed 12133 times
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

Posted: Sat Feb 25, 2017 9:35 pm
by Amigatech
Could it be that the drag speed varies depending on the angle?

Re: Squashed Turtles

Posted: Sat Feb 25, 2017 9:45 pm
by richmond62
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.

Re: Squashed Turtles

Posted: Sat Feb 25, 2017 10:34 pm
by [-hh]
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.

Re: Squashed Turtles

Posted: Sat Feb 25, 2017 11:34 pm
by mwieder
Well... you *did* create a pentagon, so I'd say "mission accomplished". :P

Re: Squashed Turtles

Posted: Sat Feb 25, 2017 11:58 pm
by [-hh]
Although Mark is right, as always:
Watch the angles, in case you wish to turtle along a regular pentagon.
regularPentagon.png
regularPentagon.png (18.48 KiB) Viewed 12070 times

Re: Squashed Turtles

Posted: Sun Feb 26, 2017 12:14 am
by richmond62
This may only give you an idea of the inner workings of my mind rather than anything else.
SqT.png
Only the 2 buttons outlined in red do any good.

Re: Squashed Turtles

Posted: Sun Feb 26, 2017 5:36 am
by [-hh]
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).

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
Hope this is the easy way you try to build upon.
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

Re: Squashed Turtles

Posted: Sun Feb 26, 2017 5:26 pm
by richmond62
Thank you very much for the help.
NT.gif
Stack removed as replaced by updated and improved version.

Re: Squashed Turtles

Posted: Sun Feb 26, 2017 7:56 pm
by richmond62
And so it goes.
NT2.gif
Stack removed as replaced by updated and improved version.

Re: Squashed Turtles

Posted: Sun Feb 26, 2017 10:06 pm
by richmond62
Ad nauseam.
NT3.png
Stack removed as replaced by updated and improved version.

Re: Squashed Turtles

Posted: Sun Feb 26, 2017 10:37 pm
by richmond62
JRMt.png

Re: Squashed Turtles

Posted: Mon Feb 27, 2017 6:59 pm
by richmond62
Pen Up, Pen Down, various niggly things.
NT4.png
Stack removed as replaced by updated and improved version.

Re: Squashed Turtles

Posted: Tue Feb 28, 2017 8:59 pm
by richmond62
Manually repositionable Turtle.