Função para criação de uma onda
Código:
int xespaco = 1;
int o;
float t = 0.0;
float abertura = 100;
float periodo = 200;
float dx;
float[] valory;
void setup() {
size(800, 500);
o = width+10;
dx = (TWO_PI /
periodo) * xespaco;
valory = new
float[o/xespaco];
}
void draw() {
background(0);
calcWave();
renderWave();
}
void calcWave() {
t += 0.02;
float x = t;
for (int i = 0; i
< valory.length; i++) {
valory[i] =
sin(x)*abertura;
x+=dx;
}
}
void renderWave() {
noStroke();
fill(255);
for (int x = 0; x
< valory.length; x++) {
ellipse(x*xespaco,
height/2+valory[x], 10, 10);
}
}

Nenhum comentário:
Postar um comentário