// Flat tringle mesh with texture for image warping // Written by Jarek Rossignac June 2006 import processing.opengl.*; // comment out if not using OpenGL PImage myImage; // image used as tecture int n=7; // size of grid. Must be >2! pt[][] G = new pt [n][n]; // array of vertices int pi,pj; // indices of vertex being dragged when mouse is pressed pt Mouse = new pt(0,0,0); // current mouse position boolean showVertices=true, showEdges=true, showTexture=true; // flags for rendering vertices and edges color red = color(200, 10, 10), blue = color(10, 10, 200), green = color(10, 200, 20), black = color(10, 10, 10); float w,h,ww,hh; // width, height of cell in absolute and normalized units vec offset = new vec (0,0,0); // offset vector from mouse to clicked vertex // SMOOTHING vec[][] L = new vec [n][n]; // laplace vectors for vertices vec[][] LL = new vec [n][n]; // bilaplace vectors for vertices boolean showL=false, showLL=true; // flags for rendering laplace vectors boolean[][] pinned= new boolean [n][n]; // mask for pinned vertices int m=3; // method used for smoothing: 0&1=average of x and y cubics, 2= radial, 3= 5x5 bicubic boolean move = true; // ** SETUP ** void setup() { size(800, 800, OPENGL); //for OpenGL use: void setup() { size(800, 800, OPENGL); myImage = loadImage("jarek.jpg"); // load image for texture ww=1.0/(n-1); hh=1.0/(n-1); // set intial width and height of a cell w=width*ww; h=height*hh; // set intial width and height of a cell in normalized [0,1]x[0,1] resetVertices(); pinBorder(); } void resetVertices() { // resets points and laplace vectors for (int i=0; i