//-----------------// // Escher's Knot // // by Henry Rogers // // 5/4/2011 - v1.0 // //-----------------// // Key Controls: c - cycle; r - revolve; g - gamut; w - wireframe; mouse click drag - rotate. //---- globals int _e = 43; // for elizabeth int _p = 576; // number of points on curve int _n = 72; // number of boxes or key frames along curve int _u = 8; // number of tweens per key frame int _b = 4; // number of points in width of box int _a = 2; // curve scaling factor int _c = 0; // to cycle or not to cycle int _f = 0; // frame iterator for cycling int _g = 0; // to show gamut or not int _h = 0; // hue interator for gamut int _o = 36; // original hue for tube int _r = 0; // to revolve or not to revolve int _m = 0; // mobius iterator for rotation int _w = 0; // to show wireframe or solids int _x = 90; // initial x rotation int _y = 70; // initial y rotation int _z = 90; // initial z rotation int _s = 72; // initial model scale float _d1 = 0.38; // distance from corner to first midpoint on side float _d2 = 0.62; // distance from corner to second midpoint on side boolean _l = false; // lock hover state when button is pressed PImage _t; // texture image TrefoilCurve _k; // Trefoil knot class // button controls Button btnCycle; // start/stop cycling Button btnRevolve; // start/stop revolution Button btnGamut; // show/hide gamut Button btnWireframe; // show/hide wireframe void setup() { import com.processinghacks.arcball.*; if (online==false) { import processing.opengl.*; size( 760, 760, OPENGL ); smooth(); textFont( loadFont("data/font.vlw"), 18 ); } else { size( 760, 760, P3D ); textMode(SCREEN); } colorMode( HSB, 360, 100, 100 ); // camera control ArcBall arcball = new ArcBall( this ); _t = loadImage( "data/lines.jpg" ); textureMode( NORMALIZED ); // instantiate trefoil curve _k = new TrefoilCurve( _a, _d1, _d2 ); // instantiate button controls btnCycle = new Button( 6, 6, color(50,40,80), "Cycle" ); btnRevolve = new Button( btnCycle.right() + 3, 6, color(50,40,80), "Revolve" ); btnGamut = new Button( btnRevolve.right() + 3, 6, color(50,40,80), "Gamut" ); btnWireframe = new Button( btnGamut.right() + 3, 6, color(50,40,80), "Wireframe" ); } void draw() { background( 59, 7, 85 ); lights(); // adjust lighting depending on gamut or texture mode if ( _g == 1 ) { lightSpecular( 30, 40, 50 ); directionalLight( 0, 0, 20, 0, 0, -1 ); } else { lightSpecular( 25, 50, 72 ); pointLight( 25, 50, 100, 0, 0, -12 ); directionalLight( 25, 50, 72, 0, 0, -1 ); } translate( width/2, height/2, -height/2 ); rotateX( radians( _x ) ); rotateY( radians( _y ) ); rotateZ( radians( _z ) ); scale( _s ); int i,j; // advance revolution angle by mobius iterator float mobius = _m * TWO_PI / (_p/6); // loop through key frames on curve for( j=0; j<_p; j=j+_u ) { i = j + _f; // advance tube by frame iterator // draw sides of tube drawTube( i, HALF_PI * 0 + mobius ); drawTube( i, HALF_PI * 1 + mobius ); drawTube( i, HALF_PI * 2 + mobius ); drawTube( i, HALF_PI * 3 + mobius ); } // persist control iterators _f = ( _f + _c ) % _u; // advance frame iterator if cycling _h = ( _h + _c ) % 360; // advance hue iterator if cycling _m = ( _m + _r ) % (_p/6); // advance mobius iterator if revolving // gui io drawGUI(); }