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.


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.




                body {
  text-align: center;

.slider {
  -webkit-appearance: none;
  width: 150px;
  height: 10px;
  border-radius: 5px;  
  background: #d3d3d3;
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%; 
  background: #000000;
  cursor: pointer;

.slider::-moz-range-thumb {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #4CAF50;
  cursor: pointer;

#rSlide {
  background: #ff0000;

#gSlide {
  background: #00ff00;

#bSlide {
  background: #0000ff;


                // Pythagoras's Theorem in 3D:
function distance(x1, y1, z1, x2, y2, z2) {
  let dx = x2 - x1;
  let dy = y2 - y1;
  let dz = z2 - z1;
  let sum_of_squares = dx*dx + dy*dy + dz*dz;
  return sqrt(sum_of_squares);

// We know two spheres collide if the sum of their radii
// is greater than or equal to the distance between them
function collides(x1, y1, z1, r1, x2, y2, z2, r2) {
  let d = distance(x1, y1, z1, x2, y2, z2);
  if (d <= r1 + r2) {
    return true;
  } else {
    return false;

// Set up the drawing area with sliders
let depth = 400;
function setup() {
  createCanvas(1400, 960, WEBGL);
  xSlider = createSlider(-width/4, width/4, -100);
  xSlider.position(100, 20);'rSlide');
  ySlider = createSlider(-height/4, height/4, 100);
  ySlider.position(100, 50);'gSlide');
  zSlider = createSlider(-depth/4, depth/4, 0);
  zSlider.position(100, 80);'bSlide');

let t = 0;
function draw() {
  //constantly rotate so we can see the 3D space
  t += 0.005;
  rotateZ(t * 0.5);
  background(250, 100, 0);
  let r1 = 40, r2 = 25;
  let curX = xSlider.value();
  let curY = ySlider.value();
  let curZ = zSlider.value();
  //draw axes
  stroke(255, 0, 0);
  line(-width, 0, 0, width, 0, 0);
  stroke(0, 255, 0);
  line(0, -height, 0, 0, height, 0);
  stroke(0, 0, 255);
  line(0, 0, -depth, 0, 0, depth);
  //draw line connecting center of the spheres
  line(0, 0, 0, curX, curY, curZ);
  // Change center sphere to red if it's touching the other
  if (collides(0, 0, 0, r1, curX, curY, curZ, r2)) {
    fill(250, 0, 0);
  } else {
    fill(250, 250, 0);
  // Draw the first sphere at the origin
  // Draw second sphere according to slider values
  translate(curX, curY, curZ);
  fill(0, 250, 0);