soegaard / sketching

A Racket library for creative drawings and animations. Inspired by Processing.
110 stars 10 forks source link

mouse-x, mouse-y, pmouse-x, and pmouse-y reset to 0 when the mouse leaves the canvas #76

Open ericcervin opened 2 years ago

ericcervin commented 2 years ago

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))
)
`
ericcervin commented 2 years ago

mouse1

soegaard commented 2 years ago

Thanks for the bug report. Preserving the previous values (rather than using 0) makes more sense.

I'll see why it happens.

ericcervin commented 2 years ago

mouse3

soegaard commented 2 years ago

There seems to be a difference between Windows and macOS here.

image

I'll look for a tester for Linux.

soegaard commented 2 years ago

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

ericcervin commented 2 years ago

Hello,

Sorry for the delayed reply. This fix works as expected on Windows 7 / DrRacket 8.2

ericcervin commented 1 year ago

I feel like a related issue still exists.

Was trying to recreate this simple processing sketch

image

I believe the reason this breaks is from mouse-x having an initial value of 0.

image

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) )`

soegaard commented 1 year ago

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.

ericcervin commented 1 year ago

Cool. This was my one little bug report from the Racketcon Hackathon