Espirografico
/*
ESPIROGRAFICO v.0.1
Curves and lines appear on central axis.
Now with sound (mod of synthesizesound minim example)
Instructions: Click and drag to draw.
KEYS:
A: Clean canvas.
S: Save image.
1-5: Change stroke and sound.
*/
// required minim library
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
Oscil wave;
void setup(){
size(1280,720,P2D);
background(200);
smooth();
cursor(CROSS);
stroke (100);
strokeWeight(0.5);
noFill();
ellipseMode(CENTER);
minim = new Minim(this);
out = minim.getLineOut();
wave = new Oscil( 100, 0.5f, Waves.SINE );
wave.patch(out);
}
void draw(){
if (mousePressed){
float amp = map(mouseY, 0, height, 1, 0);
wave.setAmplitude(amp);
float freq = map(mouseX, 0, width, 110, 880);
wave.setFrequency(freq);
line(width/2,height/2,mouseX+50,mouseY+50);
ellipse(width/2,height/2,mouseX+50,mouseY+50);
}
// CLEAN CANVAS
if (keyPressed){
if (key=='a' || key=='A'){
background(200);
}
}
// SAVE IMAGE
if (keyPressed){
if (key=='s' || key=='S'){
saveFrame("espirografico-######.png");
}
}
}
// CHANGE WAVES
void keyPressed()
{
switch( key )
{
case '1':
stroke(100,random(100));
wave.setWaveform( Waves.SINE );
break;
case '2':
stroke(150,random(100));
wave.setWaveform( Waves.TRIANGLE );
break;
case '3':
stroke(255,random(100));
wave.setWaveform( Waves.SAW );
break;
case '4':
strokeWeight(random(10));
wave.setWaveform( Waves.SQUARE );
break;
case '5':
wave.setWaveform( Waves.QUARTERPULSE );
break;
default: break;
}
}
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário