int x = 215;
int y = 45;
void setup() {
size(480, 480);
background(150);
frameRate(100);
}
void draw() {
if (keyPressed && (key == CODED)) { // If it's a coded key
if (keyCode == LEFT && x > 0) { // If it's the left arrow
x--;
}
if(keyCode == UP && y > 0){
y--;
}
if(keyCode == DOWN && y < 480-25){
y++;
}
if (keyCode == RIGHT && x < 480-25) { // If it's the right arrow
x++;
}
else{
x = x;
y = y;
}
}
fill(255,0,0); // fill color for dot
rect(x, y, 5, 5);
fill(0); // fill color for line
if(keyPressed && (key != CODED)){
background(150);
}
}
Category Archives: Class Examples
Alan Watts: The Joker
- The Joker Part 1
- The Joker Part 2
- The Joker Part 3
- The Joker Part 4
- The Joker Part 5
- The Joker Part 6
(We listened to about the first 15 minutes of part 1)
Slit-Scan modified
We changed this so it will save at the end of every scan and restart again.
/**
* Simple Real-Time Slit-Scan Program.
* By Golan Levin.
*
* This demonstration depends on the canvas height being equal
* to the video capture height. If you would prefer otherwise,
* consider using the image copy() function rather than the
* direct pixel-accessing approach I have used here.
*
* Created December 2006.
* Updated September 2011 by James Hale.
*/
import processing.video.*;
Capture video;
int videoSliceX;
int drawPositionX;
void setup() {
size(1000, 480, P2D);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, 1000, 480, 60);
videoSliceX = video.width / 2;
drawPositionX = width - 1;
background(0);
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();
// Copy a column of pixels from the middle of the video
// To a location moving slowly across the canvas.
loadPixels();
for (int y = 0; y < video.height; y++){
int setPixelIndex = y*width + drawPositionX;
int getPixelIndex = y*video.width + videoSliceX;
pixels[setPixelIndex] = video.pixels[getPixelIndex];
}
updatePixels();
drawPositionX--;
// Saves your image if pixels reach the end of the frame
if (drawPositionX < 0) {
saveFrame();
drawPositionX = width - 1; // not sure this works
}
// Takes another photo if you click the mouse.
if(mousePressed) {
drawPositionX = width - 1;}
}
}
