Script Part II

I continued to work with the script and to make some own experiments with my Corona.

From the script

void setup() {
  size(1000, 1000);
  noStroke();
   for (int x=0; x<width; x=x+10) {
     for (int y=0; y<height; y=y+10) {
      float noiseFactor=noise(x/100., y/100.)*10;
      drawElement(x,y,noiseFactor);
    }
  }
}
 
void drawElement(float x, float y, float noiseFactor){
      rect(x, y, noiseFactor, noiseFactor);
}

Noise mapped to rotation

PushMatrix() / popMatrix()

“Pushes the current transformation matrix onto the matrix stack. Understanding pushMatrix() and popMatrix() requires understanding the concept of a matrix stack. The pushMatrix() function saves the current coordinate system to the stack and popMatrix() restores the prior coordinate system. pushMatrix() and popMatrix() are used in conjunction with the other transformation functions and may be embedded to control the scope of the transformations.” https://processing.org/reference/pushMatrix_.html

translate()

translate() moves the origin [0,0] for drawing commands from the top-left corner to a new position.

rotate()

Rotates the amount specified by the angle parameter. Angles must be specified in radians (values from 0 to TWO_PI), or they can be converted from degrees to radians with the radians() function. The coordinates are always rotated around their relative position to the origin.

void setup() {
  size(500, 500);
  background(0);
  noStroke();
  for (int x=0; x<width; x=x+10) {
    for (int y=0; y<height; y=y+10) {
      float noiseFactor=noise(x/1000., y/1000.)*10;
      drawElement(x, y, noiseFactor);
    }
  }
}
 
void drawElement(float x, float y, float noiseFactor) {
  stroke(255,150);
  pushMatrix();
  translate(x, y);
  rotate(noiseFactor*radians(360));
  line(0, 0, 70, 0);
  popMatrix();
}

pushMatrix(), translate(), rotate(), and popMatrix() work together to rotate a line in proportion to the noiseFactor — the larger the noiseFactor, the more the line will be rotated.

Corona Time

Experiment #1

void setup() {
  size(500, 500);
  background(220, 110, 110);
  for (int x=0; x<width; x=x+5) {
    for (int y=0; y<height; y=y+10) {
      float noiseFactor=noise(x/1000., y/1000.)*10;
      drawVirus(x, y, noiseFactor, noiseFactor);
    }
  }
}
 
void drawVirus(float x, float y, float noiseFactor, float size) {
  pushMatrix();
  translate (x, y); 
  rotate(noiseFactor*radians(360));

  // variables relating to virus
  int darkGreen = color(100, 200, 220);
  int lightGreen = color(110, 220, 225);
  int white = color(255);
  int black = color(0);
  int red = color(220, 80, 80);
  int darkRed = color(180, 65, 65);
  float body = 500;
  float freckles = 20;
  float eye = 120;
  float pupil = 30;
  float mouthH = 20;
  float mouthW = 160;
  float tongueH = 10;
  float tongueW = 120;
  scale(0.02); // scale down size of virus
  stroke(0);
  ellipseMode(CENTER);
  fill(darkGreen);
  noStroke();
  ellipse(x, y, body, body);
  fill(white);
  ellipse(x, y-60, eye, eye);
  fill(black);
  ellipse(x, y-60, pupil, pupil);
  rectMode(CENTER);
  fill(black);
  rect(x, y+100, mouthW, mouthH);
  fill(red);
  rect(x-10, y+105, tongueW, tongueH);
  fill(white);
  triangle(x-70, y+90, x-10, y+90, x-40, y+125);
  triangle(x-10, y+90, x+50, y+90, x+20, y+140);
  fill(lightGreen);
  noStroke();
  ellipse(x-125, y, freckles, freckles);
  ellipse(x-90, y+25, freckles, freckles);
  ellipse(x+100, y+15, freckles, freckles);
  ellipse(x+100, y+40, freckles, freckles);
  ellipse(x+145, y+20, freckles, freckles);
  ellipse(x-145, y+45, freckles, freckles);

  popMatrix();
}

With the above code, I played around with the different values and screenshoted some of the examples.

void setup () {
  size (500, 500);
  background(0);
  PImage myImage = loadImage ("corona.png");
  noStroke();
  for (int x=0; x<width; x=x+10) {
    for (int y=0; y<height; y=y+10) {
      color c = myImage.get(x, y);
      fill(c);
      float noiseFactor =noise(x/100., y/100.)*50;
      drawElement(x, y, noiseFactor);
    }
  }
}

void drawElement (float x, float y, float noiseFactor) {
  pushMatrix();
  translate(x, y);
  rotate(noiseFactor*radians(360));
  rect(0, 0, 2, 10);
  popMatrix();
}
void setup () {
  size (500, 500);
  background(0);
  PImage myImage = loadImage ("corona.png");
  for (int x=0; x<width; x=x+5) {
    for (int y=0; y<height; y=y+5) {
      color c = myImage.get(x, y);
      fill(c);
      float noiseFactor =noise(x/1500., y/50.)*15;
      drawElement(x, y, noiseFactor);
    }
  }
}

