Code
void setup() {
size(600,600);
}
void draw() {
background(0);
drawZZ(30,30,30,30,15,true);
drawZZ(30,60,30,30,5,true); //shorter
drawZZ(30,90,30,70,15,true);
drawZZ(30,180,50,20,8,true);
drawZZ(30,210,30,30,15,false); //without boxes
drawWavy(30,300,30,45,10,0,false); //dotted
drawWavy(30,360,30,45,10,0, true); //connected
drawWavy(30,430,30,15,10,PI, true); //offset start
drawWavy(30,490,15,50,10,(frameCount*0.1)%TWO_PI, true); //moving
}
void drawZZ(float x, float y, float w, float h, int n, boolean showBoxes) {
noFill();
stroke(255);
for(int i = 0; i < n; i++) {
if(showBoxes) rect(x+i*w,y,w,h);
if(i%2==0) line(x+i*w,y,x+(i+1)*w,y+h);
else line(x+i*w,y+h,x+(i+1)*w,y);
}
}
void drawWavy(float x, float y, float amplitude, float waveLength, float waves, float offSet, boolean connect) {
for(int i = 0; i < waves; i++) { //looping through waves
for(int j = 0; j < waveLength; j++) { //drawing waves
point(x+i*waveLength+j,y+amplitude*sin( TWO_PI/waveLength*j+offSet));
if(connect) line(x+i*waveLength+j,y+amplitude*sin( TWO_PI/waveLength*j+offSet),
x+i*waveLength+(j+1),y+amplitude*sin( TWO_PI/waveLength*(j+1) +offSet));
}
}
}
It can only use sin-waves (or cosine if you just offset it a bit since cos = co-sinus). If you want some randomness, you could use perlin noise and set a seed for generating pseudo random nubmers.