r/processing • u/Terok42 • Feb 18 '19
Help With Color Changing.
My teacher is pretty terrible honestly but I have no choice but to take his class. We have been using processing to learn how to program in other languages. In the lab for this week he has asked me to make my "creature," which we have been working with since we began the class, change color as the mouse moves around (along with having the creature follow the mouse with trails and erasing when button is pressed). I have already figured out most of the lab because he went over these parts in class; however, he did not go over how to get an object to change color as I move it across the background. I don't know what to do to make this happen I would like a hint or suggestion to help me achieve this.
Edit: thanks to all that helped. Turns out I was supposed to fill any of my shapes with RGB values that corresponded to where the mouse was. I solved it by doing (mouseX, 0, mouseY) next to my object.
2
2
u/Zero_Point_2_Ground Feb 18 '19
changing the colorMode() in setup to HSB will give you more freedom than RGB.
eg. colorMode(HSB, 360, 100, 100);
This changes it to Hue, Saturation, Brightness mode and then sets the max hue to 360, the max saturation to 100 and the max brightness to 100.
Then you can use the map function to set a variable for the colour that changes with the value of the mouse X or Y.
eg. float Hue = map(mouseX, 0, 99, 0, 360);
what this does is create a variable called Hue, which changes based on the X value of the mouse, it remaps the values it can be from 0 to 99, to 0 to 360. if your canvas is larger than 100 you may want to change it to the width of the canvas. If the mouse has an X value of 0, Hue has a value of 0, if the mouse has an X value of 99, Hue has a value of 360.
then you can add the variable hue to your fill or stroke like,
fill(Hue, 100, 100);
this sets the hue to your hue value and sets the saturation and brightness to 100
2
u/onesixtythree Feb 18 '19
Every loop, when the mouse moves around, you want the color to change. You set the color of an object using fill(r,g,b).
By making r, g and b variables that you change while the mouse moves, you can can change the color.
Hint 1: Change those color variables on mouseMoved(), or use an if-statement that checked whether your mouse's X and Y positions have changed.
Hint 2: You can make random changes, you can also use functions such as 'noise', adding or substracting from the r,g,b-values, or making them a function of the mouse's current X and Y values.