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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Christophe Bouchard
Hello,
I have to realize an application in squeak which is an icon generator. My questions are the following:
I have an algorithm which describe a spiral and i'd like to transcript it into squeak, but it doesn't work.
The original algorithm is:
" for( i=0; i < len; i++ ) {
  theta = 2*pi*float(i) / ppr;
  r = 0.15 * sqrt(theta);
  x = r * cos(theta);
  y = r * sin(theta);
  }
"

And what i've done but that doesn't work:
"
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).
                ]
"

But this code doesn't work and I don't know how to code my spiral algorithm and how it will be displayed on screen when running.
Thank you for your help.
Chris

Reply | Threaded
Open this post in threaded view
|

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

Damien Cassou-3
2007/4/26, Christophe Bouchard <[hidden email]>:

> Hello,
> I have to realize an application in squeak which is an icon generator. My questions are the following:
> I have an algorithm which describe a spiral and i'd like to transcript it into squeak, but it doesn't work.
> The original algorithm is:
> " for( i=0; i < len; i++ ) {
>   theta = 2*pi*float(i) / ppr;
>   r = 0.15 * sqrt(theta);
>   x = r * cos(theta);
>   y = r * sin(theta);
>   }
> "
>
> And what i've done but that doesn't work:
> "
> 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).
>                 ]
> "

What are (self sqrt:), (self cos:) and (self sin:)? Don't you mean:

spiral: len with: ppr
       | theta r x y |

       0 to: (len-1) do:
               [:i | theta = 2* Float pi * i / ppr.
                       r = 0.15 * theta sqrt.
                       x = r * theta cos.
                       y = r * theta sin.
               ]

It still won't print anything to the screen however.

--
Damien Cassou

Reply | Threaded
Open this post in threaded view
|

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

Bert Freudenberg
In reply to this post by Christophe Bouchard

On Apr 26, 2007, at 16:26 , Christophe Bouchard wrote:

> Hello,
> I have to realize an application in squeak which is an icon  
> generator. My questions are the following:
> I have an algorithm which describe a spiral and i'd like to  
> transcript it into squeak, but it doesn't work.
> The original algorithm is:
> " for( i=0; i < len; i++ ) {
>   theta = 2*pi*float(i) / ppr;
>   r = 0.15 * sqrt(theta);
>   x = r * cos(theta);
>   y = r * sin(theta);
>   }
> "
>
> And what i've done but that doesn't work:
> "
> 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).
> ]
> "
>
> But this code doesn't work and I don't know how to code my spiral  
> algorithm and how it will be displayed on screen when running.

Check out classes Scanner, Parser, and Compiler to find out about  
assignment.

Now, on the newbies list, they might have told you to use ":=".

http://lists.squeakfoundation.org/mailman/listinfo/beginners


- Bert -



Reply | Threaded
Open this post in threaded view
|

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

Damien Cassou-3
2007/4/26, Bert Freudenberg <[hidden email]>:
> Now, on the newbies list, they might have told you to use ":=".

Good catch

--
Damien Cassou

Reply | Threaded
Open this post in threaded view
|

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

Edgar J. De Cleene
In reply to this post by Christophe Bouchard



El 4/26/07 11:26 AM, "Christophe Bouchard"
<[hidden email]> escribió:

> But this code doesn't work and I don't know how to code my spiral algorithm
> and how it will be displayed on screen when running.
> Thank you for your help.
> Chris
"Draw a spiral with a pen that is 2 pixels wide."
    "Display restoreAfter: [Pen example]"



Reply | Threaded
Open this post in threaded view
|

Re[2]: A newbie needs some help in squeak (maths, algorithm and drawing)

Herbert König
Hello Chris,

>> But this code doesn't work and I don't know how to code my spiral algorithm
>> and how it will be displayed on screen when running.
>> Thank you for your help.
>> Chris
EJDC> "Draw a spiral with a pen that is 2 pixels wide."
EJDC>     "Display restoreAfter: [Pen example]"

don't know how much a newbie you are, what Edgar is saying here
translates to:

"Open a Browser, find class pen, switch to the class side and read the
class method named example."

This code also draws the spiral to the screen.


Cheers,

Herbert                            mailto:[hidden email]


Reply | Threaded
Open this post in threaded view
|

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

Gary Chambers-4
In reply to this post by Christophe Bouchard
Perhaps something more like this...


        | theta r pen p|
        pen _ Pen new.
        len _ 200.
        ppr _ 10.
        0 to: (len-1) do: [:i |
                theta _ 2 * Float pi * i / len * ppr.
                r _  i.
                p _ r * theta cos @ (r * theta sin).
                pen goto: p + Display boundingBox center]


I'm not sure what len and ppr mean to you though!

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of
Christophe Bouchard
Sent: 26 April 2007 3:27 pm
To: [hidden email]
Subject: A newbie needs some help in squeak (maths, algorithm and drawing)


Hello,
I have to realize an application in squeak which is an icon generator. My
questions are the following: I have an algorithm which describe a spiral and
i'd like to transcript it into squeak, but it doesn't work. The original
algorithm is: " for( i=0; i < len; i++ ) {
  theta = 2*pi*float(i) / ppr;
  r = 0.15 * sqrt(theta);
  x = r * cos(theta);
  y = r * sin(theta);
  }
"

And what i've done but that doesn't work:
"
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).
                ]
"

But this code doesn't work and I don't know how to code my spiral algorithm
and how it will be displayed on screen when running. Thank you for your
help. Chris


Reply | Threaded
Open this post in threaded view
|

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

Damien Cassou-3
2007/4/26, Gary Chambers <[hidden email]>:

> Perhaps something more like this...
>
>
>         | theta r pen p|
>         pen _ Pen new.
>         len _ 200.
>         ppr _ 10.
>         0 to: (len-1) do: [:i |
>                 theta _ 2 * Float pi * i / len * ppr.
>                 r _  i.
>                 p _ r * theta cos @ (r * theta sin).
>                 pen goto: p + Display boundingBox center]

with ':=' when you see '_' :-)

--
Damien Cassou

Reply | Threaded
Open this post in threaded view
|

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

Gary Chambers-4
Of course. Cut and pasted from workspace (the code saves as ":=", naturally
;-)

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Damien
Cassou
Sent: 26 April 2007 6:07 pm
To: The general-purpose Squeak developers list
Subject: Re: A newbie needs some help in squeak (maths,algorithm and
drawing)


2007/4/26, Gary Chambers <[hidden email]>:

> Perhaps something more like this...
>
>
>         | theta r pen p|
>         pen _ Pen new.
>         len _ 200.
>         ppr _ 10.
>         0 to: (len-1) do: [:i |
>                 theta _ 2 * Float pi * i / len * ppr.
>                 r _  i.
>                 p _ r * theta cos @ (r * theta sin).
>                 pen goto: p + Display boundingBox center]

with ':=' when you see '_' :-)

--
Damien Cassou


Reply | Threaded
Open this post in threaded view
|

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

K. K. Subramaniam
In reply to this post by Christophe Bouchard
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