sketching
sketching copied to clipboard
(fill r g b) is not behaving like the processing one with negative inputs
Hi,
I translated some processing examples into sketching and I found out that (fill r g b) and fill(r, g, b) behave differently when passed negative numbers. The processing version just clamps the negative numbers to 0. The sketching version when called like this (fill 222 -1 0) crashes with:
initialization for color%: bad argument combination: 222 -1 0
My translation of the draw function vs the original processing map example.
(define (draw)
(background 0)
(let ([c (max (remap mouse-x 0 width 0 175) 0)]
[d (remap mouse-x 0 width 40 300)])
(fill 255 c 0)
(ellipse (/ width 2) (/ height 2) d d)))
vs.
void draw() {
background(0);
// Scale the mouseX value from 0 to 640 to a range between 0 and 175
float c = map(mouseX, 0, width, 0, 175);
// Scale the mouseX value from 0 to 640 to a range between 40 and 300
float d = map(mouseX, 0, width, 40, 300);
fill(255, c, 0);
ellipse(width/2, height/2, d, d);
}
I had to use the max
function to clamp the value to a non-negative one. I don't know if this is a bug or good behaviour, because imo negative values for colors should actually be an error. Clamping them to 0 is maybe a problem because it could conceal other errors.
I just wanted to document this difference in behaviour.
Edit: I confirmed the clamping behaviour from processing with the online tool openprocessing.
I think, I prefer to throw an error on negative numbers. It's feels more "Rackety".
However I have plans to add a section with a lists of differences between Sketching and Processing and this issue belongs there.
That's what I thought aswell. And I think it is a good decision. I also found out that atan2 in processing handles the inputs 0 0 which should actually be an error. Is there a document to add the differences I come across? Or do you want me to open issues with the correct tag?
For now I'll just tag the issues. Eventually I'll collect them and add a section to the manual.