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

              
                // PDM GRaphics with p5play
// Calling Sprite methods
// code by Matthew A. Bardin [2022]

let mySprites = [];
let colors = [
  [255, 0, 0], // red
  [0, 255, 0], // green
  [0, 0, 255], // blue
  [255, 0, 255], // magenta
  [0, 255, 255] // light blue
];

function setup() {
  createCanvas(400, 400);
  // makes 5 sprites and assigns them a color
  for (let i = 0; i < 5; i++) {
    mySprites[i] = new Sprite(random(50, 350), random(50, 350), 25); // these sprites are circular
    mySprites[i].color = color(colors[i]);
  }
}

function draw() {
  background(220);
  console.log(keyCode);
}
// responds to the keyboard inputs
function keyPressed() {
  switch (keyCode) {
    case 49:
      mySprites[0].removeColliders; // removes all collision ditection from the red sprite
      break;
    case 50:
      mySprites[1].moveAway(mouseX, mouseY); // moves the green sprite away from the mouse
      break;
    case 51:
      mySprites[2].remove(); // removes the blue sprite
      break;
    case 52:
      mySprites[3].moveTowards(mySprites[4], 0.6); // makes the magenta sprite move towards the light blue sprite
      break;
    case 53:
      mySprites[4].move("down", 1, 50); // makes the light blue sprite move downwards for 50 px.
      break;
    case 13: // return key
      allSprites.remove(); //removes all sprites
      setup(); //reruns setup()
      keyCode = " "; //avoids duplicate calls of setup
      break;
  }
}

              
            
!
999px

Console