Script Part III

This entry deals with vertices and noise mapped to circles.

Circle, noise, and vertices.

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

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

  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);
  }
}
void setup() {
  size(500, 500);
  background(0);

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

  beginShape(); 
  for (int a=0; a<360; a=a+1) { // higher value = more edges 
    float x=cos(radians(a))*radius+xMiddle;
    float y=sin(radians(a))*radius+yMiddle;
    noStroke();
    fill(255);
    vertex(x, y); // connects the dots 
    ellipse (x, y, 1, 1);
  }
  endShape(CLOSE);
  
}
void setup() {
  size(500, 500);
  background(0);

  int xMiddle=width/2; // center of circle
  int yMiddle=height/2; // center of circle
  int radius=200; // radius of circle 
  float aNoise=0;
  
  beginShape(); 
  for (int a=0; a<360; a=a+5) {
    aNoise = aNoise+0.1; // increment aNoise
    float noiseForce = noise(aNoise)*60; // noise
    float x=cos(radians(a))*radius+noiseForce+xMiddle;
    float y=sin(radians(a))*radius+noiseForce+yMiddle;
    
    noStroke();
    fill(255); 
    vertex(x, y); // connects the dots 
    point (x, y);
  }
  endShape(CLOSE);
}
void setup() {
  size(500, 500);
  background(0);

  int xMiddle=width/2; // center of circle
  int yMiddle=height/2; // center of circle
  int radius=200; // radius of circle 
  float aNoise=0;
  
  beginShape(); 
  for (int a=0; a<360; a=a+1) {
    aNoise = aNoise+0.1; // increment aNoise
    float noiseForce = noise(aNoise)*60; // noise
    float x=cos(radians(a))*radius+noiseForce+xMiddle;
    float y=sin(radians(a))*radius+noiseForce+yMiddle;
    
    noStroke();
    fill(255); 
    vertex(x, y); // connects the dots 
    point (x, y);
  }
  endShape(CLOSE);
}
void setup() {
  size(500, 500);
  background(0);
  
  int xMiddle=width/2; // center of circle
  int yMiddle=height/2; // center of circle
  int r=200; // radius of circle 
  
  for (int i=0; i<360; i=i+30) {
    beginShape();
    for (float a=0; a<=360; a=a+2) { 
      float noiseFactor=noise(a/10.)*70;
      float x=cos(radians(a))*(r+noiseFactor-i)+xMiddle;
      float y=sin(radians(a))*(r+noiseFactor-i)+yMiddle;
      curveVertex(x, y); // connects the dots 
      fill(0);
      stroke(255);
    }
    endShape(CLOSE);
  }
}

vertex()

All shapes are constructed by connecting a series of vertices. vertex() is used to specify the vertex coordinates for points, lines, triangles, quads, and polygons. It is used exclusively within the beginShape() and endShape() functions. https://processing.org/reference/vertex_.html

beginShape(POINTS);
vertex(30, 20);
vertex(85, 20);
vertex(85, 75);
vertex(30, 75);
endShape();

Curve Vertex

Curve vertex is a catmull rom spline which is closely related to Bézier curves.


Back to Corona

Experiment #1

void setup() {
  size(500, 500);
  background(220, 110, 110);

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

  for (int i=0; i<360; i=i+5) {
    beginShape();
    for (float a=0; a<=360; a=a+6) { 
      float noiseFactor=noise(a/10.)*100;
      float x=cos(radians(a))*(r+noiseFactor-i)+xMiddle;
      float y=sin(radians(a))*(r+noiseFactor-i)+yMiddle;
      curveVertex(x, y); // connects the dots 
      fill(180, 65, 65);
      strokeWeight(1);
      stroke(220, 80, 80);
    }
    endShape(CLOSE);
  }

  for (int i=0; i<360; i=i+5) {
    beginShape();
    for (float a=0; a<=360; a=a+6) { 
      float noiseFactor=noise(a/10.)*100;
      float x=cos(radians(a))*(r+noiseFactor-i)+xMiddle;
      float y=sin(radians(a))*(r+noiseFactor-i)+yMiddle;
      curveVertex(x, y); // connects the dots 
      drawVirus(x, y, noiseFactor, noiseFactor);
    }
    endShape(CLOSE);
  }
}

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(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);
  fill(white);
  triangle(x+570, y+590, x+510, y+590, x+540, y+525);
  popMatrix();
}

Experiment #2

  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);

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);
    }
  }
  for (int i=0; i<180; i=i+20) {
    int xMiddle=width/2; // center of circle
    int yMiddle=height/2; // center of circle
    int r=100; // radius of circle 
    beginShape();
    for (float a=0; a<=360; a=a+2) { 
      float noiseFactor=noise(a/10.)*70;
      float x=cos(radians(a))*(r+noiseFactor-i)+xMiddle;
      float y=sin(radians(a))*(r+noiseFactor-i)+yMiddle;
      curveVertex(x, y); // connects the dots 
      fill(red);
      strokeWeight(4);
      stroke(lightGreen);
    }
    endShape(CLOSE);
  }
}

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

  // variables relating to virus
  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.015); // 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();
}

Recap

I’m getting better at this but I’m still not quite happy. Also not sure if I am displaying my virus in a sensible way but that’s what I can do 😂 I worked so much on the exercises from the script today so maybe I’m lacking a bit of creativity right now.