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.

Processing - Java Swing I need help making circles go from black

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:

at the top, gradually turning white to the bottom, following the y

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!