HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- Particle animation ideas using Curl noise are from this great turotial video by Yuri Artiukh
* FBO Particles with Three.js #10
https://www.youtube.com/watch?v=oLH00MXTqNg -->
<script id="vs" type="x-shader/x-vertex">
uniform float time;
uniform float progress;
varying vec2 vUv;
varying vec3 vPosition;
uniform sampler2D texture;
float PI = 3.141592653589793238462643383279;
//
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
//
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+1.0)*x);
}
float noise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
vec3 curl(float x, float y, float z)
{
float eps = 1., eps2 = 2. * eps;
float n1, n2, a, b;
x += time * .05;
y += time * .05;
z += time * .05;
vec3 curl = vec3(0.);
n1 = noise(vec2( x, y + eps ));
n2 = noise(vec2( x, y - eps ));
a = (n1 - n2)/eps2;
n1 = noise(vec2( x, z + eps));
n2 = noise(vec2( x, z - eps));
b = (n1 - n2)/eps2;
curl.x = a - b;
n1 = noise(vec2( y, z + eps));
n2 = noise(vec2( y, z - eps));
a = (n1 - n2)/eps2;
n1 = noise(vec2( x + eps, z));
n2 = noise(vec2( x + eps, z));
b = (n1 - n2)/eps2;
curl.y = a - b;
n1 = noise(vec2( x + eps, y));
n2 = noise(vec2( x - eps, y));
a = (n1 - n2)/eps2;
n1 = noise(vec2( y + eps, z));
n2 = noise(vec2( y - eps, z));
b = (n1 - n2)/eps2;
curl.z = a - b;
return curl;
}
void main() {
vUv = uv;
// vec4 mvPosition = modelViewMatrix * vec4(position, 1.);
vec3 t = position
+ curl(
2. * position.x,
2. * position.y,
2. * position.z
) * 10. * progress;
float d = length(position - t) / 2.;
vec3 np = mix(position, t, pow(d, 5.));
vec4 mvPosition = modelViewMatrix * vec4(np, 1.);
gl_PointSize = 7.;
gl_Position = projectionMatrix * mvPosition;
}
</script>
<script id="fs" type="x-shader/x-fragment">
uniform float time;
uniform vec4 resolution;
varying vec2 vUv;
varying vec3 vPosition;
float PI = 3.141592653589793238462643383279;
void main() {
float alpha = 1. - smoothstep(-0.2, 0.5, length(gl_PointCoord - vec2(0.5)));
alpha *= 0.5;
gl_FragColor = vec4( vUv, 1.0, 1.0 * alpha );
}
</script>
/* CSS files add styling rules to your content */
body {
margin: 0;
padding: 0;
background-color: #000000;
height: 100vh;
overflow: hidden;
}
h1 {
font-style: italic;
color: #373fff;
}
// LPS Head
// https://casual-effects.com/data/
// Triangles: 9923
// Vertices: 17684
// Updated: 2012-02-23
// License: CC BY 3.0
// © I-R Entertainment Ltd.
import { GLTFLoader } from 'https://unpkg.com/three@0.120.0/examples/jsm/loaders/GLTFLoader.js';
import { OrbitControls } from "https://unpkg.com/three@0.120.0/examples/jsm/controls/OrbitControls";
import {Pane} from "https://cdn.skypack.dev/tweakpane@3.0.5";
import * as EssentialsPlugin from "https://cdn.skypack.dev/@tweakpane/plugin-essentials@0.1.2"
class App {
constructor() {
this.scene = new THREE.Scene()
this.renderer = new THREE.WebGLRenderer()
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
this.renderer.setSize(this.width, this.height)
this.renderer.setClearColor (0xffffff, 1)
this.renderer.physicallyCorrectLights = true
this.renderer.outputEncoding = THREE.sRGBEncoding
document.body.appendChild(this.renderer.domElement)
this.camera = new THREE.PerspectiveCamera (
70,
this.width / this.height,
0.001,
1000
)
this.camera.position.set(0, 0, 2)
this.controls = new OrbitControls(this.camera, this.renderer.domElement)
this.loader = new GLTFLoader()
this.width = window.innerWidth
this.height = window.innerHeight
this.time = 0
this.initTweakPane()
this.init()
this.resize()
window.addEventListener('resize',this.resize.bind(this))
}
/**
* set tweakpane
*/
initTweakPane() {
this.PARAMS = {
progress: 0.7,
}
this.pane = new Pane()
this.pane.addInput(this.PARAMS, 'progress', {
min: 0.0, max: 1.0,
})
}
init() {
// this.scene.add(new THREE.AmbientLight(0x404040))
const gltfUrl = 'https://dl.dropbox.com/s/w3llei92gnqqrw2/LeePerrySmith.glb?dl=0'
this.loader.load(gltfUrl, (gltf) => {
// console.log('gltf: ', gltf.scene.children[0])
this.material = new THREE.ShaderMaterial({
extensions: {
derivatives: '#extension GL_OES_standard_derivatives: enable'
},
side: THREE.DoubleSide,
uniforms: {
time: { type: 'f', value: 1.0 },
progress: { type: 'f', value: 0.0 },
},
transparent: true,
vertexShader: document.getElementById('vs').textContent,
fragmentShader: document.getElementById('fs').textContent,
depthTest: false,
depthWrite: false
})
// this.material = new THREE.PointsMaterial({ color: 0xFFFFFF, size: 0.25 })
this.mesh = new THREE.Points(gltf.scene.children[0].geometry, this.material)
this.mesh.position.set(0, -5, -40)
this.mesh.scale.set(7, 7, 7)
// console.log('this.mesh: ', this.mesh)
this.scene.add(this.mesh)
this.render()
},
(xhr) => {
console.log(xhr)
},
(err) => {
console.error("loading .obj went wrong, ", err)
})
}
resize() {
this.width = window.innerWidth
this.height = window.innerHeight
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
this.renderer.setSize( this.width, this.height )
this.camera.aspect = this.width / this.height
this.camera.updateProjectionMatrix()
}
render() {
console.log('this.material: ', this.material)
this.time += 0.05;
this.material.uniforms.time.value = this.time;
this.material.uniforms.progress.value = this.PARAMS.progress;
if (this.mesh) {
this.mesh.rotation.y = this.time * 0.1
}
requestAnimationFrame(this.render.bind(this))
this.renderer.render( this.scene, this.camera )
}
}
new App()
Also see: Tab Triggers