marcia 
		
		YaBB Newbies
		 
		Offline 
		
		
		Posts: 6
		
		
		
		
 
	 
	
		
			
				Re: Kaleidoscope  
				Reply #2 -  Aug 27th , 2008, 5:25am 
			 
			
				
	  
			 
		
		
			//-----Code continued from previous post---------   void rot() {     for(int i=0; i<n; i++) {       float x = xvertices[i];               // get vertices from object        float y = yvertices[i];        float r = sqrt(pow(x, 2) + pow(y, 2)); // Convert to polar:  compute radius       float theta = atan2 (x, y);            // compute angle       theta = theta + angle * rots++;        // rotate by angle       float x1 =r * cos(theta + angle);      // compute new points       float y1 = r * sin(theta + angle);     // put them back in object array       xverticesR[i] = x1;       yverticesR[i] = y1;        }   }   void trans() {                             // adjust object position based on its individual movement     for(int i=0; i<n; i++) {       xverticesR[i] = xvertices[i] + xincr;       yverticesR[i] = yvertices[i] + yincr;     }   }   void place() {                             // draw the repositioned shape on the kw workspace      kw.beginDraw();     kw.fill(c,t);                            // the color c and also the alpha value for opacity, t     //    kw.stroke(st);     kw.noStroke();                           // nostroke looks better     //    kw.stroke(0);     kw.beginShape();                         // build the shape in the kw buffer     for(int i = 0; i<n; i++ ) {       kw.vertex(xverticesR[i]+cx, yverticesR[i]+cy);  // define all the vertices     }     kw.endShape(CLOSE);     kw.endDraw();   }   void changeTrajectory() {     xincr = xincr + random(-d/100,d/100);          // modify translation speed     yincr = yincr + random(-d/100,d/100);   }   void changeRot(){     angle = angle + random(-PI, PI)/360;          // modify shape's rotation speed     rots = 0;                              } } void mirror() {    color p;   kw.beginDraw();   fi.beginDraw();   for (int y=0; y<(d/2); y++) {  // copy wedge-shaped 1/8 of square     for (int x=y; x<(d/2); x++) {       p = kw.get(x,y);           // get one pixel from the workspace       fi.set (x,y,p);            // put it to the "final" composed workspace        fi.set (y,x,p);       fi.set (x,d-y-1,p);       fi.set (y,d-x-1,p);         fi.set (d-x-1,y,p);       fi.set (d-x-1,d-y-1,p);       fi.set (d-y-1,x,p);       fi.set (d-y-1,d-x-1,p);         }   }   fi.endDraw();   kw.endDraw(); } void mousePressed() {    // randomize many of the variables, clear screen, create new shapes   kw.beginDraw();        // clear the buffer   kw.fill(0);   kw.rect(0,0,d,d);      // erase by drawing canvas-sized black rectangle   kw.endDraw();   maxVertices = int(random(4,9));   minVertices = int(random(3,maxVertices));   numShapes = int(random(4,20));   for (int i=1; i<numShapes; i++) {     shapes[i] = new Shape();   } } //---------end of code---------