Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

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

              
                <header>
  <h1>Art <span> of </span> posing </h1>
  <div class="description">
    1 / 6
  </div>
</header>

<nav>
  <a href="/" class="prev">Previous</a>
  <a href="/" class="next">Next</a>
</nav>

<div class="canvas-holder">
  <canvas> </canvas>
</div>
              
            
!

CSS

              
                html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}
body {
  line-height: 1;
}
ol,
ul {
  list-style: none;
}
blockquote,
q {
  quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
  content: "";
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}

@import url("https://fonts.googleapis.com/css2?family=IM+Fell+Great+Primer:[email protected];1&display=swap");

body {
  font-family: IM Fell Great Primer;
  font-size: 40px;
  line-height: 1.5;
  font-weight: 400;
  background-color: #fafdc7;
  color: #000000;
  margin: 40px;
}

header {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: space-between;
  padding: 40px;
}

nav {
  position: fixed;
  bottom: 50px;
  right: 0;
  left: 0;

  display: flex;
  justify-content: space-between;
}

header span {
  font-style: italic;
}

div.canvas-holder {
  height: 100vh;

  display: flex;
  align-items: center;
  justify-content: center;
}

div.canvas-holder canvas {
  width: 60vmin;
  height: 80vmin;
}

nav a {
  font-style: italic;
  text-decoration: none;
  color: #888888;
  padding: 40px;
}

nav a:hover {
  color: #000000;
}

              
            
!

JS

              
                const includes = `
#ifdef GL_ES
precision mediump float;
#endif
#define NUM_OCTAVES 5
float rand(vec2 n) { 
    return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}

float noise(vec2 p){
    vec2 ip = floor(p);
    vec2 u = fract(p);
    u = u*u*(3.0-2.0*u);
    
    float res = mix(
        mix(rand(ip),rand(ip+vec2(1.0,0.0)),u.x),
        mix(rand(ip+vec2(0.0,1.0)),rand(ip+vec2(1.0,1.0)),u.x),u.y);
    return res*res;
}

float fbm(vec2 x) {
    float v = 0.0;
    float a = 0.5;
    vec2 shift = vec2(100);
    // Rotate to reduce axial bias
    mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
    for (int i = 0; i < NUM_OCTAVES; ++i) {
        v += a * noise(x);
        x = rot * x * 2.0 + shift;
        a *= 0.5;
    }
    return v;
}
`;

const frag = (items) => {
  const ifLoop = items
    .map((item, index) => {
      return `
  if(index == ${index}) {
  return texture2D(textures[${index}], uv);
  }
`;
    })
    .join("else");

  return `
#define MAX ${items.length}
#ifdef GL_ES
precision mediump float;
#endif

uniform float u_time;
uniform vec2 u_resolution;
uniform float timeline;

uniform sampler2D textures[MAX];


uniform float startIndex;
uniform float endIndex;

varying vec3 v_normal;
varying vec2 v_texcoord;

${includes}

vec4 sampleColor(int index, vec2 uv){
 ${ifLoop}
 
}

void main(void)
{
    vec2 uv =  v_texcoord;
    float wave =  fbm(3.5 * uv + 0.2*u_time);
    float strength = smoothstep(0.0, 2.0, timeline)- smoothstep(3.0, 5.0, timeline);
    float distortion = mix(1.0,1.0 + strength,wave);
    uv -= 0.5;
    uv *= distortion;
    uv += 0.5;
    
    if(uv.x < 0.0 || uv.x > 1.0 || uv.y > 1.0 || uv.y < 0.0){
     discard;
    }
    
    // pick images
    vec4 startTexture = sampleColor(int(startIndex), uv);
    vec4 endTexture = sampleColor(int(endIndex), uv);
    
    float changeTimeline = smoothstep(2.0, 3.0,timeline);
    float mixer = 1.0 - step(changeTimeline, wave);
    
    
    vec4 color = mix(startTexture,endTexture, mixer);
    
    gl_FragColor = color;
}
`;
};

const paintings = [
  {
    src: "https://assets.codepen.io/3473719/image1.jpg",
    title: "1 / 6"
  },
  {
    src: "https://assets.codepen.io/3473719/image2.jpg",
    title: "2 / 6"
  },
  {
    src: "https://assets.codepen.io/3473719/image3.jpg",
    title: "3 / 6"
  },
  {
    src: "https://assets.codepen.io/3473719/image4.jpg",
    title: "4 / 6"
  },
  {
    src: "https://assets.codepen.io/3473719/image5.jpg",
    title: "5 / 6"
  },
  {
    src: "https://assets.codepen.io/3473719/image6.jpg",
    title: "6 / 6"
  }
];

const prevTag = document.querySelector("nav a.prev");

const nextTag = document.querySelector("nav a.next");

const descriptionTag = document.querySelector("header div");

const canvas = document.querySelector("div.canvas-holder canvas");

const sandbox = new GlslCanvas(canvas);
sandbox.load(frag(paintings));

let startIndex = 0;
let endIndex = 0;
let timeline = performance.now() - 9999;

const sizer = () => {
  const ww = window.innerWidth;
  const wh = window.innerHeight;

  const s = Math.min(ww, wh);
  const dpi = window.devicePixelRatio;

  canvas.width = s * 0.6 * dpi;
  canvas.height = s * 0.9 * dpi;

  canvas.style.width = s * 0.6 + "px";
  canvas.style.height = s * 0.9 + "px";
};

const update = () => {
  descriptionTag.innerHTML = paintings[endIndex].title;
  sandbox.setUniform("startIndex", startIndex);
  sandbox.setUniform("endIndex", endIndex);
  timeline = performance.now();

  startIndex = endIndex;
  tick();
};

const tick = () => {
  const diff = (performance.now() - timeline) / 1000;
  sandbox.setUniform("timeline", diff);
  requestAnimationFrame(tick);
};

const load = () => {
  sizer();
  tick();
  paintings.forEach((painting, index) => {
    sandbox.setUniform(`textures[${index}]`, painting.src);
  });
};

load();
const next = () => {
  endIndex = endIndex + 1;
  if (endIndex > paintings.length) {
    endIndex = 0;
  }
  update();
};

const prev = () => {
  endIndex = endIndex - 1;
  if (endIndex < 0) {
    endIndex = paintings.length - 1;
  }
  update();
};

// events

window.addEventListener("resize", sizer);

nextTag.addEventListener("click", (event) => {
  event.preventDefault();
  next();
});

prevTag.addEventListener("click", (event) => {
  event.preventDefault();
  prev();
});

              
            
!
999px

Console