CSC103 Processing Lab: Solution Sketches

From dftwiki3
Revision as of 20:28, 17 October 2012 by Thiebaut (talk | contribs) (Created page with "=Solutions= ==Orange Rectangles== <br /> <code><pre> void setup() { size(480, 480 ); smooth(); } void draw() { // ellipse(mouseX, mouseY, 80, 80); fill( 255, 200, 8 ); ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Solutions

Orange Rectangles


void setup() {
  size(480, 480 );
  smooth();
}
 
void draw() {
  // ellipse(mouseX, mouseY, 80, 80);
  fill( 255, 200, 8 );
  rect( mouseX, mouseY, 80, 80 );
}


Swapping mouseX and mouseY


void setup() {
  size(480, 480 );
  smooth();
}
 
void draw() {
  // ellipse(mouseX, mouseY, 80, 80);
  fill( 255, 200, 8 );
  rect( mouseY, mouseX, 80, 80 );
}


Switching between rectangles and circles on mousePressed


void setup() {
  size(480, 480 );
  smooth();
}
 
void draw() {
  //background( 200 );
 
  if ( mousePressed == true ) {
      fill( 231, 47, 39 ); // red
      ellipse(mouseX, mouseY, 80, 80);
  }
  else {
      fill( 255, 200, 8 ); // orange
      rect(mouseX, mouseY, 80, 80);
  }
 
}


Tall-skinny, vs. short-wide Rectangles


void setup() {
  size(480, 480 );
  smooth();
}
 
void draw() {
  //background( 200 );
 
  if ( mousePressed == true ) {
      fill( 231, 47, 39 ); // red
      rect(mouseX, mouseY, 200, 20);
  }
  else {
      fill( 255, 200, 8 ); // orange
      rect(mouseX, mouseY, 20, 100);
  }
 
}


Drawing lines on mousePressed


void setup() {
  size(480, 480 );
  smooth();
}
 
void draw() {
  //background( 200 );
  if ( mousePressed ) {
    line( mouseX, mouseY, pmouseX, pmouseY );
  }
  
}


Vertical Circles


void setup() {
  size( 400, 400 );
  smooth();
}
 
void draw() {
 
  background(200);
 
  // count from 20 to 380 jumping 20 each time.
  for( int x = 20; x < 400; x = x + 20 ) {
 
    // and draw a circle in that position, on a horizontal line.
    fill( 250, 200, 8 );
    ellipse( 200, x, 15,15 ); 
 
  }
}


Cross of Orange Circles


void setup() {
  size( 400, 400 );
  smooth();
}
 
void draw() {
 
  background(200);
 
  // count from 20 to 380 jumping 20 each time.
  for( int x = 20; x < 400; x = x + 20 ) {
 
    // and draw a circle in that position, on a horizontal line.
    fill( 250, 200, 8 );
    ellipse( 200, x, 15,15 ); 
    ellipse( x, 200, 15,15 ); 
 
  }
}


Diagonal Orange Circles


void setup() {
  size( 400, 400 );
  smooth();
}
 
void draw() {
 
  background(200);
  
  // count from 20 to 380 jumping 20 each time.
  for( int x = 20; x < 400; x = x + 20 ) {
       fill( 255, 200, 8 );
       ellipse( x, x, 15, 15 ); 
    }
}


Orange Circles Left of the Mouse


void setup() {
  size( 400, 400 );
  smooth();
}
 
void draw() {
 
  background(200);
  
  // count from 20 to 380 jumping 20 each time.
  for( int x = 20; x < 400; x = x + 20 ) {
    fill( 250, 200, 8 );

    if ( x < mouseX ) {   
       ellipse( x, x, 15,15 ); 
    }
  } 
}


Growing Multicolored Circles


void setup() {
  size( 400, 400 );
  smooth();
}
 
void draw() {
 
  background(200);
  
  // count from 20 to 380 jumping 20 each time.
  for( int x = 20; x < 400; x = x + 20 ) {
    fill( 250, x/2, 255-x/2 );

    if ( x < mouseX ) {   
       ellipse( x, x, x/2,x/2 ); 
    }
  } 
}