WEEK 2: Tut 2, 3, 4

by Sarah Shultz

Tut 2: Elements of Code

  • Show Code
/** @peep sketch */
 
// change the background color to any random color in the rgb spectrum, each time the code is refreshed
size(200, 200);
background(random(255), random(255), random(255));

Tut 3: Drawing with Code

  • Show Code
/** @peep sketch */
 
// draws circls in random placements throughout the sketch, along with color and stroke weight, each time the code is refreshed
size(300, 300);
 
stroke(random(255));
strokeWeight(random(1,3));
fill(random(255), random(255), random(255));
ellipse(random(width), random(height), 50, 50);
 
stroke(random(255));
strokeWeight(random(1,3));
fill(random(255), random(255), random(255));
ellipse(random(width), random(height), 50, 50);
 
stroke(random(255));
strokeWeight(random(1,3));
fill(random(255), random(255), random(255));
ellipse(random(width), random(height), 50, 50);
 
stroke(random(255));
strokeWeight(random(1,3));
fill(random(255), random(255), random(255));
ellipse(random(width), random(height), 50, 50);

Tut 4: Drawing with Colour

  • Show Code
/** @peep sketch */
// draws three filled circles that overlap
size(300, 300);
background(255); 
noStroke(); 
smooth(); 
 
fill(242, 204, 47, 160); // Yellow 
ellipse(94, 72, 128, 128); 
 
fill(174, 221, 60, 160); // Green 
ellipse(180, 94, 128, 128); 
 
fill(116, 193, 206, 160); // Blue 
ellipse(114, 158, 128, 128);
  • Show Code
/** @peep sketch */
// the same sketch as before, just without the fill and a random stroke weight between 1 and 8, each time the code is refreshed 
size(300, 300);
background(255); 
noFill();
strokeWeight(random(1,8)); 
smooth(); 
 
stroke(242, 204, 47, 160); // Yellow 
ellipse(94, 72, 128, 128); 
 
stroke(174, 221, 60, 160); // Green 
ellipse(180, 94, 128, 128); 
 
stroke(116, 193, 206, 160); // Blue 
ellipse(114, 158, 128, 128);
  • Show Code
/**@peep sketch */
size(256, 256);
colorMode(RGB);
for (int i = 0; i < width; i++) { 
  stroke(i, 255, 255); 
  line(i, 0, i, height); 
}

The two sketches above and below show the differences between using RGB and HSB values. RGB values are seen above while HSB values are used below

  • Show Code
/** @peep sketch */
size(256, 256);
colorMode(HSB); 
for (int i = 0; i < width; i++) { 
  stroke(i, 255, 255); 
  line(i, 0, i, height); 
}
  • Show Code
/** @peep sketch */
// THIS IS THE MOST HELPFUL PIECE OF CODE I THINK I COULD USE THUS FAR, b/c it is so much easier to refer back to the same color when it is stored in a variable!
color ruby = color(211, 24, 24, 160); 
color pink = color(237, 159, 176);
size(200, 200);
background(pink); 
noStroke(); 
fill(ruby); 
rect(35, 0, 20, 100);

Tut: 2, 3, 4 combined Custom Code Exercise

  • Show Code
/** @peep sketch */
 
// set up and define variables
     int startingPoint = 250;
      int x = 250;
      int y = 250;
      int fillColor1 = 255;
      int fillColor2 = 0;
      int fillColor3 = 200;
      float s = 1.0;
 
// setup canvas
void setup () {
      size (400, 400);
      background (0);
      smooth();
      noStroke();     
} //end setup
 
void draw () {
  background(0);
 
 
      if (x >=50 & y>=50) {
            //draw starting biggest circle
      fill(255, 76, 76);
        pushMatrix();
          fillColor1-=100;
          fillColor2+=10;
          fillColor3-=10;
          x--;
          y--;
          scale(s-.1);
          fill(fillColor1, fillColor2, fillColor3);
          ellipse(startingPoint, startingPoint,x, y);
        popMatrix();
      }
 
      else {
        pushMatrix();
          fillColor1-=10;
          fillColor2+=10;
          fillColor3-=10;
          x--;
          y--;
          scale(s-.1);
          fill(fillColor1, fillColor2, fillColor3);
          ellipse(startingPoint, startingPoint,x, y);
        popMatrix();
 
      }
 
 
     }

Comments

Nobody has said anything yet.