One more question, sry
I have a programm where a line rotates round the courser. Additionally I have selfmade shapes wich i can activate by pushing a key but they don´t work.Their names are "02.svg"-"06.svg"(illustrator)
And the line is sensible preferring to the sound. A loud noise will make the line kick out. But additionally i want to make a random color for every loud noise like clap e.g. Can someone help me and take a look at my code?
Would help me a lot.
Thx=)
import processing.pdf.*;
boolean recordPDF = false;
float lineModuleSize = 0;
float angle = 0;
float angleSpeed = 0.2;
PShape lineModule = null;
int clickPosX = 0;
int clickPosY = 0;
import ddf.minim.*;
color col = color(0,0,0,25);
Minim minim;
AudioInput in;
void setup()
{
size(screen.width, screen.height );
background(255);
cursor(CROSS);
smooth();
minim = new Minim(this);
minim.debugOn();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO,800);
}
void draw()
{
if (mousePressed) {
int x = mouseX;
int y = mouseY;
strokeWeight(1.0);
stroke(col);
pushMatrix();
translate(x, y);
rotate(radians(angle));
if (lineModule != null) {
shape(lineModule, 0, 0, lineModuleSize, lineModuleSize);
}
else {
line(0, 0, lineModuleSize, lineModuleSize);
angle = angle + angleSpeed;
for(int i = 0; i < in.bufferSize() - 1; i++)
line(i, 150 + in.right.get(i)*50000, i+1, 150 + in.right.get(i+1)*50);
}
popMatrix();
}
}
void keyReleased() {
if (key == DELETE || key == BACKSPACE) background(255);
if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");
// reverse direction and mirrow angle
if (key=='d' || key=='D') {
angle = angle + 180;
angleSpeed = angleSpeed * -1;
}
// r g b alpha
if (key == ' ') col = color(random(255),random(255),random(255),random(80,150));
//default colors from 1 to 4
if (key == '1') col = color(0,0,0,100);
if (key == '2') col = color(0,255,0,100);
if (key == '3') col = color(0,0,255,100);
if (key == '4') col = color(255,255,255,100);
if (key == 'q') col = color(154,111,76,100);
if (key == 'w') col = color(255,0,0,100);
if (key == 'f') {
col = color(0,0,0,100);
lineModuleSize += 100;
}
if (key == 'g') {
col = color(154,111,76,100);
lineModuleSize += 100;
}
if (key == 'c') {
col = color(0,0,0,100);
lineModuleSize -= 100;
}
if (key == 'v') {
col = color(154,111,76,100);
lineModuleSize -= 100;
}
// load svg for line module
if (key=='5') lineModule = null;
if (key=='6') lineModule = loadShape("02.svg");
if (key=='7') lineModule = loadShape("03.svg");
if (key=='8') lineModule = loadShape("04.svg");
if (key=='9') lineModule = loadShape("05.svg");
if (lineModule != null) {
lineModule.disableStyle();
}
if (key =='r' || key =='R') {
if (recordPDF == false) {
beginRecord(PDF, timestamp()+".pdf");
println("recording started");
recordPDF = true;
}
}
else if (key == 'e' || key =='E') {
if (recordPDF) {
println("recording stopped");
endRecord();
recordPDF = false;
background(255);
}
}
}
void keyPressed() {
if (keyCode == UP) lineModuleSize += 100;
if (keyCode == DOWN) lineModuleSize -= 100;
if (keyCode == LEFT) angleSpeed -= 0.2;
if (keyCode == RIGHT) angleSpeed += 0.2;
}
void stop()
{
in.close();
minim.stop();
super.stop();
}
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}