xxxxxxxxxx
//Edited and reworked version of wave code from OpenProcesing by Mohini Dutta
//the spacing needs to be lower to make the grid look similar to the one you did manually.
int xspacing = 20;
int yLoc = 0;
int w;
//colors
float red= 255;
float yellow= 0;
float theta = 0.0;
float amplitude = 70.0;
float period = 1200.0;
float dx;
//array of y locations for all the ball waves
float[] yvalues;
void setup() {
size (1000, 500);
colorMode(HSB, 255);
noStroke();
w = width+ 320;
dx = (TWO_PI / period) * xspacing;
yvalues = new float[w/xspacing];
}
void draw() {
background(0);
renderWave();
calcWave();
}
void calcWave() {
//Movement of everything vertically
theta += 0.01;
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
//make it wavy
x+=dx;
}
}
void renderWave() {
//drawing a grid of circles using for loop
//(look at grid of circles code from class)
for (int x = 0; x < yvalues.length; x++) {
for (int i = 0; i < height; i +=20) {
//reducing the range of the map so the color range shows up
// width/ higher or lower number changes the range of the colors
float c = map (x, 0, width/20, red, yellow);
fill(c, 255, 255);
ellipse (x*xspacing, yvalues[x] + i, 10, 10);
}
}
}