Pen Settings



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


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 href="" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="style.css">
    <div id = "controlPanel"> </div>
    <script src="sketch.js"></script>


                html, body {
  margin: 0;
  padding: 0;
  background: black;
canvas {
  display: block;
  margin: auto;


                // TODO: Set up how many balls we want
let ballCount = 500;
// TODO: Set up x and y position variable to equal an empty array
let x = [];
let y = [];
// TODO: Set up speed, size and color variable to equal an empty array
let xSpeed = [];
let ySpeed = [];

let size = [];

let r = [];
let g = [];
let b = [];

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

  // TODO: Create a for loop that iterates through i until it reaches the ball count value
  for(let i=0; i<ballCount; i++) {
    // Inside the for loop:
    // TODO: Set x and y position to be the center
    x[i] = width/2;
    y[i] = height/2;
    // TODO: Set the speeds to be random
    xSpeed[i] = random(-5,5);
    ySpeed[i] = random(-5,5);
    // TODO: Set the size to be random
    size[i] = random(10,50);
    // TODO: Set the colors to be random
    r[i] = random(150,256);
    g[i] = random(150,256);
    b[i] = random(150,256);

function draw() {
  background(0, 50);
  // TODO: Iterate through a new for loop to change the properties in order to animate the balls
  for(let i=0; i<ballCount; i++) {
    // Inside the for loop:
    // TODO: Increment speed for x position
    x[i] += xSpeed[i];
    // TODO: Increment speed for y position
    y[i] += ySpeed[i];
    // TODO: Reverse x direction if ball hits left or right sides
    if(x[i] < 0 || x[i] > width) {
      xSpeed[i] *= -1;

    // TODO: Reverse y direction if ball hits top or bottom sides
    if(y[i] < 0 || y[i] > height) {
      ySpeed[i] *= -1;

    // TODO: Set random R, G, B values
    fill(r[i], g[i], b[i]);

    // TODO: Style to have no strokes

    // TODO: Draw the bouncing balls
    ellipse(x[i], y[i], size[i], size[i]);