Backwards milliseconds to change colour
in
Programming Questions
•
7 months ago
Hey guys, I have a sketch that's using wave gradients to create pretty patterns/colours on the screen and then placing squares over the top that increase in size and randomness as time goes on. What I'd like to be able to do is have the colour of the squares change with regards to time but I would like if possible to change say the red (of the RBG) from 0 to 225 and 225 back to 0. Is this possible? At the moment I'm changing the red via millis() / 1000 from 0 to 225 so that it doesn't change too quickly but I can't figure out a way to get the colour to go backwards the opposite way.
Any ideas?
Any ideas?
- float angle = 0;
float px = 0, py = 0;
float amplitude = 30;
float frequency = 0;
float fillGap = 2.5;
int m;
int m2;
int m3;
int mins;
int mins10;
color c;
void setup() {
size(500, 500);
background(200);
}
void draw() {
m = millis() / 100;
m2 = millis() / 1000;
m3 = millis() / 500;
mins = millis() / 1000;
mins10 = millis() / 10000;
for (int i =- 75; i < height+75; i++){
// Reset angle to 0, so waves stack properly
angle = 0;
// Increasing frequency causes more gaps
frequency+=.002;
for (float j = 0; j < width+75; j++){
py = i + sin(radians(angle+frameCount*0.1)) * amplitude;
angle += frequency;
c = color(abs(py-i)*m2/amplitude, 255-abs(py-i)*m/amplitude, j*(255.0/(width+50)), m3);
// Hack to fill gaps. Raise value of fillGap if you increase frequency
for (int filler = 0; filler < fillGap; filler++){
set(int(j-filler), int(py)-filler, c);
set(int(j), int(py), c);
set(int(j+filler), int(py)+filler, c);
}
}
}
fill (random(mins), random(mins), random(mins));
rect(random(mins*10),random(mins*10),mins,mins);
float xspeed = m; // Speed of the shape
float yspeed = m2; // Speed of the shape
println(mins);
}
1