void drawElement (float x, float y, float noiseFactor) {
  pushMatrix();
  translate(x, y);
  rotate(noiseFactor*radians(360));
  noStroke();
  ellipse(noiseFactor, noiseFactor, 3, 3);
  popMatrix();
}

Experiment #2

void setup() {
  size(500, 500);
  background(220, 110, 110);
  for (int x=0; x<width; x=x+10) {
    for (int y=0; y<height; y=y+50) { 
      float noiseFactor=noise(x, y)*220;
      drawVirus(x, y, noiseFactor, noiseFactor);
    }
  }
}
void drawVirus(float x, float y, float noiseFactor, float size) {
  pushMatrix();
  translate (x, y); 
  rotate(noiseFactor*radians(360));

  // variables relating to virus
  int darkGreen = color(100, 200, 220);
  int lightGreen = color(110, 220, 225);
  int white = color(255);
  int black = color(0);
  int red = color(220, 80, 80);
  int darkRed = color(180, 65, 65);
  float body = 500;
  float freckles = 20;
  float eye = 120;
  float pupil = 30;
  float mouthH = 20;
  float mouthW = 160;
  float tongueH = 10;
  float tongueW = 120;
  scale(0.01); // scale down size of virus
  stroke(0);
  ellipseMode(CENTER);
  fill(darkGreen);
  noStroke();
  ellipse(x, y, body, body);
  fill(white);
  ellipse(x, y-60, eye, eye);
  fill(black);
  ellipse(x, y-60, pupil, pupil);
  rectMode(CENTER);
  fill(black);
  rect(x, y+100, mouthW, mouthH);
  fill(red);
  rect(x-10, y+105, tongueW, tongueH);
  fill(white);
  triangle(x-70, y+90, x-10, y+90, x-40, y+125);
  triangle(x-10, y+90, x+50, y+90, x+20, y+140);
  fill(lightGreen);
  noStroke();
  ellipse(x-125, y, freckles, freckles);
  ellipse(x-90, y+25, freckles, freckles);
  ellipse(x+100, y+15, freckles, freckles);
  ellipse(x+100, y+40, freckles, freckles);
  ellipse(x+145, y+20, freckles, freckles);
  ellipse(x-145, y+45, freckles, freckles);

  popMatrix();
}

Experiment #3

void setup() {
  size(500, 500);
  background(220, 110, 110);
  for (int x=0; x<width; x=x+5) {
    for (int y=0; y<height; y=y+100) { 
      float noiseFactor=noise(x, y)*100;
      drawVirus(x, y, noiseFactor, noiseFactor);
    }
  }
}
void drawVirus(float x, float y, float noiseFactor, float size) {
  pushMatrix();
  translate (x, y); 
  rotate(noiseFactor*radians(360));

  // variables relating to virus
  int darkGreen = color(100, 200, 220);
  int lightGreen = color(110, 220, 225);
  int white = color(255);
  int black = color(0);
  int red = color(220, 80, 80);
  int darkRed = color(180, 65, 65);
  float body = 500;
  float freckles = 20;
  float eye = 120;
  float pupil = 30;
  float mouthH = 20;
  float mouthW = 160;
  float tongueH = 10;
  float tongueW = 120;
  scale(0.04); // scale down size of virus
  stroke(0);
  ellipseMode(CENTER);
  fill(darkGreen);
  noStroke();
  ellipse(x, y, body, body);
  fill(white);
  ellipse(x, y-60, eye, eye);
  fill(black);
  ellipse(x, y-60, pupil, pupil);
  rectMode(CENTER);
  fill(black);
  rect(x, y+100, mouthW, mouthH);
  fill(red);
  rect(x-10, y+105, tongueW, tongueH);
  fill(white);
  triangle(x-70, y+90, x-10, y+90, x-40, y+125);
  triangle(x-10, y+90, x+50, y+90, x+20, y+140);
  fill(lightGreen);
  noStroke();
  ellipse(x-125, y, freckles, freckles);
  ellipse(x-90, y+25, freckles, freckles);
  ellipse(x+100, y+15, freckles, freckles);
  ellipse(x+100, y+40, freckles, freckles);
  ellipse(x+145, y+20, freckles, freckles);
  ellipse(x-145, y+45, freckles, freckles);

  popMatrix();
}

Experiment #4

void setup() {
  size(500, 500);
  background(220, 110, 110);
  int xMiddle=width/2; // start in the middle
  int yMiddle=height/2;
  int r=150;
  for (float a=0; a<360; a=a+15) { // distance between viruses
    //radiand of cos
    float x=cos(radians(a))*r+xMiddle;
    //radiand of sin
    float y=sin(radians(a))*r+yMiddle;
    float xOff=x/100.;
    float yOff=y/100.;
    float noiseFactor=noise(xOff, yOff)*13;
    drawVirus(x, y, noiseFactor, noiseFactor);
  }
}

