Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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:

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions