Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                
              
            
!

CSS

              
                html, body, canvas {
  margin: 0;
  width: 100%;
  height: 100%;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}
              
            
!

JS

              
                // forked from Griffin Moyer; variances and camera rotation by me

// to keep the presentation clean. check out Griffin's work at https://codepen.io/gmoyer
document.addEventListener('DOMContentLoaded', function() {
    document.querySelector('#gm-signature').setAttribute('style','display: none;');
});

// ----------------------------------------------------------------------------

import * as THREE from "https://esm.sh/three";
import TWEEN from "https://cdn.skypack.dev/@tweenjs/tween.js@18.6.4";

// in seconds
const minDelay = 5;
const maxDelay = 10;
const minRotationDelay = 3;
const maxRotationDelay = 6; 

const randomizeSpeed = true;
const randomizeSpacing = true;
const randomizeSize = true;
const gridSize = 1100; // in pixels

const scene = new THREE.Scene();
const hexColor = 0x6699ff;

function getRandomInRange(min, max) {
    return Math.random() * (max - min) + min;
}

function getInitialView() {
    const isTopDown = Math.random() > 0.5; // 50% chance to be a top-down view
    return {
        speed: getRandomInRange(10, 30),
        spacing: getRandomInRange(1.25, 6.25),
        size: getRandomInRange(1.5, 3.5),
        position: {
            x: getRandomInRange(-500, 500),
            y: getRandomInRange(150, 500),
            z: getRandomInRange(250, 500)
        },
        lookAt: {
            x: 0,
            y: 0,
            z: 0
        },
        fov: isTopDown ? getRandomInRange(13, 17) : getRandomInRange(45, 75),
        far: isTopDown ? getRandomInRange(600, 1000) : getRandomInRange(700, 1000),
        rotation: {
            x: getRandomInRange(0, 2 * Math.PI),
            y: getRandomInRange(0, 2 * Math.PI),
            z: getRandomInRange(0, 2 * Math.PI)
        }
    };
}

let currentView = getInitialView();

function getRandomView() {
    const isTopDown = Math.random() > 0.5; // 50% chance to be a top-down view
    return {
        speed: randomizeSpeed ? getRandomInRange(10, 30) : currentView.speed,
        spacing: randomizeSpacing ? getRandomInRange(1.25, 6.25) : currentView.spacing,
        size: randomizeSize ? getRandomInRange(0.5, 1.5) : currentView.size,
        position: {
            x: getRandomInRange(-500, 500),
            y: getRandomInRange(150, 500),
            z: getRandomInRange(-500, 500)
        },
        lookAt: {
            x: 0,
            y: 0,
            z: 0
        },
        fov: isTopDown ? getRandomInRange(13, 17) : getRandomInRange(45, 75),
        far: isTopDown ? getRandomInRange(600, 1000) : getRandomInRange(700, 1000),
        rotation: {
            x: getRandomInRange(0, 2 * Math.PI),
            y: getRandomInRange(0, 2 * Math.PI),
            z: getRandomInRange(0, 2 * Math.PI)
        }
    };
}

let camera = new THREE.PerspectiveCamera(currentView.fov, window.innerWidth / window.innerHeight, 0.1, currentView.far);

function setView(view) {
    camera.position.set(view.position.x, view.position.y, view.position.z);
    camera.lookAt(view.lookAt.x, view.lookAt.y, view.lookAt.z);
    camera.fov = view.fov;
    camera.far = view.far;
    camera.rotation.set(view.rotation.x, view.rotation.y, view.rotation.z);
    camera.updateProjectionMatrix();
}

function transitionView() {
    let nextView = getRandomView();

    new TWEEN.Tween(camera.position)
        .to({
            x: nextView.position.x,
            y: nextView.position.y,
            z: nextView.position.z
        }, 2000)
        .easing(TWEEN.Easing.Quadratic.InOut)
        .start();

    new TWEEN.Tween(camera.rotation)
        .to({
            x: nextView.rotation.x,
            y: nextView.rotation.y,
            z: nextView.rotation.z
        }, 2000)
        .easing(TWEEN.Easing.Quadratic.InOut)
        .onUpdate(() => {
            camera.lookAt(new THREE.Vector3(nextView.lookAt.x, nextView.lookAt.y, nextView.lookAt.z));
        })
        .start();

    new TWEEN.Tween({ fov: camera.fov })
        .to({ fov: nextView.fov }, 2000)
        .easing(TWEEN.Easing.Quadratic.InOut)
        .onUpdate(function (object) {
            camera.fov = object.fov;
            camera.updateProjectionMatrix();
        })
        .start();

    new TWEEN.Tween({ far: camera.far })
        .to({ far: nextView.far }, 2000)
        .easing(TWEEN.Easing.Quadratic.InOut)
        .onUpdate(function (object) {
            camera.far = object.far;
            camera.updateProjectionMatrix();
        })
        .start();

    currentView = nextView;

    setTimeout(transitionView, getRandomInRange(minDelay, maxDelay) * 1000); // Set next transition
}

