User:Pleun/openaanbod/processing 3: Difference between revisions
(Created page with "// === CODE === // Animating shape, sound and colour PVector v1 = new PVector(50,250); PVector v2 = new PVector(150,250); PVector v3 = new PVector(450,550); PVector v4 = ne...") |
No edit summary |
||
Line 4: | Line 4: | ||
PVector v1 = new PVector(50,250); | PVector v1 = new PVector(50,250); | ||
PVector v2 = new PVector(150,250); | PVector v2 = new PVector(150,250); | ||
PVector v3 = new PVector(450,550); | PVector v3 = new PVector(450,550); | ||
PVector v4 = new PVector(600,50); | PVector v4 = new PVector(600,50); | ||
boolean v1Selected = false; | boolean v1Selected = false; | ||
boolean v2Selected = false; | boolean v2Selected = false; | ||
boolean v3Selected = false; | boolean v3Selected = false; | ||
boolean v4Selected = false; | boolean v4Selected = false; | ||
int steps = 200; | int steps = 200; | ||
int step = 1; | int step = 1; | ||
int i = 0; | int i = 0; | ||
import ddf.minim.*; | import ddf.minim.*; | ||
import ddf.minim.ugens.*; | import ddf.minim.ugens.*; | ||
Minim minim; | Minim minim; | ||
AudioOutput out; | AudioOutput out; | ||
Oscil wave; | Oscil wave; | ||
void setup() { | void setup() { | ||
size (1000,800); | size (1000,800); | ||
Line 42: | Line 42: | ||
} | } | ||
void draw() { | void draw() { | ||
background(0); | background(0); | ||
strokeWeight(3); | strokeWeight(3); | ||
Line 80: | Line 80: | ||
step = - step; | step = - step; | ||
} | } | ||
} | } | ||
void mousePressed() { | void mousePressed() { | ||
if(dist(mouseX, mouseY, v1.x, v1.y) < 7.5) { | if(dist(mouseX, mouseY, v1.x, v1.y) < 7.5) { | ||
v1Selected = true; | v1Selected = true; | ||
Line 94: | Line 94: | ||
if(dist(mouseX, mouseY, v4.x, v4.y) < 7.5) { | if(dist(mouseX, mouseY, v4.x, v4.y) < 7.5) { | ||
v4Selected = true; | v4Selected = true; | ||
} | |||
} | } | ||
void mouseDragged() { | void mouseDragged() { | ||
if(v1Selected) { | if(v1Selected) { | ||
v1.x = mouseX; | v1.x = mouseX; | ||
Line 113: | Line 113: | ||
v4.x = mouseX; | v4.x = mouseX; | ||
v4.y = mouseY; | v4.y = mouseY; | ||
} | |||
} | } | ||
void mouseReleased() { | void mouseReleased() { | ||
v1Selected = false; | v1Selected = false; | ||
v2Selected = false; | v2Selected = false; | ||
v3Selected = false; | v3Selected = false; | ||
v4Selected = false; | v4Selected = false; | ||
} | } |
Latest revision as of 14:26, 29 October 2015
// === CODE ===
// Animating shape, sound and colour
PVector v1 = new PVector(50,250); PVector v2 = new PVector(150,250); PVector v3 = new PVector(450,550); PVector v4 = new PVector(600,50);
boolean v1Selected = false; boolean v2Selected = false; boolean v3Selected = false; boolean v4Selected = false;
int steps = 200; int step = 1; int i = 0;
import ddf.minim.*; import ddf.minim.ugens.*;
Minim minim; AudioOutput out; Oscil wave;
void setup() { size (1000,800); minim = new Minim(this); // use the getLineOut method of the Minim object to get an AudioOutput object out = minim.getLineOut(); // create a sine wave Oscil, set to 440 Hz, at 0.5 amplitude wave = new Oscil( 440, 0.5f, Waves.SINE ); // patch the Oscil to the output wave.patch( out );
}
void draw() { background(0); strokeWeight(3); stroke(255); noFill(); bezier(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v4.x, v4.y); fill(0); ellipse(v1.x, v1.y, 15, 15); ellipse(v2.x, v2.y, 15, 15); ellipse(v3.x, v3.y, 15, 15); ellipse(v4.x, v4.y, 15, 15); float t = i/float(steps); float x = bezierPoint(v1.x, v2.x, v3.x, v4.x, t); float y = bezierPoint(v1.y, v2.y, v3.y, v4.y, t); fill(0,255,0); noStroke(); ellipse(x, y, 40,40); ellipse(x, 700, 30 ,30); int c = (int)map(x, 0, 660, 0, 255); fill(c,0,255); rect(width - 240, y, c, c); float amp = map( y, 0, height, 1, 0 ); wave.setAmplitude( amp ); float freq = map( x, 0, width, 110, 880 ); wave.setFrequency( freq ); i = i + step; if (i >= steps || i < 0){ step = - step; } }
void mousePressed() { if(dist(mouseX, mouseY, v1.x, v1.y) < 7.5) { v1Selected = true; } if(dist(mouseX, mouseY, v2.x, v2.y) < 7.5) { v2Selected = true; } if(dist(mouseX, mouseY, v3.x, v3.y) < 7.5) { v3Selected = true; } if(dist(mouseX, mouseY, v4.x, v4.y) < 7.5) { v4Selected = true; } }
void mouseDragged() { if(v1Selected) { v1.x = mouseX; v1.y = mouseY; } if(v2Selected) { v2.x = mouseX; v2.y = mouseY; } if(v3Selected) { v3.x = mouseX; v3.y = mouseY; } if(v4Selected) { v4.x = mouseX; v4.y = mouseY; } }
void mouseReleased() { v1Selected = false; v2Selected = false; v3Selected = false; v4Selected = false; }