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.
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@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
--- On Sun, 7/4/10, nicolas cellier nicolas.cellier.aka.nice@gmail.com wrote:
From: nicolas cellier nicolas.cellier.aka.nice@gmail.com Subject: [Newbies] Re: Translation from old basic program To: beginners@lists.squeakfoundation.org Date: Sunday, July 4, 2010, 1:40 PM
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@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
Hi kirand, Hi Nicolas
Thought I'd give it a quick try. Here we just make a polygon and allow it to open. Heavily used the underlying goal of the problem to guide what is being done. I had fun seeing how easily I could do this in squeak. I have no idea if it meets the original purpose of the request.
If I really was feeling lazy I would have invented a Number fromUser method to simplify the input. I half expected someone to already have done so.
Lazy mans method:
n := (FillInTheBlank request: 'Enter a number' initialAnswer: '') asNumber. (plottingPoints := (0 to: 360 by: 360 /n) collect: [ :each | (Point r: 120 degrees: each) + (160@125) ] ) .
(LineMorph initializedInstance setVertices: plottingPoints ) openInWorld .
Yours in curiosity and service, --Jerome Peace
_______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
"nicolas cellier" nicolas.cellier.aka.nice@gmail.com сообщил/сообщила в новостях следующее: news:loom.20100704T192902-992@post.gmane.org...
First attempt: draw directly on Display
Maybe I choose wrong method (drawFrom:to:) or there is a mistake in a BASIC program, but a picture looks different. See here:
kirand <kirandev <at> ukr.net> writes:
"nicolas cellier" <nicolas.cellier.aka.nice <at> gmail.com> сообщил/сообщила в новостях следующее: news:loom.20100704T192902-992 <at> post.gmane.org...
First attempt: draw directly on Display
Maybe I choose wrong method (drawFrom:to:) or there is a mistake in a BASIC program, but a picture looks different. See here:
Oh, then I would say try to draw from: (xy at: i) to: (xy at: i) + (xy at: j).
Nicolas
On 04.07.2010, at 11:36, kirand wrote:
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.
Display restoreAfter: [Pen new mandala: (FillInTheBlank request: 'Enter a Number') asInteger]
- Bert -
beginners@lists.squeakfoundation.org