Fun Coding Session #5

This Fun Coding Session dealt with noise.

via GIPHY

#1

void setup(){
  size(500,500);
  background(0);
  noStroke();
  for (int x=0;x<width; x=x+20){ // space between rect is 20
    rect(x,height/2,10,10); // line in the middle of canvas
  }
}
void setup(){
  size(500,500);
  background(0);
  noStroke();
  for (int x=0;x<width; x=x+20){ // space between rect is 20
    rect(x,height/2-random(100),10,10); // variation of y pos, random value up to 100
  }
}
void setup() {
  size(500, 500);
  background(0);
  noStroke();
  for (int x=0; x<width; x=x+20) { // space between rect is 20
    float noiseForce = noise(x/100.)*200; // adds noise
    rect(x, height/2-noiseForce, 10, 10); // variation of y pos, random value up to 100
  }
}
void setup() {
  size(500, 500);
  background(255);
  stroke(0);
  for (int x=0; x<width; x=x+10) { // loop for width
    for (int y=0; y<height; y=y+10) { // loop for height
      float size = random(10);
      rect(x, y, size, size);
    }
  }
}

#2 Two Dimensional Noise

void setup() {
  size(500, 500);
  background(255);
  stroke(0);
  for (int x=0; x<width; x=x+10) { // loop for width
    for (int y=0; y<height; y=y+10) { // loop for height
      float noiseForce = noise(x/100., y/100.); // needs to be proportional 
      float size = noiseForce*10; // multiply to increase value
      rect(x, y, size, size);
    }
  }
}

xOff and yOff

off = short for offset

void setup() {
  size(500, 500);
  background(0);
  noStroke();

  float xOff=0., yOff=0.;
  for (int x=0; x<width; x=x+10) { // loop for width
    xOff=xOff+0.01;
    yOff=0;
    for (int y=0; y<height; y=y+10) { // loop for height
    yOff=yOff+0.01;
      float noiseForce = noise(xOff, yOff); // needs to be proportional 
      float size = noiseForce*10; // multiply to increase value
      fill(255);
      rect(x, y, size, size);
    }
  }
}

#3 Circle with dots

void setup() {
  size(500, 500);
  background(0);

  int xMiddle=width/2; 
  int yMiddle=height/2; // center of circle
  int radius=200;

  for (int a=0; a<360; a=a+5) {
    float x=cos(radians(a))*radius+xMiddle;
    float y=sin(radians(a))*radius+yMiddle;
    noStroke();
    fill(255);
    ellipse (x, y, 4, 4);
  }
}

Making a shape with a vertex

vertex = points where you want to draw a line

void setup() {
  size(500, 500);
  beginShape(); 

  vertex(123, 435);
  vertex(153, 415);
  vertex(142, 367);

  endShape(CLOSE);
}
void setup() {
  size(500, 500);
  background(0);

  int xMiddle=width/2; 
  int yMiddle=height/2; // center of circle
  int radius=200;
  beginShape(); 
  for (int a=0; a<360; a=a+5) {
    float x=cos(radians(a))*radius+xMiddle;
    float y=sin(radians(a))*radius+yMiddle;
    noStroke();
    fill(255);
    // catmull-rom spline 
    // babybrother of bezier 
    vertex(x, y); // connects dots 
    ellipse (x, y, 4, 4);
  }
  endShape(CLOSE);
}

Cookie

void setup() {
  size(500, 500);
  background(0);

  int xMiddle=width/2; 
  int yMiddle=height/2; // center of circle
  int radius=200;
  beginShape(); 
  for (int a=0; a<360; a=a+5) {
    float x=cos(radians(a))*radius+xMiddle;
    float y=sin(radians(a))*radius+yMiddle;
    stroke(255);
    strokeWeight(25);
    fill(255);
    // catmull-rom spline 
    // babybrother of bezier 
    vertex(x, y); // connects dots 
    ellipse (x, y, 4, 4);
  }
  endShape(CLOSE);
}

#4

void setup() {
  size(500, 500);
  background(0);

  int xMiddle=width/2; 
  int yMiddle=height/2; // center of circle
  int radius=200;
  float aNoise=0;
  beginShape(); 
  for (int a=0; a<360; a=a+5) {
    aNoise = aNoise+0.1; // increment aNoise
    float noiseForce = noise(aNoise)*50; // noise
    float x=cos(radians(a))*radius+noiseForce+xMiddle;
    float y=sin(radians(a))*radius+noiseForce+yMiddle;
    noStroke();
    fill(255);
    // catmull-rom spline 
    // babybrother of bezier 
    vertex(x, y); // connects dots 
    ellipse (x, y, 4, 4);
  }
  endShape(CLOSE);
}

Recap

This week’s fun coding session was kinda confusing. In the beginning, I understood everything especially because I try everything out while it is being discussed. But the more questions came up with more explanations I got more confused. However, I will work through the chapter in the book and try out the stuff from the script and will hopefully manage to understand everything.