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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <html>
  <head>
    <script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/p5.js"></script>
  </head>
  <body>
  </body>
</html>
              
            
!

CSS

              
                body {
  cursor: none;
  background-color: #000000;
}
              
            
!

JS

              
                const SCREEN_WIDTH = 800;
const SCREEN_HEIGHT = 600;

/* Define 2 objects to represent circles,
they need an x and y position and a radius */
c1 = {x:500, y:150, radius: 50}
c2 = {x:0, y:0, radius: 25}

/* Take two coordinate pairs and return the
distance between them using the distance
formula/Pythagorean Theorem */
function distance(x1, y1, x2, y2) {
  var dx = x2 - x1;
  var dy = y2 - y1;
  return (Math.sqrt(dx * dx + dy * dy));
}

/* Determine whether or not 2 given circular objects
are colliding. Find the distance between them and
compare the sum of their radii. If the distance is
greater, they are not colliding, otherwise they are */
function collides(circle1, circle2) {
  var d = distance(circle1.x, circle1.y, circle2.x, circle2.y)
  if (d <= circle1.radius + circle2.radius) {
    return true;
  } else {
    return false;
  }
  /* A more succinct way to write this is
  return (d <= circle1.radius + circle2.radius); */
}

function setup() {
  createCanvas(SCREEN_WIDTH, SCREEN_HEIGHT);
}

function draw() {
  
  //draw blue background
  background(0, 0, 255);
  
  //draw circle at fixed location
  noStroke();
  fill(255, 255, 0);
  ellipse(c1.x, c1.y, c1.radius * 2);

  //draw cirlce at cursor
  c2.x = mouseX;
  c2.y = mouseY;
  if (collides(c1, c2)) {
    fill(255, 0, 0); //set to red if colliding
  } else {
    fill(0, 255, 0); //set to green if not colliding
  }
  ellipse(c2.x, c2.y, c2.radius * 2);

  //display "debug" information on screen
  stroke(0, 0, 0);
  line(c1.x, c1.y, c2.x, c2.y);
  textSize(20);
  text("distance: ", 10, 20);
  text(distance(c1.x, c1.y, c2.x, c2.y), 100, 20);
  text("r1 + r2: ", 10, 45);
  text(c1.radius + c2.radius, 100, 45);
}
              
            
!
999px

Console