<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br><br>--- On <b>Sun, 7/4/10, nicolas cellier <i><nicolas.cellier.aka.nice@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: nicolas cellier <nicolas.cellier.aka.nice@gmail.com><br>Subject: [Newbies] Re: Translation from old basic program<br>To: beginners@lists.squeakfoundation.org<br>Date: Sunday, July 4, 2010, 1:40 PM<br><br><div class="plainMail">kirand <kirandev <at> ukr.net> writes:<br><br>> <br>> Hi!<br>> <br>> Is anybody remember basic?<br>> <br>> I am a beginner and cant understand how to make this program in Smalltalk. I <br>> found it in old magazine from 80-th years :)<br>> So, this is the program. It makes interest graphics.<br>> <br>> 10 INPUT "Enter a number"; N<br>> 20 DIM X(N), Y(N)<br>> 30 R =
120<br>> 40 DT = 2 * 3,1416 /N<br>> 50 T = 0<br>> 60 FOR I = 1 TO N<br>> 70 T = T + DT<br>> 80 X(I) = 160 + R*COS (T): Y(I) = 125 - R*SIN (T)<br>> 90 NEXT I<br>> 95 CLSZ<br>> 100 FOR I = 1 TO N-1<br>> 110 FOR J= I+1 TO N<br>> 120 PLOT X(I), Y(I), 3<br>> 130 LINE X(J), Y(J)<br>> 140 NEXT J<br>> 150 NEXT I<br>> 160 STOP<br>> <br>> Some remarks can help. PLOT+LINE is BitBlt>>drawFrom:to:. DIM X(N), Y(N) is <br>> PointArray instance.<br>> <br>> If anobody make it pls give me a code to see how. <br>> <br><br>First attempt: draw directly on Display<br><br>| n xy r dt brush |<br>n := FillInTheBlank request: 'Enter a number' initialAnswer: ''.<br>n := Number readFrom: n. "Transform the String into a Number" <br>xy := Array new: n.<br>dt := Float twoPi / n.<br>r := 120.<br>1 to: n do: [:i | <br> "Mind the order or operations here, Smalltalk interprets left to right"<br>
xy at: i put: ((i*dt) cos * r +160) @ ((i*dt) sin negated * r + 125)].<br>brush := Form extent: 3 @ 3.<br>brush fillBlack.<br>1 to: n-1 do: [:i | <br>i+1 to: n do: [:j | <br> Display<br> drawLine: brush<br> from: (xy at: i)<br> to: (xy at: j)<br> clippingBox: Display boundingBox<br> rule: Form paint<br> fillColor: nil]].<br><br>Second attempt: draw on a Form, copy the Form on Display,<br>restore the Display after 10 seconds.<br><br>| n xy r dt form brush |<br>n := (FillInTheBlank request: 'Enter a number' initialAnswer: '') asNumber.<br>dt := Float twoPi / n.<br>r := 120.<br>xy := (1 to: n) collect: [:i | <br> ((i*dt) cos * r +160) @ ((i*dt) sin negated * r + 125)].<br>form := Form extent:
300@300.<br>brush := Form extent: 1 @ 1.<br>brush fillBlack.<br>1 to: n-1 do: [:i | <br>i+1 to: n do: [:j | <br> form<br> drawLine: brush<br> from: (xy at: i)<br> to: (xy at: j)<br> clippingBox: form boundingBox<br> rule: Form paint<br> fillColor: nil]].<br>form displayOn: Display.<br>[(Delay forSeconds: 10) wait. Display restore] fork<br><br>Nicolas<br><br>Hi kirand, Hi Nicolas<br><br>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.<br><br>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.<br><br>Lazy mans method:<br><br>n := (FillInTheBlank request: 'Enter a number' initialAnswer: '') asNumber.<br>(plottingPoints :=<br>(0 to: 360 by: 360 /n) collect: [ :each | (Point r: 120 degrees: each) + (160@125) ] ) .<br><br>(LineMorph initializedInstance setVertices: plottingPoints )<br>openInWorld .<br><br><br>Yours in curiosity and service, --Jerome Peace<br><br><br>_______________________________________________<br>Beginners mailing list<br><a ymailto="mailto:Beginners@lists.squeakfoundation.org" href="/mc/compose?to=Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br><a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br></div></blockquote></td></tr></table><br>