1. This is a handy piece of code for Processing that should work with the arrow keys on makey-makey
its based on an if else statement see here: //based on this code https://processing.org/reference/keyCode.html
the square will change color based on input/output
//if else etc
//based on https://processing.org/reference/keyCode.html
void draw() {
rect(25, 25, 50, 50);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
fill(255);
} else if (keyCode == DOWN) {
fill(41,47, 142);
}
else if (keyCode == LEFT) {
fill(33, 22, 6);
}
else if (keyCode == RIGHT) {
fill(147,46,46);
}
else {
fill(33,6,6);
}
}
}
2. Try also a first step towards playing video (see zip file loop below)
. You must load the video library -go to import add library
the video file must be in a data folder inside sketch folder see loop zip at end of this page.
//loop
/**
* Loop.
*
* Shows how to load and play a QuickTime movie file.
*
*/
import processing.video.*;
Movie movie;
void setup() {
size(640, 360);
background(0);
// Load and play the video in a loop
movie = new Movie(this, "transit.mov");
movie.loop();
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
//if (movie.available() == true) {
// movie.read();
//}
image(movie, 0, 0, width, height);
//easy color invert of image
//filter(INVERT);
//makes black and white
//filter(THRESHOLD, .5);
//filter(POSTERIZE,7);
}
3. See this test which loads two videos on arrow key press..we could add more easily.. see sketch2videoYulia zip below
//video Yulia
import processing.video.*;
Movie movie;
Movie movie2;
String movieName;
void setup() {
size(640, 720);
// Load and play each video in a loop
movie = new Movie(this, "transit.mov");
movie.loop();
movie.volume(0);
movie2 = new Movie(this, "dancer.mov");
movie2.loop();
movie2.volume(0);
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
image(movie, 0, 0, width, height);
} else if (keyCode == DOWN) {
image(movie2, 0, 0, width, height);
}
else if (keyCode == LEFT) {
fill(33, 22, 6);
}
else if (keyCode == RIGHT) {
fill(147,46,46);
}
else {
fill(33,6,6);
}
}
}