cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              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
            
          
!
            
              if (!Detector.webgl)
    Detector.addGetWebGLMessage()

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

Console