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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&display=swap" rel="stylesheet">
<div class="container">
<h1>serenity</h1>
</div>
<script id="vertShader" type="text">
// attributes, in
attribute vec3 aPosition;
// matrices
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
void main() {
gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
}
</script>
<script id="fragShader" type="text">
#ifdef GL_ES
precision highp float;
#endif
uniform float uTime;
uniform float uSpeedColor;
uniform vec2 uResolution;
uniform vec3 uColor1;
uniform vec3 uColor2;
uniform vec3 uColor3;
uniform vec3 uColor4;
uniform vec3 uColor5;
const int AMOUNT = 2;
const float scale = 2.0;
vec3 blendExclusion(vec3 base, vec3 blend) {
return base+blend-2.0*base*blend;
}
vec3 blendExclusion(vec3 base, vec3 blend, float opacity) {
return (blendExclusion(base, blend) * opacity + base * (1.0 - opacity));
}
float blendLighten(float base, float blend) {
return max(blend,base);
}
vec3 blendLighten(vec3 base, vec3 blend) {
return vec3(blendLighten(base.r,blend.r),blendLighten(base.g,blend.g),blendLighten(base.b,blend.b));
}
vec3 blendLighten(vec3 base, vec3 blend, float opacity) {
return (blendLighten(base, blend) * opacity + base * (1.0 - opacity));
}
float blendDarken(float base, float blend) {
return min(blend,base);
}
vec3 blendDarken(vec3 base, vec3 blend) {
return vec3(blendDarken(base.r,blend.r),blendDarken(base.g,blend.g),blendDarken(base.b,blend.b));
}
vec3 blendDarken(vec3 base, vec3 blend, float opacity) {
return (blendDarken(base, blend) * opacity + base * (1.0 - opacity));
}
float blendPinLight(float base, float blend) {
return (blend<0.5)?blendDarken(base,(2.0*blend)):blendLighten(base,(2.0*(blend-0.5)));
}
vec3 blendPinLight(vec3 base, vec3 blend) {
return vec3(blendPinLight(base.r,blend.r),blendPinLight(base.g,blend.g),blendPinLight(base.b,blend.b));
}
vec3 blendPinLight(vec3 base, vec3 blend, float opacity) {
return (blendPinLight(base, blend) * opacity + base * (1.0 - opacity));
}
float blendOverlay(float base, float blend) {
return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend));
}
vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b));
}
vec3 blendOverlay(vec3 base, vec3 blend, float opacity) {
return (blendOverlay(base, blend) * opacity + base * (1.0 - opacity));
}
float blendLinearDodge(float base, float blend) {
// Note : Same implementation as BlendAddf
return min(base+blend,1.0);
}
vec3 blendLinearDodge(vec3 base, vec3 blend) {
// Note : Same implementation as BlendAdd
return min(base+blend,vec3(1.0));
}
vec3 blendLinearDodge(vec3 base, vec3 blend, float opacity) {
return (blendLinearDodge(base, blend) * opacity + base * (1.0 - opacity));
}
float blendLinearBurn(float base, float blend) {
// Note : Same implementation as BlendSubtractf
return max(base+blend-1.0,0.0);
}
vec3 blendLinearBurn(vec3 base, vec3 blend) {
// Note : Same implementation as BlendSubtract
return max(base+blend-vec3(1.0),vec3(0.0));
}
vec3 blendLinearBurn(vec3 base, vec3 blend, float opacity) {
return (blendLinearBurn(base, blend) * opacity + base * (1.0 - opacity));
}
float blendLinearLight(float base, float blend) {
return blend<0.5?blendLinearBurn(base,(2.0*blend)):blendLinearDodge(base,(2.0*(blend-0.5)));
}
vec3 blendLinearLight(vec3 base, vec3 blend) {
return vec3(blendLinearLight(base.r,blend.r),blendLinearLight(base.g,blend.g),blendLinearLight(base.b,blend.b));
}
vec3 blendLinearLight(vec3 base, vec3 blend, float opacity) {
return (blendLinearLight(base, blend) * opacity + base * (1.0 - opacity));
}
float blendScreen(float base, float blend) {
return 1.0-((1.0-base)*(1.0-blend));
}
vec3 blendScreen(vec3 base, vec3 blend) {
return vec3(blendScreen(base.r,blend.r),blendScreen(base.g,blend.g),blendScreen(base.b,blend.b));
}
vec3 blendScreen(vec3 base, vec3 blend, float opacity) {
return (blendScreen(base, blend) * opacity + base * (1.0 - opacity));
}
float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
//lengths
float createLen() {
float time = 10.0 + uTime / 1.0;
vec2 coord = scale * (gl_FragCoord.xy - uResolution.xy) / min(uResolution.y, uResolution.x);
float len;
for(int i = 0; i < AMOUNT; i++) {
len = length(vec2(coord.x, coord.y));
coord.x = coord.x + cos(coord.y - sin(len)) - cos(time / 9.1);
coord.y = coord.y + sin(coord.y + cos(len)) + sin(time / 12.0);
}
return len;
}
float createLen2(float x, float y, float speed, float offset) {
float time = offset + uTime / speed;
vec2 coord = scale * (gl_FragCoord.xy - uResolution.xy) / min(uResolution.y, uResolution.x);
float len;
for(int i = 0; i < AMOUNT; i++) {
len = length(vec2(coord.x, coord.y));
coord.x = coord.x + sin(coord.y + cos(len) * cos(len)) + sin(time / x);
coord.y = coord.y - cos(coord.y + sin(len) * sin(len)) + cos(time / y);
}
return len;
}
float createLen3(float x, float y, float speed, float offset) {
float time = offset + uTime / speed;
vec2 coord = scale * (gl_FragCoord.xy - uResolution.xy) / min(uResolution.y, uResolution.x);
float len;
for(int i = 0; i < AMOUNT; i++) {
len = length(vec2(coord.x, coord.y));
//coord.x = coord.x - cos(coord.y + sin(len)) + cos(time / x);
coord.y = coord.y + sin(coord.y + cos(len)) + sin(time / y);
}
return len;
}
float createLen4(float x, float y, float speed, float offset) {
float time = offset + uTime / speed;
vec2 coord = scale * (gl_FragCoord.xy - uResolution.xy) / min(uResolution.y, uResolution.x);
float len;
for(int i = 0; i < AMOUNT; i++) {
len = length(vec2(coord.x, coord.y));
coord.x = coord.x - cos(coord.y + sin(len)) + cos(time / x);
//coord.y = coord.y + sin(coord.y + cos(len)) + sin(time / y);
}
return len;
}
vec3 createCircle(vec2 position, vec3 color, float size, float blur) {
vec2 pos = (gl_FragCoord.xy - uResolution.xy) / min(uResolution.y, uResolution.x) - position;
float circle = sqrt(pow(pos.x, 3.0) + pow(pos.y, 2.0));
circle = smoothstep(size, size + blur, 1.0 - circle);
return color * circle;
}
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main() {
vec2 coord = scale * (gl_FragCoord.xy - uResolution.xy) / min(uResolution.y, uResolution.x);
float len = createLen();
float len2 = createLen2(10.0, 10.0, 8.0, 20.0);
float len3 = createLen3(2.0, 2.0, 10.0, 30.0);
float len4 = createLen4(5.0, 20.0, 5.0, 40.0);
vec3 blue = uColor1 + cos(len) * 0.25 + 0.25;
vec3 turquoise = uColor2 + cos(len2) * 0.5 + 0.75;
/*
vec2 pos = vec2(sin(uTime * 0.01 * sin(uTime * 0.001)), cos(uTime * 0.002));
float radius = 0.5 + cos(uTime * 0.01) * 0.1;
vec3 turquoise = createCircle(pos, uColor2, radius, 0.5);
vec2 pos2 = vec2(cos(-uTime * 0.01), sin(-uTime * 0.03 * sin(-uTime * 0.001)));
float radius2 = 0.3 + cos(uTime * 0.01) * 0.01;
turquoise += createCircle(pos2, uColor2, radius2, 0.75);
*/
vec3 pink = uColor3 + cos(len3) * 0.5 + 0.75;
vec3 peach = uColor4 + cos(len4) * 0.75 + 0.95;
float pinkValue = min(1.0, max(0.0, 1.2 - (pink[0] / 1.2)));
float peachValue = min(1.0, max(0.0, 1.5 - (peach[0] / 1.2)));
float turquoiseValue = min(1.0, max(0.0, 1.5 - (turquoise[2] / 1.1)));
vec3 blend = blue;
blend = mix(blend, turquoise, turquoiseValue);
blend = mix(blend, peach, peachValue);
blend = mix(blend, pink, pinkValue);
//blend += turquoise;
//blend += torquoise;
//blend = blendDarken(blend, pink);
//blend = blendLinearBurn(blend, peach);
vec3 lightercolor = blendLinearBurn(blend, peach);
blend = mix(blend, lightercolor, max(1.0 - lightercolor[0], 0.0));
blend = blendOverlay(blend, vec3(0.0, 0.0, 0.0));
vec3 color = blend;
float r = color[0];
float g = color[1];
float b = color[2];
vec3 hsb = rgb2hsv(vec3(r, g, b));
hsb[1] -= rand(coord) * 0.15;
vec3 rgb = hsv2rgb(hsb);
gl_FragColor = vec4(rgb, 1.0);
}
</script>
body{
margin: 0;
overflow: clip;
background: #1B2021;
font-family: 'DM Serif Display', serif;
}
main{
position: fixed;
display: flex;
top: 0;
height: 100vh;
}
canvas{
width: 100%;
height: 100%;
margin: auto;
}
.container{
z-index: 2;
position: fixed;
top: 0;
height: 100vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
h1{
color: white;
font-size: 5rem;
}
const colors = ["#225ee1", "#28d7bf", "#ac53cf", "#e7a39c"];
const backgroundColor = "#31AFD4";
const width = window.innerWidth;
const height = window.innerHeight;
const totalFrames = 1000;
let frameCount = 0;
let recording = false;
let recordingStarted = false;
let frameDelta = 0;
let s;
function setup() {
canvas = createCanvas(width, height, WEBGL);
noiseSeed(20);
rectMode(CENTER);
noStroke();
let vert = document.getElementById('vertShader').innerText;
let frag = document.getElementById('fragShader').innerText;
s = createShader(vert, frag);
}
function draw() {
frameCount += 1;
frameDelta = (2 * Math.PI * (frameCount % totalFrames)) / totalFrames;
background(backgroundColor);
shader(s);
s.setUniform('uResolution',[width,height]);
s.setUniform('uTime',millis()/100);
s.setUniform('uLowGpu',false);
s.setUniform('uVeryLowGpu',false);
s.setUniform('uSpeedColor',20.0);
s.setUniform('uColor1',hex2rgb(colors[0]));
s.setUniform('uColor2',hex2rgb(colors[1]));
s.setUniform('uColor3',hex2rgb(colors[2]));
s.setUniform('uColor4',hex2rgb(colors[3]));
rect(0,0,width,height);
}
const hex2rgb = (hex) => {
const r = parseInt(hex.slice(1, 3), 16)
const g = parseInt(hex.slice(3, 5), 16)
const b = parseInt(hex.slice(5, 7), 16)
return [ r / 255, g / 255, b / 255 ];
}
Also see: Tab Triggers