I am trying to keystone a generative diagram using the keystone library with processing 3.1 The keystone example code when input into my design executes fine, but doesn't call in the graphics to the keystone area. I am not sure whats wrong, is it because my patch calls the graphic via a class and a parented patch? Is there anything I should know to get this running okay?
/*
import deadpixel.keystone.*;
import megamu.mesh.*;
Keystone ks;
CornerPinSurface surface;
PGraphics offscreen;
// Menu GUI. Bolleans to change visualizations
boolean debug = false;
boolean view = true;
boolean info=true;
boolean voronoi=false;
boolean lines=true;
FlowField flowfield; // Flowfield object
ArrayList<Vehicle> vehicles; // An ArrayList of vehicles
int nrParticles = 100; // number of elements/particles
//float[][] points = new float[nrParticles][2]; // Array for the VORONOI cells // ############# HACK
void setup() {
size(1280,720, P3D);
ks = new Keystone(this);
surface = ks.createCornerPinSurface(640, 360, 20);
offscreen = createGraphics(640,360, P3D);
// Resolution of the flowfield. nr of cells
flowfield = new FlowField(50);
// create the elements in a random position
vehicles = new ArrayList<Vehicle>();
for (int i = 0; i < nrParticles; i++) {
vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 15), random(0.1, 1.5)));
}
//Audiostuff
input = new AudioIn(this, 0); //Create an Audio input and grab the 1st channel
input.start();// start the Audio Input
rms = new Amplitude(this); // create a new Amplitude analyze
rms.input(input); // Patch the input to an volume analyzer
input.amp(2.0);
smooth();
}
void draw() {
PVector surfaceMouse = surface.getTransformedMouse();
//amplitude stuff
float analise = map(rms.analyze(), 0, 0.5, 0.0, 50.0);
audioIn+= (analise-audioIn)*0.01; //smoothing the audioIn vall
background(0);
flowfield.update(); // Flowfield update and display
if (debug) flowfield.display(); // If debug mode True, display flowfield
// Tell all the vehicles to follow the flow field
for (Vehicle v : vehicles) {
v.follow(flowfield);
v.run();
}
// DRAWING VORONOI
nrParticles=vehicles.size(); // ############# HACK
int nrVoronois=int(map(720, 0, height, 0, nrParticles));
float[][] points = new float[nrParticles][2]; // Array for the VORONOI cells // ############# HACK
//GETTING VEHICLES POSITION TO VORONOI'S POINTS
for (int i=0; i<vehicles.size(); i++) {
points[i][0]= vehicles.get(i).location.x;
points[i][1]= vehicles.get(i).location.y;
}
Voronoi myVoronoi = new Voronoi(points);
MPolygon[] myRegions = myVoronoi.getRegions();
for (int i=0; i<nrVoronois; i++)
{
// an array of points
float[][] regionCoordinates = myRegions[i].getCoords();
fill(int(map(i*255.0, 147, i*255.0/nrParticles, 130 * (i % 2), 255)));
//fill(int(map(i*255.0/nrParticles, 130 * (i % 2), 225 * (i % 2),0,0)));
//fill(255,int(map(sum[i],0,10,255,0))); // dar valor do FFT ao interior do voronoi
if (voronoi) myRegions[i].draw(this); // draw this shape
}
float[][] myEdges = myVoronoi.getEdges();
for (int i=0; i<myEdges.length; i++)
{
float startX = myEdges[i][0];
float startY = myEdges[i][1];
float endX = myEdges[i][2];
float endY = myEdges[i][3];
stroke(255);
if (lines) line( startX, startY, endX, endY );
}
// Draw the scene, offscreen
offscreen.beginDraw();
offscreen.background(255);
offscreen.fill(0, 255, 0);
offscreen.ellipse(surfaceMouse.x, surfaceMouse.y, 75, 75);
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);
}
// Keyboard Interaction
void keyPressed() {
switch(key) {
case 'c':
// enter/leave calibration mode, where surfaces can be warped
// and moved
ks.toggleCalibration();
break;
case 'o':
// loads the saved layout
ks.load();
break;
case 's':
// saves the layout
ks.save();
break;
}
if (key == ' ') {
debug = !debug;
}
if (key=='i') {
info=!info;
}
if (key=='p') {
view=!view;
}
if (key=='v') {
voronoi=!voronoi;
}
if (key=='l') {
lines=!lines;
}
if (key=='r') {
vehicles.remove(0);
println(vehicles.size());
}
if (key=='a') {
vehicles.add(new Vehicle(new PVector(random(width), 0-3), random(2, 5), random(0.1, 0.5)));
println(vehicles.size());
}
}