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. 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


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


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.






                // Cube to sphere program. Inspired by Golan Levin’s circle morphing:
//, brought to us by
// Dan Shiffman’s The Coding Train.

const options = {
    cubeEdgeLength:         30,
    betweenCubeSpace:       75,
    morphPeriodSecs:        10,
    yRotationPeriodSecs:    11

let numCubes;
let startCoord;
let halfSpace;

function setup() {
    createCanvas(windowWidth, windowHeight, WEBGL);
    const maxLargeCubeEdge = min(800, width, height);
    numCubes = Math.floor(maxLargeCubeEdge / (options.cubeEdgeLength + options.betweenCubeSpace));
    const spaceNeeded = numCubes * options.cubeEdgeLength + (numCubes - 1) * options.betweenCubeSpace;
    halfSpace = spaceNeeded / 2;
    startCoord = -halfSpace + options.cubeEdgeLength / 2;

function draw() {

    function colorPart(offset) {
        return map(offset, -halfSpace, halfSpace, 0, 255)

    function forRange(fn) {
        for (let i = 0; i < numCubes; ++i) {
            fn(startCoord + i * (options.cubeEdgeLength + options.betweenCubeSpace));

    translate(0, 0, -700);
    rotateX(PI / 4);
    rotateY(millis() / 1000 / options.yRotationPeriodSecs * TWO_PI);
    const cornerVector = createVector(halfSpace, halfSpace, halfSpace);
    const cosSquashAt = 0.7;
    const radians = millis() / 1000 / options.morphPeriodSecs * TWO_PI;
    const cosOverTime = constrain(cos(radians), -cosSquashAt, cosSquashAt);
    const changingMaxRadius = createVector(
        map(cosOverTime, -cosSquashAt, cosSquashAt, halfSpace, cornerVector.mag()), 0, 0);

    forRange(x => forRange(y => forRange(z => {
        let pos = createVector(x, y, z);
        const shrinkNeeded = changingMaxRadius.mag() / pos.mag();
        if (shrinkNeeded < 1) {
            pos = pos.mult(shrinkNeeded);
        translate(pos.x, pos.y, pos.z);
        fill(colorPart(x), colorPart(y), colorPart(z));