A newbie needs some help in squeak (maths, algorithm and drawing)

subbukk subbukk at gmail.com
Thu Apr 26 18:21:30 UTC 2007


On Thursday 26 April 2007 7:56 pm, Christophe Bouchard wrote:
> Hello,
> spiral: len with: ppr
>
> 	| theta r x y |
>
> 	0 to: (len-1) do:
> 		[:i | theta = 2* Float pi * i / ppr.
> 			r = 0.15 * (self sqrt: theta).
> 			x = r * ( self cos: theta).
> 			y = r * ( self sin: theta).
> 		]
> "
I am not sure what ppr means, but theta calculation doesn't appear right. 
Here is an example that you can type into Workspace and run:

turns := 3.
radius := 90.
points := 30.
p := Pen new down.
middle := p location.

0 to: (turns-1) do: [ :n |
	1 to: points do: [ :i |
		theta := 2.0 * Float pi * i / points.
		r := radius * (n + (theta/(2.0*Float pi))).
		x := r * theta cos.
		y := r * theta sin.
		p goto: (middle + (x @ y)). ] ]

BTW, in Squeak,the convention is to think of spiral from the pen's 
viewpoint and compute steps and turns. For a spiral, the pen would move 
forward by increasing amounts for every turn, so the logic becomes:

n := radius/points.
angle := 360/points.
s := n.
1 to: turns do: [ :t | 
	1 to: points do: [ :i |
		p go: s; turn: angle.
                s := s + n ] ].


Hope this helps .. Subbu



More information about the Squeak-dev mailing list