Generative Art: Designing With Code

  • All of the designs shown above are created using this code: 
    void setup()
    {
      size(1400,500);
      background(255);  
    }
    void draw()
    {  
      if (keyPressed && key == 'z') { //diamond background
        background(255);
        noFill();
        noStroke(); 
        for (int i = 0; i < 100; i = i+1) {
          strokeWeight(0.1);  
          stroke(28,27,24);
          quad(i*0,i*50,i*30,i*0,i*60,i*50,i*30,i*100); 
        }  
        for (int i = 0; i < 100; i = i+10) {
          strokeWeight(0.1); 
          stroke(103,101,93);
          quad(i*10,i*50,i*30,i*10,i*60,i*50,i*30,i*100); 
        }
      }  
      if (keyPressed && (key == 'a')) { //abstract triangles
        for (int i = 0; i < 100; i = i+1) {
          noFill();
          stroke(0,random(255),random(255),30);
          quad(i*mouseX,i*mouseY,i*mouseY,i*0,mouseX,i*mouseY,i*100,i*mouseX);
        }
      }
      if (keyPressed && (key == 'b')) { //green blue circles white stroke
        stroke(255);
        fill(0,random(255),random(255),30);
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      if (keyPressed && (key == 'l')) { //green blue circles light black stroke
        stroke(0,20);
        fill(0,random(255),random(255),30);
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      
      if (keyPressed && (key == 'c')) {
        strokeWeight(1);
        stroke(206,92,90);
        noFill();
        triangle(700,250,random(400),random(400),0,0);
        triangle(700,250,random(300),random(300),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
      
        triangle(400,400,800,800,random(400,800),random(400,800));
        triangle(400,400,800,800,random(500,800),random(500,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
      }
      if (keyPressed && (key == 'd')) {
        strokeWeight(1);
        stroke(206,92,90);
        noFill();
        triangle(700,250,random(400),random(400),1400,0);
        triangle(700,250,random(300),random(300),1400,0);
        triangle(700,250,random(200),random(200),1400,0);
        triangle(700,250,random(200),random(200),1400,0);
        triangle(700,250,random(200),random(200),1400,0);
        triangle(700,250,random(200),random(200),1400,0);
        triangle(700,250,random(200),random(200),1400,0);
      
        triangle(400,400,1400,800,random(400,800),random(400,800));
        triangle(400,400,1400,800,random(500,800),random(500,800));
        triangle(400,400,1400,800,random(600,800),random(600,800));
        triangle(400,400,1400,800,random(600,800),random(600,800));
        triangle(400,400,1400,800,random(600,800),random(600,800));
        triangle(400,400,1400,800,random(600,800),random(600,800));
        triangle(400,400,1400,800,random(600,800),random(600,800));
      }
      if (keyPressed && (key == 'e')) {
        strokeWeight(1);
        stroke(206,92,90);
        noFill();
        triangle(700,250,random(800,400),random(400),1400,0);
        triangle(700,250,random(800,300),random(300),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
      
        triangle(400,400,1400,800,random(400),random(400,800));
        triangle(400,400,1400,800,random(500),random(500,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
      } 
      if (keyPressed && (key == 'f')) { 
        strokeWeight(1);
        stroke(206,92,90);
        noFill();
        triangle(700,500,random(800,400),random(400),1400,400);
        triangle(700,1000,random(800,300),random(300),1400,400);
        triangle(700,1000,random(800,200),random(200),1400,400);
        triangle(700,500,random(800,200),random(200),1400,400);
        triangle(700,1000,random(800,200),random(200),1000,400);
        triangle(700,1000,random(800,200),random(200),1400,400);
        triangle(700,500,random(800,200),random(200),1400,400);
      
        triangle(400,400,1400,800,random(400),random(400,800));
        triangle(400,400,1400,800,random(500),random(500,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
      }
     
      
      if (keyPressed && (key == 'g')) {  //pinkstroke big blue
        stroke(251,137,135);
        fill(37,165,165);
        ellipse(mouseX,mouseY,random(300),random(300)); 
      }
      if (keyPressed && (key == 'h')) { //red shade
        noStroke();
        fill(random(255),0,random(50),10);
        ellipse(mouseX,mouseY,random(30),random(30));
      }
      if (keyPressed && (key == 'i')) { //pink circles
        noStroke();
        fill(251,137,135);
        ellipse(mouseX,mouseY,random(30),random(30));
      }
      if (keyPressed && (key == 'j')) { //small pink strokes
        stroke(251,137,135);
        noFill();
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      if (keyPressed && (key == 'k')) {  //blue circles
        noStroke();
        fill(37,165,165,50);
        ellipse(mouseX,mouseY,random(100),random(100)); 
      }
      if (keyPressed && (key == 'm')) { //circles with pink-red stroke
        stroke(164,137,137);
        noFill();
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      if (keyPressed && (key == 'n')) { //greyish dots
        stroke(126,126,126);
        fill(126,126,126);
        ellipse(mouseX,mouseY,random(10),random(10));
      }
      if (keyPressed && (key == 'o')) { //red shade big
        noStroke();
        fill(random(255),0,random(50),10);
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      if (keyPressed && (key == 'p')) { //white dots
        stroke(255);
        fill(255);
        ellipse(mouseX,mouseY,random(5),random(5));
      }
      if (keyPressed && (key == 'q')) { //pink small small dots
        stroke(251,137,135);
        fill(251,137,135);
        ellipse(mouseX,mouseY,random(5),random(5));
      }
      if (keyPressed && (key == 't')) { //circles with blueish stroke
        stroke(81,112,113);
        noFill();
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      if (keyPressed && (key == 'u')) { //circles with white stroke
        stroke(255,200);
        noFill();
        ellipse(mouseX,mouseY,random(100),random(100));
      }
      
      if (keyPressed && (key == 'v')) {
        strokeWeight(1);
        stroke(255,200);
        noFill();
        triangle(700,250,random(400),random(400),0,0);
        triangle(700,250,random(300),random(300),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
        triangle(700,250,random(200),random(200),0,0);
      
        triangle(400,400,800,800,random(400,800),random(400,800));
        triangle(400,400,800,800,random(500,800),random(500,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
        triangle(400,400,800,800,random(600,800),random(600,800));
      }
      if (keyPressed && (key == 'w')) {
        strokeWeight(1);
        stroke(255,200);
        noFill();
        triangle(700,250,random(800,400),random(400),1400,0);
        triangle(700,250,random(800,300),random(300),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
        triangle(700,250,random(800,200),random(200),1400,0);
      
        triangle(400,400,1400,800,random(400),random(400,800));
        triangle(400,400,1400,800,random(500),random(500,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        
      }
      if (keyPressed && (key == 'x')) { 
        strokeWeight(1);
        stroke(255,200);
        noFill();
        triangle(700,500,random(800,400),random(400),1400,400);
        triangle(700,1000,random(800,300),random(300),1400,400);
        triangle(700,1000,random(800,200),random(200),1400,400);
        triangle(700,500,random(800,200),random(200),1400,400);
        triangle(700,1000,random(800,200),random(200),1000,400);
        triangle(700,1000,random(800,200),random(200),1400,400);
        triangle(700,500,random(800,200),random(200),1400,400);
      
        triangle(400,400,1400,800,random(400),random(400,800));
        triangle(400,400,1400,800,random(500),random(500,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
        triangle(400,400,1400,800,random(600),random(600,800));
      }
    }

    void keyPressed() {
      if (key == 'r') {
        beginRecord(PDF, "page_" + int(random(10000)) + ".pdf");
      }
      if (key == 's') {
        endRecord();
      }
    }