sketching
sketching copied to clipboard
mouse-x, mouse-y, pmouse-x, and pmouse-y reset to 0 when the mouse leaves the canvas
Writing a simple drawing example that connects mouse positions with a line. When my mouse leaves the canvas, the mouse positions all become 0 and a line is drawn to the corner. I checked the java version of Processing and the values are preserved when the mouse is off the canvas.
#lang sketching
(define (setup)
(size 480 120)
(smoothing 'smoothed)
(background 200)
(stroke 0 102)
(stroke-weight 4)
(set-frame-rate! 60)
)
(define (draw)
(line mouse-x mouse-y pmouse-x pmouse-y)
(display (list mouse-x mouse-y pmouse-x pmouse-y))
)
`
Thanks for the bug report. Preserving the previous values (rather than using 0) makes more sense.
I'll see why it happens.
There seems to be a difference between Windows and macOS here.

I'll look for a tester for Linux.
Hi Eric,
I have commited what I hope is a fix to this issue. I have tested it on Windows 10 on DrRacket 8.4.
Let me know if the fix works as expected - or if it needs further adjustments.
/Jens Axel
Hello,
Sorry for the delayed reply. This fix works as expected on Windows 7 / DrRacket 8.2
I feel like a related issue still exists.
Was trying to recreate this simple processing sketch
I believe the reason this breaks is from mouse-x having an initial value of 0.
The example works for me when I constrain the value of mouse-x.
`#lang sketching (define (setup) (size 120 120) (smoothing 'smoothed) (set-frame-rate! 60) (background 200) )
(define (draw)
(translate mouse-x mouse-y) (scale (/ (constrain mouse-x 1 120) 60.0)) (rect -15 -15 30 30) )`
Hi @ericcervin
Thanks for the report.
I see the same as you on Windows.
I don't think the (0,0) is to blame - at least not directly.
Reading the source of Processing, I believe they too use (0,0) as a default.
I also looked at the implemented of scale
, but it looks fine.
For now your solution with constrain
looks as the best temporary fix.
I'll think about some more about the issue.
Cool. This was my one little bug report from the Racketcon Hackathon