float[][] anpts = { new float[] { 250f, 150f } ,new float[] { 250f, 250f } }; float[][] cvpts = { new float[] { 350f, 150f } ,new float[] { 350f,250f } }; char [] ad = { 'a', 'd'}; char [] bc = { 'b', 'c'}; Handle[] anchors = new Handle[2]; Handle[] curvs = new Handle[2]; PFont myFont; String string ; float squishy = 0.0; PSlider slider1 ; color bkColor = color(220,255,255); void setup() { size( 600, 500 ); slider1 = new PSlider (5, 480, 150, 15, "squishiness= ", -10.0, 20.0); slider1.initPos(18.0); for (int i=0; i<2; i++) { { anchors[i] = new Handle( anpts[i][0], anpts[i][1], 10, color(0,255,200), "Square" ); curvs[i] = new Handle( cvpts[i][0], cvpts[i][1], 10, color(0,255,200), "Square" ); } } myFont = loadFont("Verdana-Bold-12.vlw"); textFont(myFont); ellipseMode( CORNER ); framerate(30); } void draw() { squishy = slider1.slv; curveTightness(squishy); background(bkColor); fill(0); rect(0,0,600,400); fill(50); text("Created by Koo-Chul Lee (Nov./10/'05))", 330,15); text("I hear, I forget; I see, I remember; I do, I understand. - A Chinese proverb", 30,395); slider1.display(); for (int i=0; i<2; i++) { anchors[i].display(); curvs[i].display(); } fill(255); for (int i=0; i<2; i++) { string = ad[i] + " ("+nf(anpts[i][0], 3,0)+", "+nf(anpts[i][1], 3,0) + ")"; text(string, anpts[i][0]-20, anpts[i][1]-8); string = bc[i] + " ("+nf(cvpts[i][0], 3,0)+", "+nf(cvpts[i][1], 3,0) + ")"; text(string, cvpts[i][0]-20, cvpts[i][1]-8); } updatePos(); stroke(255,255,255); curve (anpts[0][0],anpts[0][1],cvpts[0][0],cvpts[0][1], cvpts[1][0],cvpts[1][1],anpts[1][0],anpts[1][1]); stroke(255, 100, 100); curve (anpts[1][0],anpts[1][1], anpts[0][0],anpts[0][1],cvpts[0][0],cvpts[0][1], cvpts[1][0],cvpts[1][1]); stroke(100, 255, 100); curve (cvpts[1][0],cvpts[1][1],anpts[1][0],anpts[1][1],anpts[0][0],anpts[0][1],cvpts[0][0],cvpts[0][1]); stroke(100, 100, 255); curve (cvpts[0][0],cvpts[0][1], cvpts[1][0],cvpts[1][1],anpts[1][0],anpts[1][1],anpts[0][0],anpts[0][1]); fill(0); text("curveTightness( " + nfs(slider1.slv, 1,2) + " );", 10, 420); text("stroke(255, 255, 255); curve( a, b, c, d); stroke(255, 100, 100); curve( d, a, b, c); " , 10, 440); text("stroke(100, 255, 100); curve( c, d, a, b); stroke(100, 100, 255); curve( b, c, d, a); " , 10, 460); stroke(0); } void updatePos() { for (int i=0; i<2; i++) { anpts[i][0] = anchors[i].x + anchors[i].w/2; anpts[i][1] = anchors[i].y + anchors[i].w/2; cvpts[i][0] = curvs[i].x + curvs[i].w/2; cvpts[i][1] = curvs[i].y + curvs[i].w/2; } } void mousePressed() { slider1.dragThumb(); if(slider1.over()) slider1.changeValue(); for (int i=0; i<2; i++) { anchors[i].drag(); curvs[i].drag(); } } void mouseReleased() { slider1.dragThumb(); if(slider1.over()) slider1.changeValue(); for (int i=0; i<2; i++) { anchors[i].drag(); curvs[i].drag(); } }