here's a simple little code my teacher gave us
Code:
//Code by JFR
float posX, posY, amplitude = 40, variationY, variationY2, temps = 0, WaveSpeed, completeCycle, subCycle;
int startX = 100, endX = 500, step=10, distanceX;
color color_1, color_2;
void setup() {
size(600,500);
background(0);
color_1 = color(200,150,0);
color_2 = color(150,240,50);
noStroke();
smooth();
rectMode(CENTER);
distanceX = endX-startX;
completeCycle = TWO_PI/float(distanceX);
subCycle = (TWO_PI*5)/float(distanceX);
}
void draw() {
background(0);
fill(color_1);
posY = 75;
WaveSpeed = 0.0005;
for (int i = startX; i<endX; i+=step) {
temps += (millis()%i)*WaveSpeed;
variationY = sin(((i-startX)+temps)*completeCycle);
variationY*=amplitude;
ellipse(i, (posY+variationY), 5, 5);
}
fill(color_2);
posY = 165;
WaveSpeed = 0.0005;
for (int i = startX; i<endX; i+=step) {
temps += (millis()%i)*WaveSpeed;
variationY = sin(((i-startX)+temps)*completeCycle);
variationY*=(amplitude*0.2)+((i*i)/(4000));
rect(i, (posY+variationY), 5, 5);
}
fill(color_1);
posY = 275;
WaveSpeed = 0.0001;
for (int i = startX; i<endX; i+=step) {
temps += (millis()%i)*WaveSpeed;
variationY = sin(((i-startX))*completeCycle);
variationY*=amplitude;
variationY2 = sin((i-startX+temps)*subCycle);
variationY2 *= amplitude*0.3;
ellipse(i, (posY+variationY+variationY2), 5, 5);
}
fill(color_2);
posY = 395;
WaveSpeed = 0.0001;
for (int i = startX; i<endX; i+=step) {
temps += (millis()%i)*WaveSpeed;
variationY = sin(((i-startX+temps))*completeCycle);
variationY*=(amplitude*0.2)+((i*i)/(4000));
variationY2 = sin((i-startX+temps)*subCycle);
variationY2 *= (amplitude*0.005)+((i*i)/(16000));
rect(i, (posY+variationY+variationY2), 5, 5);
}
}