User Tools

Site Tools


courses:2009.03.04.vector.loops

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:2009.03.04.vector.loops [2009/03/06 00:00]
camille more comment in the code
courses:2009.03.04.vector.loops [2009/03/06 00:03] (current)
camille more comment in the code
Line 1: Line 1:
 +====== march 04 2009: vector shapes and loops ======
 +==== Using vector shape in Processing ====
 +
 +  * Create a SVG file in Illustrator. If you use a ready-made symbol from the library, remember to right-click and "Break link to symbol"​. Save the file as SVG (see image below for settings).
 +{{:​courses:​vector_save_svg.jpg|}}
 +  * Make sure the SVG file is located in the same folder as your Processing .pde file. Download {{:​courses:​crow.svg.zip|}}
 +  * Processing code for loading and displaying the vector shape <code java>
 +// Loading a shape when using setup() and draw()
 +
 +PShape s;
 +
 +void setup() {
 +  size(800, 600);
 +  s = loadShape("​crow.svg"​);​ // file needs to be located in the sketch folder
 +  smooth();
 +  noLoop(); // no looping here, comment if you need dynamic sketch
 +  shapeMode(CENTER);​ // draw from center point of the shape
 +}
 +
 +void draw() {
 +  shape(s, 400, 300); // display the shape on the stage, no size specified
 +  // shape(s, 400, 300, 100, 100);  // if you need to specify the width and height
 +}
 +</​code>​
 +  {{:​courses:​vector_crow.jpg|}}
 +
 +==== For loops to generate graphics/​patterns ====
 +
 +   * <code java>
 +float rotationVal = 0; 
 +
 +void setup(){
 +  size(900, 600, P3D); // P3D needed to activate 3D functions and capabilities
 +  //smooth();
 +  rectMode(CENTER); ​ // we draw rect from the center
 +}
 +
 +void draw(){
 +
 +  background(100);​ // clear the background
 +
 +  for(float j = 0; j < 15; j++){ // loop for rows
 +
 +    for(float i = 0; i < 30; i++){  // loop for columns
 +      ​
 +      // save the current reference transformation matrix
 +      pushMatrix(); ​
 +      ​
 +      // local transformation
 +      translate(i * 50, j * 50);
 +      rotateZ(tan(i * j * mouseX/​50000));​
 +      rect(0, 0, 70, 70); // draw at local x,y coordinates
 +      ​
 +      // restore to saved matrix, out of local reference
 +      popMatrix();​
 +
 +    } // end of loop for column
 +
 +  } // end of loop for row
 +
 +  //​saveFrame();​ // if you want to generate tiff for each frame => quicktime sequence
 +}
 +</​code>​
 +{{:​courses:​for_loops_generative.jpg|}}
 +
  
courses/2009.03.04.vector.loops.txt · Last modified: 2009/03/06 00:03 by camille