void drawVirus(float x, float y, float noiseFactor, float size) {
  pushMatrix();
  translate (x, y); 
  rotate(noiseFactor*radians(360));

  // variables relating to virus
  int darkGreen = color(100, 200, 220);
  int lightGreen = color(110, 220, 225);
  int white = color(255);
  int black = color(0);
  int red = color(220, 80, 80);
  int darkRed = color(180, 65, 65);
  float body = 500;
  float freckles = 20;
  float eye = 120;
  float pupil = 30;
  float mouthH = 20;
  float mouthW = 160;
  float tongueH = 10;
  float tongueW = 120;
  scale(0.04); // scale down size of virus
  stroke(0);
  ellipseMode(CENTER);
  fill(darkGreen);
  noStroke();
  ellipse(x, y, body, body);
  fill(white);
  ellipse(x, y-60, eye, eye);
  fill(black);
  ellipse(x, y-60, pupil, pupil);
  rectMode(CENTER);
  fill(black);
  rect(x, y+100, mouthW, mouthH);
  fill(red);
  rect(x-10, y+105, tongueW, tongueH);
  fill(white);
  triangle(x-70, y+90, x-10, y+90, x-40, y+125);
  triangle(x-10, y+90, x+50, y+90, x+20, y+140);
  fill(lightGreen);
  noStroke();
  ellipse(x-125, y, freckles, freckles);
  ellipse(x-90, y+25, freckles, freckles);
  ellipse(x+100, y+15, freckles, freckles);
  ellipse(x+100, y+40, freckles, freckles);
  ellipse(x+145, y+20, freckles, freckles);
  ellipse(x-145, y+45, freckles, freckles);

  popMatrix();
}
void setup() {
  size(500, 500);
  background(220, 110, 110);
  int xMiddle=width/2; // start in the middle
  int yMiddle=height/2;
  int r=150;
  for (float a=0; a<360; a=a+15) { // distance between viruses
    //radiand of cos
    float x=cos(radians(a))*r+xMiddle;
    //radiand of sin
    float y=sin(radians(a))*r+yMiddle;
    float xOff=x/100.;
    float yOff=y/100.;
    float noiseFactor=noise(xOff, yOff)*13;
    drawVirus(x, y, noiseFactor, noiseFactor);
  }
}

void drawVirus(float x, float y, float noiseFactor, float size) {
  pushMatrix();
  translate (x, y); 
  rotate(noiseFactor*radians(360));

  // variables relating to virus
  int darkGreen = color(100, 200, 220);
  int lightGreen = color(110, 220, 225);
  int white = color(255);
  int black = color(0);
  int red = color(220, 80, 80);
  int darkRed = color(180, 65, 65);
  float body = 500;
  float freckles = 20;
  float eye = 120;
  float pupil = 30;
  float mouthH = 20;
  float mouthW = 160;
  float tongueH = 10;
  float tongueW = 120;
  scale(0.04); // scale down size of virus
  for (int a=0; a<360; a=a+40) {
    //dots around virus
    int dx = (int)(cos(radians(a))*360);
    int dy = (int)(sin(radians(a))*360);
    noStroke();
    fill(darkRed);
    rect(300+dx, 300+dy, 150, 150);
  }
  for (int a=0; a<360; a=a+25) {
    //dots around virus
    int dx = (int)(cos(radians(a))*360);
    int dy = (int)(sin(radians(a))*360);
    noStroke();
    fill(255);
    ellipse(400+dx, 400+dy, 50, 50);
  }
  stroke(0);
  ellipseMode(CENTER);
  fill(darkGreen);
  noStroke();
  ellipse(x, y, body, body);
  fill(white);
  ellipse(x, y-60, eye, eye);
  fill(black);
  ellipse(x, y-60, pupil, pupil);
  rectMode(CENTER);
  fill(black);
  rect(x, y+100, mouthW, mouthH);
  fill(red);
  rect(x-10, y+105, tongueW, tongueH);
  fill(white);
  triangle(x-70, y+90, x-10, y+90, x-40, y+125);
  triangle(x-10, y+90, x+50, y+90, x+20, y+140);
  fill(lightGreen);
  noStroke();
  ellipse(x-125, y, freckles, freckles);
  ellipse(x-90, y+25, freckles, freckles);
  ellipse(x+100, y+15, freckles, freckles);
  ellipse(x+100, y+40, freckles, freckles);
  ellipse(x+145, y+20, freckles, freckles);
  ellipse(x-145, y+45, freckles, freckles);
  
  
  popMatrix();
}

Recap

This was kinda fun. I especially like those wavy designs which remind me of a blanket. Trying out with low and high values helped me a little to understand what is happening. Working with the code from the script made it easier for me to adapt my own code. I also looked into previous exercises with functions to make it easier for me to use the virus. My main issue is that I can make it work and I try out the values and different code but I still don’t fully understand it in order to explain what is happening.