Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


    <script src=""></script>
     <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

    <script src="sketch.js"></script>



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


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() {

  //this animates the shapes. you don't need to do anything with this


//this is the brains of the function that animates the shapes. you do not need to change anything here.
function animateShapes() {

  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;