Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fill r g b) is not behaving like the processing one with negative inputs #39

Open
Ecsodikas opened this issue Jan 11, 2022 · 3 comments
Labels
difference Mentions difference between Processing and Racket documentation Improvements or additions to documentation

Comments

@Ecsodikas
Copy link
Contributor

Ecsodikas commented Jan 11, 2022

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.

@Ecsodikas Ecsodikas changed the title (fill r g b) is not behaving like the processing one with negtaive intputs (fill r g b) is not behaving like the processing one with negative inputs Jan 11, 2022
@soegaard
Copy link
Owner

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.

@soegaard soegaard added difference Mentions difference between Processing and Racket documentation Improvements or additions to documentation labels Jan 11, 2022
@Ecsodikas
Copy link
Contributor Author

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?

@soegaard
Copy link
Owner

For now I'll just tag the issues. Eventually I'll collect them and add a section to the manual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difference Mentions difference between Processing and Racket documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants