Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                #canvas-wrapper(aria-label='curve')
              
            
!

CSS

              
                html,
body {
	height: 100%;
}

body {
	background-color: #010101; // black
	margin: 0;
	padding: 0;
	overflow: hidden;
}
              
            
!

JS

              
                /* 
 * CURVE TYPO
 * Made with ThreeJS - Enjoy!
 * https://threejs.org/
 *
 * Experimenting with texture typography for a screen effect.
 * Move the cursor to zoom in/out.
 * On mobile touch + drag screen to zoom in/out.
 *
 * Inspired by the Tron film.
 *
 * #codevember 20 - CURVE
 * #026 - #100DaysOfCode
 * By ilithya | 2019
 */

const colorBg = '#010101'; // Black
const colorText = '#01ecd5'; // Blue

const nearDist = 0.1;
const farDist = 5000;

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
	75,
	window.innerWidth / window.innerHeight,
	nearDist,
	farDist
);
camera.position.z = farDist;

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor(colorBg);
renderer.setPixelRatio(window.devicePixelRatio); // For HiDPI devices to prevent bluring output canvas
renderer.setSize(window.innerWidth, window.innerHeight);
document.querySelector("#canvas-wrapper").appendChild(renderer.domElement);

// CREATE TYPOGRAPHY
const group = new THREE.Group(); // To add 3d float effect
const typoLoader = new THREE.FontLoader();
const generateTypoTexture = () => {
	const canvas = document.createElement('canvas');
	const ctx = canvas.getContext('2d');
	
	canvas.width = 12;
	canvas.height = 12;
	ctx.fillStyle = 'white';
	ctx.fillRect(1, 10, 10, 1);
	
	return canvas;
};
const createTypo = font => {
	const word = "curve";
	const typoSize = Math.floor(window.innerWidth/10);
	const typoProperties = {
		font: font,
		size: typoSize,
		height: typoSize / 2,
		curveSegments: 20,
		bevelEnabled: false,
	};
	const textMesh = new THREE.Mesh();

	textMesh.geometry = new THREE.TextBufferGeometry(word, typoProperties);

	// Let's add texture for screen effect
	const texture = new THREE.CanvasTexture(generateTypoTexture());
	texture.wrapT = THREE.RepeatWrapping;
	texture.wrapS = THREE.RepeatWrapping;
	textMesh.material = new THREE.MeshBasicMaterial({ 
		alphaMap: texture,
		alphaTest: 0.6,
		color: colorText,
		side: THREE.DoubleSide,
	});
	
	// Let's center typo in scene
    textMesh.geometry.computeBoundingBox();
	textMesh.geometry
		.boundingBox
		.getCenter(textMesh.position)
		.multiplyScalar(-1);
	
	// Manually control when 3D transformations recalculation occurs for better performance
	textMesh.matrixAutoUpdate = false;
	textMesh.updateMatrix();

	group.add(textMesh);
};
typoLoader.load(
	"https://threejs.org/examples/fonts/helvetiker_bold.typeface.json",
	createTypo
);
scene.add(group);

// CREATE PART OF THE MOUSE/TOUCH OVER EFFECT
const w = window.innerWidth;
const h = window.innerHeight;
const lim = 280;
let mouseX = w>h && h<=lim ? Math.sqrt(w*h)/4 : w/4;
const mouseFX = {
	windowHalfX: window.innerWidth/2,
	coordinates: function(coordX) {
		mouseX = Math.abs(coordX - mouseFX.windowHalfX);
		mouseX = mouseX >= lim ? lim : mouseX;
	},
	onMouseMove: function(e) {
		mouseFX.coordinates(e.clientX);
	},
	onTouchMove: function(e) {
		const touchX = e.changedTouches[0].clientX;
		mouseFX.coordinates(touchX);
	}
};
document.addEventListener("mousemove", mouseFX.onMouseMove, false);
document.addEventListener("touchmove", mouseFX.onTouchMove, false);

// RENDER 3D GRAPHIC
const render = () => {
	requestAnimationFrame(render);

	// Camera animation
	// Works with onMouseMove and onTouchMove functions
	const ct = 0.05;
	const pZ = (mouseX - camera.position.z) * ct;
	camera.position.z += pZ;		

	// Floating animation
	const radians = Date.now() * 0.0005;
	const rot = Math.sin(radians) * 0.1;
	group.rotation.x = rot;
	group.rotation.y = rot;

	renderer.render(scene, camera);
};
render();
              
            
!
999px

Console