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    
    position absolute
    top 0
    left 0

html
    background #1B2B34
    background radial-gradient(ellipse at center, #001B36 0%, #000 100%)
    
body
    background url('https://gallery.yopriceville.com/var/resizes/Free-Clipart-Pictures/Butterflies-PNG/Butterfly_Blue_PNG_Clip_Art_Image.png?m=1454516304') 50%
    background-size 30%
    background-repeat no-repeat
    
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

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 = 500
    
    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', '#aaa', 50)
    light.position.set(0, 700, 700)
    light.castShadow = true
    scene.add(light)

    light = new THREE.PointLight(0x222222, 1, 0)
    light.position.set(1000, 500, 1000)
    light.castShadow = true
    // scene.add(light)    
    
    camera.lookAt(scene.position)
    
    let root = new THREE.Object3D()
    
    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)
    
    let waterMaterial = new THREE.MeshPhongMaterial({
        color: '#0C7CA5'
        , transparent: true
        , blending: THREE.SubtractiveBlending
    });

    let sphere = new THREE.SphereGeometry(250, 100, 100);
    let mask = new THREE.Mesh(sphere, waterMaterial);
    root.add(mask); 
    
    let test = new THREE.SphereBufferGeometry(300, 50, 50);
    test = new THREE.Mesh(test, new THREE.MeshPhongMaterial({
        color: 0xffffff,
        wireframe: true,
        opacity: .2,
        blending: THREE.AdditiveBlending
    }));
    root.add(test);
    
    test = new THREE.SphereBufferGeometry(150, 50, 50);
    test = new THREE.Mesh(test, new THREE.MeshPhongMaterial({
        color: 0xff00ff,
        opacity: 1,
        blending: THREE.AdditiveBlending
    }));
    test.position.x += 160;
    root.add(test);
    
    let lineGroup = new THREE.Object3D();
    let geo = new THREE.SphereBufferGeometry(1);
    geo = new THREE.Mesh(geo, new THREE.MeshBasicMaterial({
        color: 0xffffff,
        transparent: true,
        opacity: 1,
        blending: THREE.AdditiveBlending
    }));
    lineGroup.add(geo);

    var line = new THREE.Geometry();
    var pos = new THREE.Vector3();
    line.vertices.push(pos);
    pos = pos.clone().setZ(50);
    line.vertices.push(pos);

    line = new THREE.LineSegments(line, new THREE.LineBasicMaterial({
        color: 0xffffff,
        transparent: true,
        opacity: 1,
        blending:THREE.AdditiveBlending
    }));
    lineGroup.add(line);

    var texture = makeLabelTexture("label.name", 96, 24);

    geo = new THREE.PlaneGeometry(48, 12);
    geo = new THREE.Mesh(geo, new THREE.MeshBasicMaterial({
        color: "#fff",
        opacity: 1,
        map: texture,
        side: THREE.DoubleSide,
        blending: THREE.AdditiveBlending,
        transparent: true
        // depthTest: false
    }));
    geo.position.set(24, 3, 50);
    geo.rotation.z = -.05;
    lineGroup.add(geo);

    pos = new THREE.Vector3(10, 5, 50);
    pos.normalize().multiplyScalar(300);

    lineGroup.position.set(pos.x, pos.y, pos.z);
    pos.normalize().multiplyScalar(300 * 2);
    lineGroup.lookAt(pos);
    root.add(lineGroup);
    scene.add(root);
}

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

function update() {
    
}

function makeLabelTexture(label, width, height) {
    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext('2d');

    canvas.width = width * 2;
    canvas.height = height < 32 ? 32 : height;

    ctx.textAlign = "left";
    ctx.textBaseline = "top";

    // ctx.translate(canvas.width / 2, canvas.height / 2);
    // ctx.scale(-1, 1);
    ctx.translate(5, 0);
    // ctx.rotate(5 * Math.PI/180);

    ctx.fillStyle = '#fff';
    ctx.font = '24px fantasy';
    ctx.fillText(label, 0, 0);

    var sizes = ctx.measureText(label);
    ctx.fillStyle = '#fff';
    ctx.fillRect(-5, 26, sizes.width + 5, 2);

    var tex = new THREE.Texture(canvas);
    tex.needsUpdate = true;
    return tex;
}
            
          
!
999px
Loading ..................

Console