Question
Processing - Java Swing I need help making circles go from black at the top, gradually turning white to the bottom, following the y coordinate
Processing - Java Swing
I need help making circles go from black at the top, gradually turning white to the bottom, following the y coordinate of your cursor (mouseY). It also needs to work with any size window, which is the problem.
Here is my code:
// declaring global variables int diameter;
// max size of circles final int MAX_SIZE = 100;
// setup block void setup() { size(500, 500); background(0); }
// draw block void draw() { diameter = (MAX_SIZE * mouseX) / width; fill(mouseY % 255); ellipse(mouseX, mouseY, diameter, diameter); }
The problem is this:
On a 500x500 canvas, the fill will reach 255 (White) in the middle, and then reset going from 0 (Black) to 255 (White) again.
I need to be able to find a way to allow the whole height of the canvas be compatible with the range of 0 --> 255, so the gradual change from black to white spans the entire window, instead of stopping halfway through (because of the 500x500 height, 255 * 0 = 0 (black)).
Thank you so much to anyone who can be able to help!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started