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.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<div id="container"></div>
<script id="vertexShader" type="x-shader/x-vertex">
uniform float iGlobalTime;
uniform vec2 iResolution;
uniform vec4 iMouse;
uniform float audio1;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
varying vec2 vUv;
void main() {
vUv = uv;
vec4 mvPosition = modelViewMatrix * vec4(position, 1 );
gl_Position = projectionMatrix * mvPosition;
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
uniform float iGlobalTime;
uniform vec2 iResolution;
uniform vec4 iMouse;
uniform float audio1;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
// inspired by bal-khan, by aiekick and some other cool algos here
//http://www.physics.sfasu.edu/astro/color/blackbody.html
//http://www.vendian.org/mncharity/dir3/blackbody/
//http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
#define I_MAX 3333
#define E .001 * audio1
#define t2 iGlobalTime
#define r2 iResolution.xy
#define CAM_PATH 1
#define CENTERED
#define ALTERNATE_DE
#define NO_MOUSTACHE
#define VIGNETTE_RENDER
#define FWD_SPEED -100.
float t;
float a;
vec4 march(vec3 pos, vec3 dir);
vec3 camera(vec2 uv);
vec2 rot(vec2 p, vec2 ang);
void rotate(inout vec2 v, float angle);
vec3 blackbody(float Temp)
{
vec3 col = vec3(255.);
col.x = 56000. * pow(Temp,(-3. / 2.)) + 148. * audio1;
col.y = 00.04 * log(Temp) - 623.6;
if (Temp > 6500.) col.y = 720000. * pow(Temp,(-3. / 2.)) + 184.;
col.z = 94.18 * log(Temp) - 948.6;
col = clamp(col, 0., 255.)/255.;
if (Temp < 1600.) col *= Temp/9000.;
return col ;
}
// -------------blackbody----------------- //
void main()
{
vec2 f = gl_FragCoord.xy;
t = iGlobalTime*1.5;
vec3 col = vec3(0., 0., 0.) * audio1;
vec2 R = iResolution.xy,
uv = vec2(f-R/2.) / R.y;
vec3 dir = camera(uv);
vec3 pos = vec3(0.0, 0.0, 1.0) * audio1;
#ifndef OUTSIDE
pos.z = t*FWD_SPEED;
#endif
vec4 inter = (march(pos, dir));
//#ifndef COUNTOURED
col.xyz = blackbody(inter.x*10. * audio1/inter.w);
// #else
//float countour = 500.*-inter.x;
//col.xyz = blackbody( inter.w*1. + countour );
//#endif
#ifdef VIGNETTE_RENDER
col.xyz += blackbody( ( (3.0-length(uv)*1.5)*inter.x) *18. ) ;
#endif
gl_FragColor = vec4(col,10.0) ;
}
float de_0(vec3 p)
{
float mind = cos(audio1);
vec3 pr = p - cos(t*.5) *.135;
rotate(pr.xy, (a) );
pr.xy /= .5;
pr.xyz = fract(pr.xyz);
pr -= .5;
mind = min(mind, (length(pr.xyz)-.432 - sin(iGlobalTime)*.1 ) );
return (mind);
}
float de_1(vec3 p) // cylinder
{
float mind = 0.0;
vec3 pr = p*1.9;
vec2 q;
q = vec2(length(pr.yx) - 1., pr.z );
#ifdef PULSE
q.y = rot(q.xy, vec2(-1.+sin(t*15.), 0.)).x;
#else
q.y = rot(q.xy, vec2(-1., 0.)).x;
#endif
mind = length(q) - 18.;
return mind;
}
// add 2 distances to constraint the de_0 to a cylinder
float de_2(vec3 p)
{
#ifndef OUTSIDE
return (de_0(p)-de_1(p)/3.);
#else
return (de_0(p)+de_1(p)/3.);
#endif
}
float scene(vec3 p)
{
float mind = 1e5;
a = -(t*.5) + 1.5*cos( 1.8*(p.y*.015+p.x*.015+p.z *.15) + t);
#ifdef CAM_PATH
vec2 rot = vec2( cos(a+1.57), sin(a+1.57) );
#else
vec2 rot = vec2( cos(a*.5), sin(a*.5) );
#endif
#ifndef CENTERED
#ifdef CAM_PATH
#if CAM_PATH == 0
p.x += rot.x*2.+sin(t*4.)/2.;
p.y += rot.y*2.+cos(t*4.)/2.;
#elif CAM_PATH == 1
p.x += rot.x*2.+sin(t*2.);
p.y += rot.y*2.+cos(t*2.);
#endif
#else
p.x += rot.x*4.;
p.y += rot.y*4.;
#endif
#endif
#ifdef OUTSIDE
vec2 rot1 = vec2( -.54, .84 ); // cos(1.), sin(1.)
p.xz *= mat2(rot1.x, rot1.y, -rot1.y, rot1.x);
#endif
mind = de_2(p);
return(mind);
}
vec4 march(vec3 pos, vec3 dir)
{
vec2 dist = vec2(10.0, 10.0);
vec3 p = vec3(0.0, 0.0, 0.0);
vec4 s = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = -1; i < I_MAX; ++i)
{
p = pos + dir * dist.y;
dist.x = scene(p);
dist.y += dist.x;
if (dist.x < E || dist.y > 60.)
{
s.y = 1.;
break;
}
s.x++;
}
s.w = dist.y;
return (s);
}
// Utilities
void rotate(inout vec2 v, float angle)
{
v = vec2(cos(angle)*v.x+sin(angle)*v.y,-sin(angle)*v.x+cos(angle)*v.y);
}
vec2 rot(vec2 p, vec2 ang)
{
float c = tan(ang.x);
float s = sin(ang.y) * tan(iGlobalTime);
mat2 m = mat2(c, -s, s, c);
return (p * m);
}
vec3 camera(vec2 uv)
{
float fov = 1.;
vec3 forw = vec3(0.0, 0.0,-2.5 + sin(iGlobalTime*.1) );
vec3 right = vec3(1.0, 0.0, 0.0);
vec3 up = vec3(0.0, 1.0, 0.0);
return (normalize((uv.x) * right + (uv.y) * up + fov * forw));
}
</script>
</body>
</html>
body {
margin: 0px;
overflow: hidden;
}
'use strict';
const clock = new THREE.Clock();
let camera, scene, renderer;
let uniforms;
let mouseX = 0,
mouseY = 0;
let analyser, dataArray;
const init = () => {
const container = document.getElementById('container');
camera = new THREE.PerspectiveCamera(19, window.innerWidth / window.innerHeight, 1, 1000000);
camera.position.z = 1;
scene = new THREE.Scene();
uniforms = {
iGlobalTime: { type: 'f', value: 10.0 },
audio1: { type: 'f', value: 10.0 },
iMouse: { type: 'v2', value: new THREE.Vector2() },
iResolution: { type: 'v2', value: new THREE.Vector2() },
iChannel0: {
type: 't',
value: THREE.ImageUtils.loadTexture('assets/tex1.png')
}
};
//uniforms.iChannel0.value.wrapS = uniforms.iChannel0.value.wrapT = THREE.RepeatWrapping;
const material = new THREE.ShaderMaterial({
uniforms,
vertexShader: document.getElementById('vertexShader').textContent,
fragmentShader: document.getElementById('fragmentShader').textContent
});
const geometry = new THREE.PlaneGeometry(10, 10);
const mesh = new THREE.Mesh(geometry, material);
mesh.scale.x = window.innerWidth;
mesh.scale.y = window.innerHeight;
scene.add(mesh);
renderer = new THREE.WebGLRenderer();
container.appendChild(renderer.domElement);
uniforms.iResolution.value.x = window.innerWidth;
uniforms.iResolution.value.y = window.innerHeight;
renderer.setSize(window.innerWidth, window.innerHeight);
};
const render = () => {
uniforms.iGlobalTime.value += clock.getDelta() * 0.1;
if (uniforms.iGlobalTime.value >= 100.0) {
uniforms.iGlobalTime.value = 0.0;
}
uniforms.iMouse.value.y = mouseY;
uniforms.iMouse.value.x = mouseX;
if (dataArray) {
analyser.getByteTimeDomainData(dataArray);
var v = dataArray[0] / 128.0;
//console.log(v);
uniforms.audio1.value = v;
} else {
uniforms.audio1.value = 1.45;
}
renderer.render(scene, camera);
};
const animate = () => {
requestAnimationFrame(animate);
render();
};
const onWindowResize = () => {
// (windowHalfX = window.innerWidth / 2),
// (windowHalfY = window.innerHeight / 2),
// (camera.aspect = window.innerWidth / window.innerHeight);
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
uniforms.iResolution.value.x = window.innerWidth;
uniforms.iResolution.value.y = window.innerHeight;
};
window.addEventListener('load', () => {
init();
animate();
});
window.addEventListener('resize', onWindowResize, false);
Also see: Tab Triggers