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.
<script type="x-shader/x-vertex" id="vertexshader">
// attribute float aOrder;
uniform float uTime;
varying vec2 vUv;
varying float vOrder;
#define PI 3.14159265359
void main() {
vec4 modelPosition = modelMatrix * vec4(position, 1.0);
vec2 dist = vec2(modelPosition.x,modelPosition.z);
float radius = sin(uTime*.5);
float elevation = 0.7 * sin(-PI * length(dist) * 3. + uTime * 2.7);
modelPosition.y += elevation*.1;
vec4 viewPosition = viewMatrix * modelPosition;
gl_Position = projectionMatrix * viewPosition;
vUv = uv;
}
</script>
<script type="x-shader/x-fragment" id="fragment-dot">
varying vec2 vUv;
void main() {
float strength = 1.- step(.5,(step(.15, mod(vUv.y * 15.15,1.)) + step(.15, mod(vUv.x * 15.15,1.))));
vec3 color = vec3(0.2, 0.5, 1.0);
gl_FragColor = vec4(strength * color, strength);
}
</script>
<script type="x-shader/x-fragment" id="fragment-line">
varying vec2 vUv;
uniform vec3 uColor;
void main() {
float strength = 1.-step(.1, mod(vUv.y * 15.1,1.));
// vec3 color = vec3(0.97, 0.00, 1.00);
vec3 color = uColor;
gl_FragColor = vec4(strength * color, strength);
}
</script>
<script type="x-shader/x-fragment" id="fragment-grid">
varying vec2 vUv;
void main() {
float strength = 1. - step(.1, mod(vUv.y * 15.1,1.)) * step(.1, mod(vUv.x * 15.1,1.));
vec3 color = vec3(0.3, 0.8, 1.00);
gl_FragColor = vec4(strength * color,strength);
}
</script>
*{
padding:0;
margin:0;
}
canvas{
display:block;
}
import * as THREE from "three";
import { OrbitControls } from 'OrbitControls';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from "three/addons/postprocessing/RenderPass.js";
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js";
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
/**
* Sizes
*/
const sizes = {
width: window.innerWidth,
height: window.innerHeight
}
let renderer = new THREE.WebGLRenderer()
document.body.appendChild(renderer.domElement)
renderer.setSize(sizes.width, sizes.height)
/**
* Base
*/
// Scene
const scene = new THREE.Scene()
// scene.background = new THREE.Color("red");
/**
* Test mesh
*/
// Geometry
const geometry = new THREE.PlaneGeometry(1, 1, 15, 15)
geometry.rotateX(Math.PI/2);
const edges = new THREE.EdgesGeometry( geometry );
// Shaders
const vertexShader = document.querySelector('#vertexshader' ).textContent;
const lineShader = document.querySelector('#fragment-line' ).textContent;
const dotShader = document.querySelector('#fragment-dot' ).textContent;
const gridShader = document.querySelector('#fragment-grid' ).textContent;
// Material
const dotMat = new THREE.ShaderMaterial({
side:THREE.DoubleSide,
transparent:true,
uniforms:{
uTime:{ value:0 },
},
vertexShader: vertexShader,
fragmentShader: dotShader,
})
const lineMat = new THREE.ShaderMaterial({
side:THREE.DoubleSide,
transparent:true,
uniforms:{
uTime:{ value:0 },
uColor:{value:new THREE.Vector3(0.16, 0.94, 0.37)}
},
vertexShader: vertexShader,
fragmentShader: lineShader,
})
const gridMat = new THREE.ShaderMaterial({
side:THREE.DoubleSide,
transparent:true,
uniforms:{
uTime:{ value:0 },
},
vertexShader: vertexShader,
fragmentShader: gridShader,
})
const dots = new THREE.Mesh(geometry, dotMat);
dots.position.y = 3 / 2.5 - .5;
const lines1 = new THREE.Mesh(geometry, lineMat);
lines1.position.y = 2 / 2.5 - .5;
lines1.rotation.y = 1 * Math.PI/2;
const lines2 = new THREE.Mesh(geometry, lineMat.clone());
lines2.position.y = 1 / 2.5 - .5;
lines2.material.uniforms.uColor.value = new THREE.Vector3(0.82, 0.16, 0.94);
const grids = new THREE.Mesh(geometry, gridMat);
grids.position.y = 0 / 2.5 - .5;
scene.add(dots,lines1,lines2,grids)
/**
* Camera
*/
// Base camera
const camera = new THREE.OrthographicCamera( -1.5, 1.5, sizes.height/sizes.width * 1.5 , sizes.height/sizes.width * -1.5, 1.5, 1000 );
camera.position.set(3,3,3)
// camera.rotation.y=(Math.PI/2)
scene.add(camera)
// Controls
const controls = new OrbitControls(camera, renderer.domElement)
controls.enableDamping = true
/**
* PostProcessing
*/
let renderScene = new RenderPass( scene, camera );
const scanlinesShader = {
name: 'scanlinesShader',
uniforms: {
'tDiffuse': { value: null },
'opacity': { value: 1.0 }
},
vertexShader: /* glsl */`
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,
fragmentShader: /* glsl */`
uniform float opacity;
uniform sampler2D tDiffuse;
varying vec2 vUv;
void main() {
gl_FragColor = texture2D( tDiffuse, vUv );
float strength = step(.2, mod(vUv.y * 10.,1.));
vec4 scanlines = clamp(vec4(mod((vUv.y * 400.0), 2.4)), 0.2, 1.0) * 0.4 + 0.6;
gl_FragColor *= scanlines;
}`
};
const scanlinesPass = new ShaderPass( scanlinesShader );
let bloomPass = new UnrealBloomPass(
new THREE.Vector2( window.innerWidth, window.innerHeight ),
.9, .9, 0.1
);
let composer = new EffectComposer( renderer );
composer.addPass( renderScene );
composer.addPass( bloomPass );
composer.addPass( scanlinesPass );
/**
* Animate
*/
const clock = new THREE.Clock();
const tick = () =>
{
// Update controls
controls.update()
const elapsedTime = clock.getElapsedTime()
dotMat.uniforms.uTime.value =
lineMat.uniforms.uTime.value =
lines2.material.uniforms.uTime.value =
gridMat.uniforms.uTime.value = elapsedTime;
// Render
composer.render(scene, camera)
// Call tick again on the next frame
window.requestAnimationFrame(tick)
}
tick()
window.addEventListener('resize', () =>
{
// Update sizes
sizes.width = window.innerWidth
sizes.height = window.innerHeight
// Update camera
camera.top = sizes.height / sizes.width * 1.5 ;
camera.bottom = sizes.height / sizes.width * -1.5 ;
camera.updateProjectionMatrix()
// Update renderer
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
})
Also see: Tab Triggers