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

              
                
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

  </head>
  <body>
    <script src="sketch.js"></script>
  </body>
</html>

              
            
!

CSS

              
                html, body {
  margin: 0;
  padding: 0;
}
              
            
!

JS

              
                /* PDM: Intro to Coding Unit

Math for Coding - Simple Operations against a changing variable

Code by Anthony T. Marasco [2018]
*/

//Variables for our rectangle X and Y base values, initialized as a fixed value

let rectX = 10;
let rectY = 10;

function setup() {
  createCanvas(600, 600);
}

function draw() {
  background(223);
  /*with each loop of the draw() block, we reassign the value inside of rectX to be the
mouse's current X position*/

  rectX = mouseX;
  rectY = mouseY;

  //building a row by addition
  fill("lightBlue");
  rect(rectX + 40, rectY, 30, 30);
  rect(rectX + 90, rectY, 30, 30);
  rect(rectX + 140, rectY, 30, 30);

  //building a row by multiplication
  fill("pink");
  rect(rectX * 5, rectY * 5, 30, 30);
  rect(rectX * 10, rectY * 5, 30, 30);
  rect(rectX * 15, rectY * 5, 30, 30);

  //building a row through subtraction
  fill("orange");
  rect(rectX + 140 - 0, rectY * 9, 30, 30);
  rect(rectX + 140 - 50, rectY * 9, 30, 30);
  rect(rectX + 140 - 100, rectY * 9, 30, 30);

  //building a row through combination operators
  fill("green");
  rect((rectX * 15) / 3, rectY * 13, 30, 30); //left-most square
  rect((rectX * 15) / 3 + 50, rectY * 13, 30, 30); //middle square
  rect(rectX * 15, rectY * 13, 30, 30); //right-most square
}

              
            
!
999px

Console