Does python really have a logo interface? Last time I touched this programming language was in middle school almost 25 years ago!
Some years ago, I create this :
http://bytes.com/topic/python/answer...ng-tkinter-run
where a funny shape was drawn with Tkinter. Now I want to modify this program so it draws the same shape with pythons Logo interface and could be pasted directly into sculpt.
First of all, unlike Tkinter, you cannot draw a line with a start position and an end position (like line(x1,y1,x2,y2)). In Logo you specify the start direction (from 0 to 360 degrees), then you specify how long it should be drawn.
So
Expand|Select|Wrap|Line Numbers
- left(30) # rotates the pen 30 degrees
- forward(100) # draws it for 100 pixels (i guess) forward
Now, let's do some example calculations to see how it's all done:
The start coordinates is 0,0. The end coordinates of the first line is : 174.147, 274.455. This is a line right, so let's figure out the length of it, which can be done the following way:
Expand|Select|Wrap|Line Numbers
- math.sqrt( (174.147 - 0)**2 + (274.455 - 0)**2 )
Expand|Select|Wrap|Line Numbers
- math.atan2(275.455-0,174.147)
atan2 return the angle in radians, but since Logo is using degrees, we have to convert to degrees. This is done by the following way:
Expand|Select|Wrap|Line Numbers
- (180.0 / math.pi)*rad
Expand|Select|Wrap|Line Numbers
- import math
- import turtle # this seems to be Logo in python
- t = turtle.Turtle() # create an istance of it
- t.speed(0) # full speed
- theta = 0.015
- sx = 0
- sy = 0
- while(theta<4*3.1415):
- xt = math.sin(theta * 10) * 270 + 300
- yt = math.cos(theta * 9.5) * 270 + 300
- nthet = xt / 30 + yt / 30
- yp = yt + math.sin(nthet) * 20
- xp = xt + math.cos(nthet) * 20
- gx = math.sqrt( (sx/2 - xp/2)**2 + (sy/2 - yp/2)**2) # the distance of the line
- tx = (xp/2.0) - (sx/2.0)
- ty = (yp/2.0) - (sy/2.0)
- cx = math.atan2(-ty,tx)*(180.0 / math.pi) # the angle between the line and the horizontal axis
- t.left(cx) # set the angle
- t.forward(gx) # move forwared the appropriate amount
- t.left(-1*cx) # reset the angle, so next time, we start off at scratch
- sx = xp
- sy = yp
- theta+=0.004