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

              
                
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js"></script>
     <script src="https://cdn.jsdelivr.net/gh/molleindustria/p5.play/lib/p5.play.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/tone/13.8.12/Tone.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

              
                /*
Programming Digitla Media: interactions with shapes

Review assignment

Code by Matthew A Bardin [2020]

Instructions: For this assignment, there are 4 different 
animated shapes moving across the screen. 
Create the necessary nested conditional statement(s) 
in order to change the background to a different color when each 
shape is pressed. Each shape should cause a different color to appear. 
The background should return to the starting color when the mouse is 
released.You do not need to delete/change any of the starting code, 
but you will have to add to it.
*/

let yellowSqX = 100;
let yellowSqY = -50;
let blueSqX = 300;
let blueSqY = -250;
let pinkCirX = -200;
let pinkCirY = 200;
let purpleCirX = 600;
let purpleCirY = 300;
let pinkCirDiam  = 50;
let purpleCirDiam = 100;
let bg = "gray";




function setup() {
  createCanvas(400, 400);

}

function draw() {
  background(bg);
  noStroke();

  //this animates the shapes. you don't need to do anything with this
  animateShapes();
  

}

//this is the brains of the function that animates the shapes. you do not need to change anything here.
function animateShapes() {
  yellowSqY++;
  blueSqY++;
  pinkCirX++;
  purpleCirX--;

  fill(100, 100, 0, 100);
  rect(yellowSqX, yellowSqY, 50, 50);
  fill(0, 200, 200, 150);
  rect(blueSqX, blueSqY, 50, 50);
  fill(255, 0, 255, 100);
  ellipse(pinkCirX, pinkCirY, pinkCirDiam);
  fill(41, 25, 173, 100);
  ellipse(purpleCirX, purpleCirY, purpleCirDiam);

  if (yellowSqY > 450) {
    yellowSqY = -50;
  }
  if (blueSqY > 450) {
    blueSqY = -50;
  }
  if (pinkCirX > 425) {
    pinkCirX = -25;
  }
  if (purpleCirX < -100) {
    purpleCirX = 450;
  }

}
              
            
!
999px

Console