Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
let shape,n;//shape pattern id and n counter
let sArray=[];
let snipe;
let feathers; 
function preload() {
  feathers = loadImage('https://assets.codepen.io/4559259/feathers.png');
  snipe = loadImage('https://assets.codepen.io/4559259/snipecropped.png')
}

function setup(){
createCanvas(windowWidth,windowHeight);//flexible canvas
  n=floor(random(3,5))
  angleMode(DEGREES)//degree mode
  shape=floor(random(0,8))//random shape ID
  background(0);//black background
  translate(width/2,height/2);//center at (0,0)
  textSet()//setup text
  createRules()//creates pattern
}
function textSet(){//words on screen
  textSize(20);
  fill(255)
  text("One",-width/2+20,-height/2+20)
  text("Two",width/100,-height/2+20)
  text("Three",-width/2+20,height/2-20)
  text("Four?", width/100,height/5)
  textSize(10);
  text("Click for a new pattern", width/100,height/3)
}
function mousePressed(){
  n=floor(random(3,5))
  setup();//run code when mouse is pressed for a new pattern
}
function createRules(){
  sArray= [];
  if (shape===0){
    shape1();
  } else if( shape ===1){
    shape2();
  } else if(shape===2){
   shape3();
  }else if(shape===3){
   shape4();
  }
  else if(shape===4){
   shape5();
  }else if(shape===5){
   shape6();
  }else if(shape===6){
   shape7()
   }else if(shape===7){
     shape8();
   }
}
function polygon(x, y, radius, npoints) { //from p5js.org
  let angle = 360 / npoints;
  beginShape();
  for (let a = 0; a < 360; a += angle) {
    let sx = x + cos(a) * radius;
    let sy = y + sin(a) * radius;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}
function shape1(){ //square pattern blocks with growth
  p=min(width,height)/30;//size of squares
   for (let i=0;i<n;i++){
      for (let j=0;j<n;j++){
        sArray[i]=[round(random(0,1)),round(random(0,1))];
        if (sArray[i][0]===1){
          fill(145-10*i,240-i*j,275-30*j)
          //case1
          rect(-width/3+i%n*p,-height/3+j%n*p,p,p);
          //case2
          rect(width/6+i%n*p,-height/3+j%n*p,p,p);
          if(i%n===0 && sArray[i][1]===1){
            rect(width/6+i%n*p-p,-height/3+j%n*p,p,p);
          }
          if(i%n===n-1 && sArray[i][1]===1){
            rect(width/6+i%n*p+p,-height/3+j%n*p,p,p); 
          }
          if(j%n===0 && sArray[i][1]===1){
            rect(width/6+i%n*p,-height/3+j%n*p-p,p,p);
          }
          if(j%n===n-1 && sArray[i][1]===1){
            rect(width/6+i%n*p,-height/3+j%n*p+p,p,p); 
          }
          //case3
          rect(-width/3+i%n*p,height/6+j%n*p,p,p);
          if(i%n===0 && sArray[i][1]===1){
            rect(-width/3+i%n*p-p,height/6+j%n*p,p,p);
            rect(-width/3+i%n*p-2*p,height/6+j%n*p,p,p);
          }
          if(i%n===n-1 && sArray[i][1]===1){
            rect(-width/3+i%n*p+p,height/6+j%n*p,p,p);
            rect(-width/3+i%n*p+2*p,height/6+j%n*p,p,p); 
          }
          if(j%n===0 && sArray[i][1]===1){
            rect(-width/3+i%n*p,height/6+j%n*p-p,p,p);
            rect(-width/3+i%n*p,height/6+j%n*p-2*p,p,p);
          }
          if(j%n===n-1 && sArray[i][1]===1){
            rect(-width/3+i%n*p,height/6+j%n*p+p,p,p);
            rect(-width/3+i%n*p,height/6+j%n*p+2*p,p,p); 
          }
        }
      }
    }
}
function shape2(){ //hexagon growth pattern
  r=min(width,height)/40;
  for (let i=0;i<n;i++){
      for (let j=0;j<n;j++){
        sArray[i]=[round(random(0,1)),round(random(0,1))];
         fill(135-10*i,130-i*j,255-30*j)
        if (sArray[i][0]===1){
          x = r * j * 1.5;
          y = -r * 12 + r * sqrt(3) * i + r * j / 1.15;
          //case1
          polygon(-width/5-x,y-height/9,r,6);
          //case2
          polygon(width/5-x,y-height/9,r,6);
          if(i%n===0 && sArray[i][1]===1){
            y2 = -r * 12 + r * sqrt(3) * (i) + r * (j-2) / 1.15;
            polygon(width/5-x,y2-height/9,r,6);
          }
          if(i%n===n-1 && sArray[i][1]===1){
            y2 = -r * 12 + r * sqrt(3) * i + r * (j+2) / 1.15;
            polygon(width/5-x,y2-height/9,r,6);
          }
          if(j%n===0 && sArray[i][1]===1){
            x2 = r * (j+1) * 1.5;
            y2 = -r * 12 + r * sqrt(3) * (i) + r * (j+1) / 1.15;
            polygon(width/5+x2,y2-height/9,r,6);
          }
          if(j%n===n-1 && sArray[i][1]===1){
             x2 = r * (j+1) * 1.5;
             y2 = -r * 12 + r * sqrt(3) * (i) + r * (j+1) / 1.15;
             polygon(width/5-x2,y2-height/9,r,6);

          }
           //case3
          polygon(-width/5-x,height/3+y,r,6);
          if(i%n===0 && sArray[i][1]===1){
            y2 = -r * 12 + r * sqrt(3) * (i) + r * (j-2) / 1.15;
            polygon(-width/5-x,height/3+y2,r,6);
            y2 = -r * 12 + r * sqrt(3) * (i) + r * (j-4) / 1.15;
            polygon(-width/5-x,height/3+y2,r,6);
          }
          if(i%n===n-1 && sArray[i][1]===1){
            y2 = -r * 12 + r * sqrt(3) * i + r * (j+2) / 1.15;
            polygon(-width/5-x,height/3+y2,r,6);
            y2 = -r * 12 + r * sqrt(3) * i + r * (j+4) / 1.15;
            polygon(-width/5-x,height/3+y2,r,6);
          }
          if(j%n===0 && sArray[i][1]===1){
            x2 = r * (j+1) * 1.5;
            y2 = -r * 12 + r * sqrt(3) * (i) + r * (j+1) / 1.15;
            polygon(-width/5+x2,height/3+y2,r,6);
            x2 = r * (j+2) * 1.5;
            y2 = -r * 12 + r * sqrt(3) * (i) + r * (j+2) / 1.15;
            polygon(-width/5+x2,height/3+y2,r,6);
          }
          if(j%n===n-1 && sArray[i][1]===1){
             x2 = r * (j+1) * 1.5;
             y2 = -r * 12 + r * sqrt(3) * (i) + r * (j+1) / 1.15;
             polygon(-width/5-x2,height/3+y2,r,6);
            x2 = r * (j+2) * 1.5;
             y2 = -r * 12 + r * sqrt(3) * (i) + r * (j+2) / 1.15;
             polygon(-width/5-x2,height/3+y2,r,6);

          }
        }
      }
    }
}
function shape3(){//circles
   p=min(width,height)/70
   r=min(width,height)/60
   s=floor(random(3,5));
    theta = 360/s
    m=2
    for (let i=0;i<s;i++){
      sArray[i]=[round(random(0,1)),round(random(0,1))];
      fill(255-10*i,150-i*i,155-30*i)
        circle(-width/4+r*cos(theta*i),-height/4+r*sin(theta*i),p);
        circle(width/4+r*cos(theta*i),-height/4+r*sin(theta*i),p);
        circle(-width/4+r*cos(theta*i),height/4+r*sin(theta*i),p);
        if (sArray[i][0]===1){
            //case1
            circle(-width/4+2*r*cos(theta*i),-height/4+2*r*sin(theta*i),p);
            //case2
            circle(width/4+2*r*cos(theta*i),-height/4+2*r*sin(theta*i),p);
            for(let k=3;k<=pow(m,2);k++){
            circle(width/4+k*r*cos(theta*i),-height/4+k*r*sin(theta*i),p);
            }
          //case3
            circle(-width/4+2*r*cos(theta*i),height/4+2*r*sin(theta*i),p);
              for(let k=3;k<=pow(m,2)+pow(m,2);k++){
                circle(-width/4+k*r*cos(theta*i),height/4+k*r*sin(theta*i),p);
            }
      }
    }
}
function shape4(){//triangles
   s=floor(random(3,5));
    theta = 360/s
    g=min(height,width)/30
    h=min(height,width)/60
    m=3
    for (let i=0;i<s;i++){
       sArray[i]=[round(random(0,1)),round(random(0,1))];
      fill(125-10*i,200-i*i,155-30*i)
        polygon(-width/4+g*cos(theta*i),-height/4+g*sin(theta*i),h,3);
        polygon(width/4+g*cos(theta*i),-height/4+g*sin(theta*i),h,3);
        polygon(-width/4+g*cos(theta*i),height/4+g*sin(theta*i),h,3);
        if (sArray[i][0]===1){
            //case1
            polygon(-width/4+2*g*cos(theta*i),-height/4+2*g*sin(i*theta),h,3);
            //case2
            polygon(width/4+2*g*cos(theta*i),-height/4+2*g*sin(i*theta),h,3);
            for(let k=2;k<=m;k++){
            polygon(width/4+k*g*cos(theta*i),-height/4+k*g*sin(i*theta),h,3);
            }
          //case3
            polygon(-width/4+2*g*cos(theta*i),height/4+2*g*sin(i*theta),h,3);
              for(let k=2;k<=m+1;k++){
                polygon(-width/4+k*g*cos(theta*i),height/4+k*g*sin(i*theta),h,3);
            }
      }
    }
}
function shape5(){//square tiles
  n=floor(random(3,6))
  s=min(width,height)/50;
  for (let i=0;i<n;i++){
      for (let j=0;j<n;j++){
        sArray[i]=[round(random(0,1)),round(random(0,1))];
        if (sArray[i][0]===1){
          fill(205-4*i,245,205-10*j*j)
          //case1
          rect(-width/2+i%n*s+width/10,-height/3+j%n*s,s,s);
          //case2
          rect(width/10+i%n*s,-height/3+j%n*s,s,s);
          push()
          translate(width/10+n*s,-height/3)
          rect(i%n*s,j%n*s,s,s);
          pop()
          rect(width/10+i%n*s,-height/3+j%n*s+n*s,s,s);
          rect(width/10+i%n*s+n*s,-height/3+j%n*s+n*s,s,s);
          //case3
          rect(-width/2+width/10+i%n*s,50+j%n*s,s,s);
          rect(-width/2+width/10+i%n*s+n*s,50+j%n*s,s,s);
          rect(-width/2+width/10+i%n*s,50+j%n*s+n*s,s,s);
          rect(-width/2+width/10+i%n*s+n*s,50+j%n*s+n*s,s,s);
          rect(-width/2+width/10+i%n*s+2*n*s,50+j%n*s,s,s);
          rect(-width/2+width/10+i%n*s,50+j%n*s+2*n*s,s,s);
          rect(-width/2+width/10+i%n*s+n*s,50+j%n*s+2*n*s,s,s);
          rect(-width/2+width/10+i%n*s+2*n*s,50+j%n*s+n*s,s,s);
          rect(-width/2+width/10+i%n*s+2*n*s,50+j%n*s+2*n*s,s,s);
          
        }
      }
  }
  
}
function shape6(){//turning 270s
   S=min(width,height)/20
  theta=45
  n=floor(random(4,6))
   for (let i=0;i<n;i++){
      for (let j=0;j<n;j++){
        sArray[i]=[round(random(0,1)),round(random(0,1))];
        //case1
        fill(125+10*i,200-i*j,205-30*j)
        arc(-width/3+i%n*S, -height/3+j%n*S, S, S, 0, 270);
        if (sArray[i][0]===1){
          //case1
          push()
          translate(50+i%n*S, -height/3+j%n*S)
          rotate(90)
          arc(0,0, S, S,0, 270);
          pop()
          push()
          translate(-width/3+i%n*S, 50+j%n*S)
          rotate(180)
          arc(0,0, S, S,0, 270);
          pop()
        }else{
          arc(50+i%n*S, -height/3+j%n*S, S, S,0,270);
          arc(-width/3+i%n*S, 50+j%n*S, S, S,0, 270);
        }
          
      }
   }
}
function shape7(){//turing 270s part 2
  S=min(width,height)/20
  theta=45
  n=floor(random(4,6))
  s=floor(random(1,4))
   for (let i=0;i<n;i++){
      for (let j=0;j<n;j++){
        sArray[i]=[round(random(0,1)),round(random(0,1))];
        //case1
        fill(25+10*i,100-i*j,255-30*j)
        arc(-width/3+i%n*S, -height/3+j%n*S, S, S, 0, 270);
        if (sArray[i][0]===1){
          //case1
          push()
          translate(50+i%n*S, -height/3+j%n*S)
          rotate(45*s)
          arc(0,0, S, S,0, 270);
          pop()
          push()
          translate(-width/3+i%n*S, 50+j%n*S)
          rotate(45*s*2)
          arc(0,0, S, S,0, 270);
          pop()
        }else{ 
          push()
          translate(50+i%n*S, -height/3+j%n*S)
          rotate(-45*s)
          arc(0,0, S, S,0, 270);
          pop()
          push()
          translate(-width/3+i%n*S, 50+j%n*S)
          rotate(-45*s*2)
          arc(0,0, S, S,0, 270);
          pop()
        }
          
      }
   }
}
function shape8(){//snipes
  //square tiles
  n=3;
  s=height/15;
  fill(255);
  for (let i=0;i<n-1;i++){
      for (let j=0;j<n;j++){
        sArray[i]=[round(random(0,2)),round(random(0,2)),round(random(0,2))];
        if (sArray[i][0]===1){
          img = snipe
        }else if(sArray[i][0]===0){
          img=feathers
        }
          //case1
          if(sArray[i][0]===1||sArray[i][0]===0){
            rect(-width/2+i%n*s+width/20,-height/3+j%n*s,s,s);
            image(img,-width/2+i%n*s+width/20,-height/3+j%n*s,s,s);
          }
          //case2
          if(sArray[i][0]===1||sArray[i][0]===0){
            rect(width/12+i%n*s,-height/3+j%n*s,s,s);
            image(img,width/12+i%n*s,-height/3+j%n*s,s,s);
            push()
            scale(-1,1)
            rect(-(width/12-i%n*s+(n+1)*s),-height/3+j%n*s,s,s);
            image(img,-(width/12-i%n*s+(n+1)*s),-height/3+j%n*s,s,s);
            pop()
            
          }          
          //case3
          if(sArray[i][0]===1||sArray[i][0]===0){
            rect(-width/2+width/20+i%n*s,height/20+j%n*s,s,s);
            image(img,-width/2+width/20+i%n*s,height/20+j%n*s,s,s);
            push()
            scale(-1,1)
            rect((width/2-width/20+i%n*s-(n+1)*s),height/20+j%n*s,s,s);
            image(img,(width/2-width/20+i%n*s-(n+1)*s),height/20+j%n*s,s,s);
            pop()
          }   
        push()
        translate(0,-height/20+(n+5.25)*s);
        scale(1,-1)
        if(sArray[i][0]===1||sArray[i][0]===0){
            rect(-width/2+width/20+i%n*s,height/20+j%n*s,s,s);
            image(img,-width/2+width/20+i%n*s,height/20+j%n*s,s,s);
            push()
            scale(-1,1)
            rect((width/2-width/20+i%n*s-(n+1)*s),height/20+j%n*s,s,s);
            image(img,(width/2-width/20+i%n*s-(n+1)*s),height/20+j%n*s,s,s);
            pop()
          }  
        pop()
          
      }
  }
}


              
            
!
999px

Console