Squashed Turtles

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Squashed Turtles

Post by richmond62 » Sat Feb 25, 2017 9:23 pm

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 9788 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 9788 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 . . .

Amigatech
Posts: 18
Joined: Mon Jan 18, 2010 12:55 am

Re: Squashed Turtles

Post by Amigatech » Sat Feb 25, 2017 9:35 pm

Could it be that the drag speed varies depending on the angle?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Sat Feb 25, 2017 9:45 pm

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.
Last edited by richmond62 on Sun Feb 26, 2017 3:07 pm, edited 1 time in total.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Squashed Turtles

Post by [-hh] » Sat Feb 25, 2017 10:34 pm

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.
shiftLock happens

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Squashed Turtles

Post by mwieder » Sat Feb 25, 2017 11:34 pm

Well... you *did* create a pentagon, so I'd say "mission accomplished". :P

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Squashed Turtles

Post by [-hh] » Sat Feb 25, 2017 11:58 pm

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 9725 times
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Sun Feb 26, 2017 12:14 am

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.
Attachments
Turtle1.livecode.zip
Here's the stack
(6.29 KiB) Downloaded 282 times

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Squashed Turtles

Post by [-hh] » Sun Feb 26, 2017 5:36 am

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
Attachments
turtledPentagon.png
Turtled with the scripts above.
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Sun Feb 26, 2017 5:26 pm

Thank you very much for the help.
NT.gif
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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Sun Feb 26, 2017 7:56 pm

And so it goes.
NT2.gif
Stack removed as replaced by updated and improved version.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Sun Feb 26, 2017 10:06 pm

Ad nauseam.
NT3.png
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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Sun Feb 26, 2017 10:37 pm

JRMt.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Mon Feb 27, 2017 6:59 pm

Pen Up, Pen Down, various niggly things.
NT4.png
Stack removed as replaced by updated and improved version.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9383
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Squashed Turtles

Post by richmond62 » Tue Feb 28, 2017 8:59 pm

Manually repositionable Turtle.
Attachments
NLCT.livecode.zip
Here's the stack.
(121.66 KiB) Downloaded 282 times

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”