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
    padding 0
    width 100vw
    height 100vh
    overflow hidden
    background #1B2B34
    background radial-gradient(ellipse at center, #001B36 0%, #000 100%)
    position absolute
    top 0
    left 0

div
    z-index 100
    
div:last-child
    top 48px !important
        
canvas
    z-index 10
              
            
!

JS

              
                import Stats from "https://cdn.skypack.dev/[email protected]";
let renderer
    , controls
    , scene
    , camera
    , w, h
    , statsFps
    , statsMs

const material = new THREE.MeshPhongMaterial( { color: '#ff3300', side: 2} );
let t = 0;
let lt = Date.now();
let tl = 0;

resize()
init()
animate()

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

function resize() {
    w = document.body.clientWidth
    h = document.body.clientHeight
    if (!camera) {
        return
    }
    
    camera.aspect = w / h
    camera.updateProjectionMatrix()
    renderer.setSize(w, h)
}

function init() {
    
    scene = new THREE.Scene()

    camera = new THREE.PerspectiveCamera(75, w / h, 1, 6000)
    camera.position.z = 50
    
    renderer = new THREE.WebGLRenderer({alpha: true})
    renderer.setSize(w, h)
    renderer.setClearColor("#0C7CA5", 0)
    renderer.setPixelRatio(window.devicePixelRatio)
    renderer.sortObjects = false
    renderer.autoClear = false
    renderer.generateMipmaps = false
    
    let light = new THREE.HemisphereLight('#fff', '#eee', 2)
    light.position.set(0, 0, 300)
    light.castShadow = true
    scene.add(light)

    light = new THREE.PointLight(0x222222, 3)
    light.position.x = 1000
    light.position.y = 500
    light.position.z = 1000
    light.castShadow = true
    scene.add(light)    
    
    camera.lookAt(scene.position)
    
    controls = new THREE.OrbitControls(camera, renderer.domElement);
    
    document.body.appendChild(renderer.domElement)
        
    statsFps = new Stats()
    document.body.appendChild(statsFps.dom)
    
    statsMs = new Stats()
    statsMs.showPanel(1)
    document.body.appendChild(statsMs.dom)
    
    window.addEventListener('resize', resize, false)
    create(scene)
}

function create(scene) {
    const geometry = new THREE.CylinderBufferGeometry( 7, 7, 40, 140, 120, true );
    //const geometry = new THREE.PlaneBufferGeometry(2 * 7 * Math.PI, 10, 140, 70);
    material.map =
    material.displacementMap =
    // material.normalMap =
            new THREE.Texture(generateBump(2 * 7 * Math.PI, 40, 0));

    material.map.needsUpdate = true;

    material.normalScale = new THREE.Vector2( 1, - 1 );

    material.displacementScale = 6;
    material.displacementBias = - 0.428408;

    const cylinder = new THREE.Mesh( geometry, material );

    scene.add(cylinder);
}

function animate() {
    
    requestAnimationFrame(animate)
    
    update()
    
    renderer.clear()
    renderer.render(scene, camera)
    
    controls.update()
    statsFps.update()
    statsMs.update()
    
}

function update() {
    
    t = Date.now() - lt;
    
    if (t < 100) 
        return
        
    lt = Date.now();
    
    material.map =
    material.displacementMap =
    // material.normalMap =
            new THREE.Texture(generateBump(2 * 7 * Math.PI, 40, lt));

    material.map.needsUpdate = true;
}

var ttl = 0;
function generateBump(w, h, time) {

    var temp = document.createElement('canvas');
    temp.width = (w*10) | 0;
    temp.height = (h*10) | 0;
    var wm = w | 0;
    var hm = h | 0;
    var ws = wm;
    var hs = hm;
    
    
    var ctx = temp.getContext('2d');    
    
    ctx.fillStyle = "rgba(0, 0, 0, 1)";
    ctx.fillRect(0, 0, temp.width, temp.height);
    
    while(ws--) {
        hs = hm
        while(hs--) {
            var tt = (ws % 4) - 1;
            if (!tt) {
                tl+=.5
            }
            ctx.fillStyle = tt ? 'hsla(0, 0%, 0%, 1)' : 'hsla(0, 0%, '+ Math.sin(tl) * 100 +'%, 1)';
            ctx.translate(ws *  10, hs * 10);
            ctx.fillRect(0, 0, 10, 10);
            ctx.translate(-ws * 10, -hs * 10);
        }
    }
    
    // let img = new Image();
    // img.src = temp.toDataURL();

    return temp;
}

              
            
!
999px

Console