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>


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


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

function draw() {
  //draw blue background
  background(0, 0, 255);
  //draw circle at fixed location
  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);
  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);