[Newbies] Re: Translation from old basic program
nicolas cellier
nicolas.cellier.aka.nice at gmail.com
Sun Jul 4 17:40:57 UTC 2010
kirand <kirandev <at> ukr.net> writes:
>
> Hi!
>
> Is anybody remember basic?
>
> I am a beginner and cant understand how to make this program in Smalltalk. I
> found it in old magazine from 80-th years :)
> So, this is the program. It makes interest graphics.
>
> 10 INPUT "Enter a number"; N
> 20 DIM X(N), Y(N)
> 30 R = 120
> 40 DT = 2 * 3,1416 /N
> 50 T = 0
> 60 FOR I = 1 TO N
> 70 T = T + DT
> 80 X(I) = 160 + R*COS (T): Y(I) = 125 - R*SIN (T)
> 90 NEXT I
> 95 CLSZ
> 100 FOR I = 1 TO N-1
> 110 FOR J= I+1 TO N
> 120 PLOT X(I), Y(I), 3
> 130 LINE X(J), Y(J)
> 140 NEXT J
> 150 NEXT I
> 160 STOP
>
> Some remarks can help. PLOT+LINE is BitBlt>>drawFrom:to:. DIM X(N), Y(N) is
> PointArray instance.
>
> If anobody make it pls give me a code to see how.
>
First attempt: draw directly on Display
| n xy r dt brush |
n := FillInTheBlank request: 'Enter a number' initialAnswer: ''.
n := Number readFrom: n. "Transform the String into a Number"
xy := Array new: n.
dt := Float twoPi / n.
r := 120.
1 to: n do: [:i |
"Mind the order or operations here, Smalltalk interprets left to right"
xy at: i put: ((i*dt) cos * r +160) @ ((i*dt) sin negated * r + 125)].
brush := Form extent: 3 @ 3.
brush fillBlack.
1 to: n-1 do: [:i |
i+1 to: n do: [:j |
Display
drawLine: brush
from: (xy at: i)
to: (xy at: j)
clippingBox: Display boundingBox
rule: Form paint
fillColor: nil]].
Second attempt: draw on a Form, copy the Form on Display,
restore the Display after 10 seconds.
| n xy r dt form brush |
n := (FillInTheBlank request: 'Enter a number' initialAnswer: '') asNumber.
dt := Float twoPi / n.
r := 120.
xy := (1 to: n) collect: [:i |
((i*dt) cos * r +160) @ ((i*dt) sin negated * r + 125)].
form := Form extent: 300 at 300.
brush := Form extent: 1 @ 1.
brush fillBlack.
1 to: n-1 do: [:i |
i+1 to: n do: [:j |
form
drawLine: brush
from: (xy at: i)
to: (xy at: j)
clippingBox: form boundingBox
rule: Form paint
fillColor: nil]].
form displayOn: Display.
[(Delay forSeconds: 10) wait. Display restore] fork
Nicolas
More information about the Beginners
mailing list