/*\ * Study to visualize parametrized surfaces * Last editing: May 16, 2005 before PITF workshop * This Flash actionscript file is part of a PITF project * Copyright (C) 2004-2005, Oliver Knill, Harvard University * spin off of PITF project Summer 2004 with Presidential IT fellow * David Mahfouda. Visit website www.math.harvard.edu/~knill/pitf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. \*/ // some global variables alpha = 0.0; // rotation angles beta = 0.4; gamma = 0.0; dgamma=0.3; // increments for rotation dbeta=0.3; dalpha=0.3; x_center = 200; // center of picture y_center = 200; z_center = 200; nu = 13; // number of u divisions nv = 13; // number of v divisions r = 50; // size of surface thick=1; // thickness of lines alpha1 = 0; // parameter 1 for surface dalpha1 = 0.3; alpha2 = 0; // parameter 2 for surface dalpha2 = 0.3; alpha3 = 0; // parameter 3 for surface dalpha3 = 0.3; twopi = 2*Math.PI; // optimization attempts oneovertwopi = 1/twopi; twopiovernu = twopi/nu; // timeline main procedure onEnterFrame = function() { _root.clear(); keys(); surface(); fixangles(); } // keep track of user input and adjust parameters function keys () { if(Key.isDown(Key.UP)) { clear(); gamma = gamma + dgamma; } if(Key.isDown(Key.DOWN)) { clear(); gamma = gamma - dgamma; } if(Key.isDown(Key.LEFT)) { clear(); beta = beta + dbeta; } if(Key.isDown(Key.RIGHT)) { clear(); beta = beta - dbeta; } if(Key.isDown(Key.ENTER)) { clear(); alpha = alpha + dalpha; } if(Key.isDown(Key.BACKSPACE)) { clear(); alpha = alpha - dalpha; } if(Key.isDown(65)) { clear(); alpha1=alpha1+dalpha1; } // key a parameter 1 if(Key.isDown(83)) { clear(); alpha2=alpha2+dalpha2; } // key s parameter 2 if(Key.isDown(68)) { clear(); alpha3=alpha3+dalpha3; } // key d parameter 3 if(Key.isDown(67)) { clear(); nu= 8; nv=8} // key c low resolution if(Key.isDown(88)) { clear(); nu=13; nv=13} // key x middle resolution if(Key.isDown(90)) { clear(); nu=25; nv=25} // key z high resolution cosa = Math.cos(alpha); sina = Math.sin(alpha); cosb = Math.cos(beta); sinb = Math.sin(beta); cosg = Math.cos(gamma); sing = Math.sin(gamma); A=cosa*cosb; B=cosb*sina; C=sinb; D=(-cosg*sina-cosa*sinb*sing); E=( cosa*cosg-sina*sinb*sing); F=cosb*sing; G=(-cosa*cosg*sinb+sina*sing); H=(-cosg*sina*sinb-cosa*sing); II=cosb*cosg; oneovertwopi = 1/twopi; twopiovernu = twopi/nu; } // draw the surface function surface() { aa = 2*Math.cos(alpha1); for (i=0; itwopi) {alpha1-=twopi; } if (alpha1<-twopi) {alpha1 +=twopi } if (alpha2>twopi) {alpha2-=twopi; } if (alpha2<-twopi) {alpha2 +=twopi } if (alpha3>twopi) {alpha3-=twopi; } if (alpha3<-twopi) {alpha3 +=twopi } if (alpha>twopi) {alpha-=twopi; } if (alpha<-twopi) {alpha +=twopi } if (beta>twopi) {beta-=twopi; } if (beta<-twopi) {beta +=twopi } if (gamma>twopi) {gamma-=twopi; } if (gamma<-twopi) {gamma +=twopi } }