setView(currentView);
setTimeout(transitionView, getRandomInRange(minRotationDelay, maxRotationDelay) * 1000); // Initial random delay

function update() {
    TWEEN.update();
}

// Existing code
let renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

addNote();

function randint(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function RGB(red, green, blue) {
    function colorcheck(color) {
        if (color > 255) color = 255;
        if (color < 0) color = 0;
        return color;
    }
    red = colorcheck(red);
    green = colorcheck(green);
    blue = colorcheck(blue);

    return 'rgb(' + red + ',' + green + ',' + blue + ')';
}

function rgb2hex(redGreenBlue) {
    redGreenBlue = redGreenBlue.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);

    return (redGreenBlue && redGreenBlue.length === 4) ? "0x" +
        ("0" + parseInt(redGreenBlue[1], 10).toString(16)).slice(-2) +
        ("0" + parseInt(redGreenBlue[2], 10).toString(16)).slice(-2) +
        ("0" + parseInt(redGreenBlue[3], 10).toString(16)).slice(-2) : '';
}

function rgb2color(r, g, b) {
    return rgb2hex(RGB(r, g, b));
}

let color = {};
color.red = 0;
color.green = 0;
color.blue = 255;
color.redStep = 0;
color.greenStep = 0;
color.blueStep = 0;
color.redTarget = 0;
color.greenTarget = 0;
color.blueTarget = 255;

// Create elements here:
const simplex = new SimplexNoise();

function smoothNoise(x, z) {
    // Calculate the contribution of the corners
    let cornerNoise = (
        simplex.noise2D(x - 1, z - 1) +
        simplex.noise2D(x + 1, z - 1) +
        simplex.noise2D(x - 1, z + 1) +
        simplex.noise2D(x + 1, z + 1)
    ) / 16;

    // Calculate the contribution of the sides
    let sideNoise = (
        simplex.noise2D(x - 1, z) +
        simplex.noise2D(x + 1, z) +
        simplex.noise2D(x, z - 1) +
        simplex.noise2D(x, z + 1)
    ) / 8;

    // Calculate the contribution of the center
    let centerNoise = simplex.noise2D(x, z) / 4;

    // Combine the contributions to get the final smooth noise value
    return cornerNoise + sideNoise + centerNoise;
}

function noise(x, z) {
  return smoothNoise(x / 100, z / 100) * 10; // Adjusted scaling factors
}

let size = gridSize,
    grid = new THREE.BufferGeometry(),
    positions = [],
    gMaterial = new THREE.PointsMaterial({
        color: hexColor,
        size: currentView.size
    });

// now create the individual particles
for (let x = 0; x < size; x += currentView.spacing) {
    for (let z = 0; z < size; z += currentView.spacing) {
        positions.push(x, 0, z);
    }
}

// Add positions to the geometry
grid.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));

// create the particle system
let gridSystem = new THREE.Points(grid, gMaterial);

// add it to the scene
scene.add(gridSystem);
gridSystem.position.x = -size / 2;
gridSystem.position.z = -900;

//end of elements
camera.position.y = 175;
camera.position.z = 250;
camera.lookAt(new THREE.Vector3(0, 0, 0));

let render = function () {
    requestAnimationFrame(render);
    mainloop();
    renderer.render(scene, camera);
};

let time = 0;

function mainloop() {
    time += currentView.speed;

    if (Math.abs(color.red - color.redTarget) >= 5) color.red += color.redStep;
    if (Math.abs(color.green - color.greenTarget) >= 5) color.green += color.greenStep;
    if (Math.abs(color.blue - color.blueTarget) >= 5) color.blue += color.blueStep;

    if (Math.abs(color.red - color.redTarget) < 5 &&
        Math.abs(color.green - color.greenTarget) < 5 &&
        Math.abs(color.blue - color.blueTarget) < 5) {
        color.redTarget = randint(0, 255);
        color.greenTarget = randint(0, 255);
        color.blueTarget = randint(0, 255);
        const divisor = 50;

        color.redStep = (color.redTarget > color.red) ? randint(5, 45) / divisor : -randint(5, 45) / divisor;
        color.greenStep = (color.greenTarget > color.green) ? randint(5, 45) / divisor : -randint(5, 45) / divisor;
        color.blueStep = (color.blueTarget > color.blue) ? randint(5, 45) / divisor : -randint(5, 45) / divisor;
    }

    let red = Math.round(color.red);
    let green = Math.round(color.green);
    let blue = Math.round(color.blue);

    const positions = grid.attributes.position.array;
    
    for (let i = 0; i < positions.length; i += 3) {
        positions[i + 1] = noise(positions[i] + (time / 20), positions[i + 2] + (time / 10));
    }
    
    grid.attributes.position.needsUpdate = true;
    gridSystem.material.color.setHex(rgb2color(red, green, blue));

    update(); // Update camera animation
}

render();

window.addEventListener('resize', onWindowResize, false);

function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();

    renderer.setSize(window.innerWidth, window.innerHeight);
}

              
            
!
999px

Console