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

              
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
<div id="bg"></div>
<input type="text" id="text-input" autofocus placeholder="Type_">
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Rubik+Mono+One&display=swap');
body {
	padding: 0;
	margin: 0;
	overflow: hidden;
}
#bg {
	background-image: url("https://res.cloudinary.com/losrodriguez/image/upload/v1591942826/bg_nr9p2v.gif");
	-webkit-background-size: cover;
	background-size: cover;
	background-attachment: fixed;
	background-position: center;
	z-index: 1;
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	mix-blend-mode: overlay;
}
input {
	position: absolute;
	left: 50%;
	bottom: 10px;
	width: 300px;
	transform: translate(-50%, 0%);
	border: 2px solid white;
	background-color: transparent;
	padding: 15px;
	font-size: 30px;
	color: white;
	z-index: 3;
	text-align: center;
	font-family: "Rubik Mono One";
}
              
            
!

JS

              
                var camera, scene, renderer, mesh;
var mouseX = 0, mouseY = 0;

var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;

var colors = ["#D98E04","#F2E205","#7F25D9","#5C12A6","#2F0459"];

function init() {
    camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.z = -100;
    camera.position.y = -100;
    // 
    var imgs = textToTexture("Hola");
    var texture = new THREE.CubeTextureLoader().load(imgs);
    texture.mapping = THREE.CubeRefractionMapping;

    scene = new THREE.Scene();
    //scene.background = texture;

    var ambient = new THREE.AmbientLight(0xffffff);
    scene.add(ambient);

    var geometry = new THREE.IcosahedronGeometry(50, 1);
    var material = new THREE.MeshPhongMaterial({
        envMap: texture,
        refractionRatio: 0.85
    });
	
    mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);

    renderer = new THREE.WebGLRenderer({
        antialias: true,
        alpha: true
    });
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    document.addEventListener('mousemove', onDocumentMouseMove, false);
    document.addEventListener('touchmove', onDocumentMouseMove, false);
    window["text-input"].addEventListener('keyup', onTextChange, false);
    window.addEventListener('resize', onWindowResize, false);
}

function onTextChange() {
    var str = window["text-input"].value || "Hola Mundo";
    var imgs = textToTexture(str);
    var texture = new THREE.CubeTextureLoader().load(imgs);
    texture.mapping = THREE.CubeRefractionMapping;
    mesh.material.envMap = texture;
}

function onWindowResize() {
    windowHalfX = window.innerWidth / 2;
    windowHalfY = window.innerHeight / 2;
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight);
}

function onDocumentMouseMove(event) {
    if (event.touches) event = event.touches[0];
    mouseX = (event.clientX - windowHalfX) / 4;
    mouseY = (event.clientY - windowHalfY) / 4;
}

function animate() {
    requestAnimationFrame(animate);
    render();
}

function render() {
    camera.position.x += (mouseX - camera.position.x) * 0.05;
    camera.position.y += (-mouseY - camera.position.y) * 0.05;
    camera.lookAt(mesh.position);
    renderer.render(scene, camera);
}

function textToTexture(text) {
    if (text === undefined) text = "Hello World";
    var canvas = document.createElement('canvas');
    var tile_size = 1024;
    var fontSize = 50;
    // 
    canvas.width = tile_size * 4;
    canvas.height = tile_size;
    // 
    var ctx = canvas.getContext('2d');
    ctx.font = fontSize + "px Rubik Mono One, Helvetica";
    var fillColor = colors[Math.floor(Math.random()*colors.length)];
    document.body.style.backgroundColor = fillColor;
    ctx.fillStyle = fillColor;
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    var text_width = ctx.measureText(text).width;
    var text_height = fontSize * 0.8;
    var repetitions_x = Math.ceil(canvas.width / text_width);
    var repetitions_y = Math.ceil(canvas.height / text_height);
    var index = 0;
    for (var y = 0; y < canvas.height; y += text_height) {
        for (var x = 0; x < canvas.width; x += text_width) {
            ctx.fillStyle = colors[Math.floor(Math.random()*colors.length)];
            var _x = index % 2 == 0 ? x : x - (text_width/2);
            ctx.fillText(text, _x, y);
        }
        index += 1;
    }
    var tileFromCanvas = function(index) {
        var img_canvas = document.createElement('canvas');
        img_canvas.width = tile_size;
        img_canvas.height = tile_size;
        var context = img_canvas.getContext("2d");
        context.drawImage(canvas, -tile_size * index, 0);
        return img_canvas.toDataURL();
    }
    var imgs = [];
    imgs.push(tileFromCanvas(0));
    imgs.push(tileFromCanvas(1));
    imgs.push(tileFromCanvas(4)); // blank_space
    imgs.push(tileFromCanvas(4)); // blank_space
    imgs.push(tileFromCanvas(2));
    imgs.push(tileFromCanvas(3));
    return imgs;
}

init();
animate();
              
            
!
999px

Console