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://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>
    <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/2034654/p5.play.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 Course: Graphics Unit

Animating Sprites using the p5.play.js library

Dog sprite pictures used through open license, sourced from opengameart.com

Dog created by user kirard

Code by Anthony T. Marasco [2018]
*/

let photoDirectory = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/2034654/";
let dog_sprites = [];

let rover;

function preload() {
  for (let i = 0; i <= 9; i++) {
    dog_sprites[i] = loadImage(
      photoDirectory+"dog_" + i + ".png"
    );
  }
}

function setup() {
  createCanvas(windowWidth, windowHeight);

  rover = createSprite(width / 2, height / 2);
  let dog_animation = rover.addAnimation(
    "walking",
    dog_sprites[0],
    dog_sprites[1],
    dog_sprites[2],
    dog_sprites[3],
    dog_sprites[4],
    dog_sprites[5],
    dog_sprites[6],
    dog_sprites[7],
    dog_sprites[8],
    dog_sprites[9]
  );
  
  dog_animation.frameDelay = 4;
  rover.mouseActive = true;
  
}

function draw() {
  background(200);
  if (rover.mouseIsOver) {
    textSize(32);
    fill("aqua");
    stroke(0);
    strokeWeight(2);
    text("woof!!!", rover.position.x - 20, rover.position.y - 55);
    rover.rotation = 25;
  } else {
    rover.rotation = 0;
  }

  
  
  
if (keyIsDown(UP_ARROW)) {
    rover.rotation =90;
  } else if(keyIsDown(DOWN_ARROW)) {
    rover.rotation =270;
  } else if(keyIsDown(LEFT_ARROW)){
    rover.mirrorX(1);
    //rover.rotation =0;
   
  } else if(keyIsDown(RIGHT_ARROW)){
    rover.mirrorX(-1);
  } else if(keyIsDown(32)){
    rover.animation.stop();
  }else if(key == "w"){//we use "key" here since we're using a letter key
        rover.animation.play();   
           }
  
  if (key=="s"){//we use "key" here since we're using a letter key
    rover.animation.goToFrame(4);
  }
  drawSprites();
}



              
            
!
999px

Console