Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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 shps = []; // array of Shapes

function setup() {
  createCanvas(windowWidth, windowHeight); // size of the canvas

  /* double for loop to create a grid of shapes */

  for (let x = 25; x < width; x += 50) {
    for (let y = 25; y < height; y += 50) {
      shps.push(new Shapes(x, y));
    }
  }
}

function draw() {
  background(0);

  /* For loop for the length of the shps array, here we display the shapes */
  for (let i = 0; i < shps.length; i++) {
    shps[i].display();
  }
}

class Shapes {
  constructor(posX, posY) {
    this.xPos = posX;
    this.yPos = posY;

    /* The different sizes the shape can choose from */
    /* 1 or 2 times 25 equals 25 or 50*/
    this.sz = floor(random(1, 3)) * 25;

    /* array of colors to randomly choose from, add or change it yourself */
    this.cl = [
      color("#390099"),
      color("#ff5400"),
      color("#D6FFF5"),
      color("#FFFFFF")
    ];

    /* random functions for color, shape and rotation*/
    this.rndCol = floor(random(this.cl.length));
    this.rndShp = floor(random(4));
    this.rndRot = floor(random(1, 4));
  }

  display() {
    rectMode(CENTER); // the 0 point will be in the center for the rectangle

    /* Fill or stroke? */
    /* this.rndCol gives a random number to pick a color in this.cl array */
    fill(this.cl[this.rndCol]);
    noStroke();

    // stroke(this.cl[this.rndCol]);
    // noFill();

    push();
    translate(this.xPos, this.yPos);
    rotate(radians(90) * this.rndRot);

    /* list of different shapes */
    if (this.rndShp == 0) {
      ellipse(0, 0, this.sz, this.sz);
    } else if (this.rndShp == 1) {
      rect(0, 0, this.sz, this.sz);
    } else if (this.rndShp == 2) {
      let triangleSz = this.sz / 2;
      triangle(
        0,
        0,
        0 + triangleSz,
        0 + triangleSz,
        0 - triangleSz,
        0 + triangleSz
      );
    } else if (this.rndShp == 3) {
      let triangleSz = this.sz / 2;
      triangle(
        0 + triangleSz,
        0 - triangleSz,
        0 + triangleSz,
        0 + triangleSz,
        0 - triangleSz,
        0 + triangleSz
      );
    }

    pop();
  }
}

              
            
!
999px

Console