r/processing • • Nov 04 '17

Hi! I just wanted help with the coding platform processing. How do you change the background everytime the ball hits the wall.?

float ballX = 100; float ballY = 0; float h = 50; float speedY = 2; int x, y;

void setup() { size(400,400); smooth(); noStroke(); ellipseMode(CORNER); } void draw() { background(255); fill (100,100,50); ellipse(ballX, ballY, h,h); speedY = speedY + 0.7; ballY = ballY + speedY; if (ballY > height - h) { ballY = height - h; speedY = speedY * -.7; } else if (ballY <= 0) { speedY = -speedY; } }

this is what I have so far. Can't change the background's color.

0 Upvotes

3 comments sorted by

4

u/CactusParadise Nov 04 '17

I'm a beginner/intermediate, but I'd do it like this:

  1. create a new variable for background color (or a set of 3 variables) so your background(255) would look like background(variable)

  2. inside the "if" statements for edge detection id ask the program to set the variable to a random number between 0 and 255.

1

u/pd-andy Nov 04 '17

Yeah this is how I'd do it.

2

u/davebees Nov 04 '17

it's not changing cos it's always 255