import deadpixel.keystone.*;
Keystone keyStone;
CornerPinSurface surface;
PGraphics offscreen;
int numCircle = 30;
float movX[], movY[];
float directionX[], directionY[];
float speedX[], speedY[];
color colorCircle[];
float sizeCircle[];
void setup() {
size(1280, 800, P3D);
keyStone = new Keystone(this);
surface = keyStone.createCornerPinSurface(400, 400, 20);
offscreen = createGraphics(400, 400, P3D);
movX = new float[numCircle];
movY = new float[numCircle];
directionX = new float[numCircle];
directionY = new float[numCircle];
speedX = new float[numCircle];
speedY = new float[numCircle];
colorCircle = new color[numCircle];
sizeCircle = new float[numCircle];
for (int i=0; i<numCircle; i++) {
directionX[i] = 1;
directionY[i] = 1;
speedX[i] = random(3, 10);
speedY[i] = random(3, 10);
colorCircle[i] = color( random(255), random(255), random(255) );
sizeCircle[i] = random(20, 40);
}
}
void draw() {
for (int i=0; i<numCircle; i++) {
movX[i] = movX[i] + directionX[i] * speedX[i];
movY[i] = movY[i] + directionY[i] * speedY[i];
if (movX[i]>400) directionX[i] = -1;
if (movX[i]<0) directionX[i] = 1;
if (movY[i]>400) directionY[i] = -1;
if (movY[i]<0) directionY[i] = 1;
}
PVector surfaceMouse = surface.getTransformedMouse();
// Draw the scene, offscreen
offscreen.beginDraw();
offscreen.background(0);
offscreen.fill(0, 255, 0);
offscreen.ellipse(surfaceMouse.x, surfaceMouse.y, 75, 75);
for (int i=0; i<numCircle; i++) {
offscreen.fill(colorCircle[i]);
float _size = sizeCircle[i];
offscreen.ellipse(movX[i], movY[i], _size, _size);
}
offscreen.endDraw();
// most likely, you'll want a black background to minimize
// bleeding around your projection area
background(0);
// render the scene, transformed using the corner pin surface
surface.render(offscreen);
}
void keyPressed() {
switch(key) {
case 'c':
// enter/leave calibration mode, where surfaces can be warped
// and moved
keyStone.toggleCalibration();
break;
case 'l':
// loads the saved layout
keyStone.load();
break;
case 's':
// saves the layout
keyStone.save();
break;
}
}