Sunday 24 October 2010

So it works like a psychedelic vision mixer, with the two potentiometers
controlling x and y rotations and the button causing the image to be inverted. Works really well!









crazyKalope - Arduino to Processing using the same circuit and same way of getting data into Processing as the Etch-a-Sketch






import processing.serial.*;
Serial myPort; // Create object from Serial classint potX; // Data received from the serial portint potY;int button;////////
PImage bob, bob2, bob3, bob4;float rot;int ax;int ay;void setup(){
background(255); size(600, 600, P3D);
//////// String portName = Serial.list()[2]; //choose from [0] [1] [2] myPort = new Serial(this, portName, 9600); myPort.bufferUntil('\n');

//////////////
bob = loadImage("input2.jpg");
bob2 = loadImage("input.jpg");
bob3 = loadImage("input3.jpg");
bob4 = loadImage("input4.jpg"); //random load image? ax = width/2; ay = height/2; rot =random(360);
}
void draw(){
// frameRate(14); // background(255); translate(300, 300); rot +=15; rotate(rot); //tint(0, 243); rotateY(radians(potY)); // strokeWeight(3); pushMatrix(); translate(130, height/2, 0); rotateY(radians(potY)); rotateX(radians(potX)); triangle(30, 75, 58, 20, 86, 75); popMatrix(); noFill(); stroke(255); pushMatrix(); translate(500, height*0.35, -200); fill((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); triangle(30, 75, 58, 20, 86, 75); popMatrix(); noStroke(); fill((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); ellipse(0, 0, 15, 15); // fill((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); //fill(255, 0, 0); noStroke();

println(" " +frameCount + " "); // tint(255, 230); noStroke(); fill((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); ellipse(width/3, height/3, 23, 23); tint(255, 123); //? // image(bob, 0,0,width/3,height/3); tint(255, 123); //? // noTint(); tint(255, 223); stroke(13); strokeWeight(3); // tint(255, 230);
stroke((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); line(0, 123, 0, 234); tint(255, 234);

if(button == 1){ pushMatrix(); translate(130, height/2, 0); rotateY(frameCount); rotateX(-0.4); // image(bob2, -50, -30, 123, 224); popMatrix(); save("data/ima.jpg"); print(" " + "PRESSED" + " ");
tint((int)random(100, 255),(int)random(100, 255),(int)random(100, 255)); filter(INVERT); rot +=45; PImage nee2 = loadImage("data/ima.jpg"); tint((int)random(100, 255),(int)random(100, 255),(int)random(100, 255)); // image(nee2, 100, 100, 123, 124); }
if(mousePressed){
// PImage nee2 = loadImage("data/ima.jpg");
// rot +=45;

} /* rotateY(mouseX); rotateX(mouseY); */ rotateY(radians(potX)); // rotateX(potY); rotateY(radians(potY));
//filter(BLUR, 4); // save("data/ima.jpg"); // PImage nee = loadImage("data/ima.jpg"); //image(nee, -100, -100, width, height); // tint(255, 203); // image(nee, 100, 100, 123, 124); // image(nee, 100, 100, 123, 124); // noTint(); fill((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); ellipse(width/3, height/3, 23, 23); // noTint(); fill((int)random(123, 255),(int)random(123, 255),(int)random(123, 255)); ellipse(width/3, height/3, 23, 23); tint(255, 123); if(frameCount >20 ){ // image(bob3, 0, 0, 123, 123); tint(255, 123); }
if(frameCount >30){ image(bob4, 20, 20, 423, 123); noTint(); scale(-0.75);
}
if(frameCount %30==0){
rot -=15; } if((frameCount >=40) &&(frameCount<=70)){ // image(bob3,-20, -20, 223, 223); tint(155, 33); filter(DILATE); } if((frameCount >=80) &&(frameCount<=170)){ // image(bob3, 45, 45, frameCount%4, frameCount%4 ); // } // filter(ERODE); scale( frameCount%4);} void serialEvent(Serial myPort){ String inString = myPort.readStringUntil('\n'); //get the data in and divide it with each new line if(inString != null){ //check there is a full string inString = trim(inString); //remove any gaps String[] list = split(inString, ','); //split where there are commas potX = Integer.parseInt(list[1]); //make the Sting into an int potY = Integer.parseInt(list[2]); //ditto button = Integer.parseInt(list[0]); //print them out so I can see what's happening if I want /* println(" " + Integer.parseInt(list[1]) + " "); //pot right hand println(" " + list[2] + " "); //pot left hand println(" " + list[0] + " "); //button */ stroke(0); strokeWeight(5); //dont allow values to go outside of screen int xVal = constrain(potX, 0, 360); int yVal = constrain(potY, 0, 360); println(" " + xVal + " " ); println(" " + yVal + " " ); // float m = map(xVal, 1024, 0, 360); point(xVal, potY); } }

No comments:

Post a Comment