[plt-scheme] Re: Draw and save coordinates on every mouse event on canvas?
Okay. In world.ss you will soon find the note "use universe".
On Jun 10, 2009, at 5:50 PM, Captain___nemo wrote:
>
> oppss..I am sorry that I forgot to answer your question :( That
> warning is written in document of "draw.ss".
>
> regards.
>
> On Jun 11, 1:55 am, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
>> Here is a solution:
>>
>> #lang scheme
>>
>> (require 2htdp/universe)
>>
>> ;; World = [Listof (list Nat Nat)]
>> (define mt (empty-scene 200 200))
>> (define col "red")
>> (define DOT (circle 3 "solid" col))
>>
>> (define (click w x y ke)
>> (cond
>> [(mouse=? "button-down" ke)
>> (cons (list x y) w)]
>> [else w]))
>>
>> (define (render w0)
>> (local ((define (cnt w a) (foldl (lambda (f a) (list f (apply ln+
>> f a))) a w))
>> (define (dot s p) (place-image DOT (first p) (second p)
>> s))
>> (define (ln+ p q s)
>> (add-line s (first p) (second p) (first q) (second q)
>> col))
>> (define dots (foldr (lambda (f r) (dot r f)) mt w0)))
>> (cond
>> [(empty? w0) mt]
>> [else (second (cnt (rest w0) (list (first w0) (dot dots (first
>> w0)))))])))
>>
>> (big-bang '() (on-mouse click) (on-draw render))
>>
>> But this solution will give you away in case this is homework. To
>> prove that this isn't homework, you need to point us to the place
>> where our manuals recommend using world.ss.
>>
>> -- Matthias
>>
>> On Jun 10, 2009, at 6:53 AM, Captain___nemo wrote:
>>
>>
>>
>>
>>
>>> Hi,
>>> I am newbie in scheme, just started yesterday. So, please don't mind
>>> if I am overlooking anything simple.
>>
>>> I want to draw circular points on every click on the drawing window
>>> (or canvas). Also I want to save the coordinates in an array. After
>>> every click a connecting line should be drawn (from last point)
>>> and so
>>> on.
>>
>>> Now, I don't understand how I should put a canvas. As I can see in
>>> Dr.Scheme manual , it is recommended to use world.ss. But I don't
>>> understand how will I get the coordinates and save in an array? Also
>>> how that line can be drawn?
>>
>>> Any suggestion is appreciated.
>>
>>> Thanks in advance.
>>> _________________________________________________
>>> For list-related administrative tasks:
>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme