Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <script id="fragmentShader" type="x-shader/fragment">
precision highp float;
uniform vec3 color;

uniform float time;
uniform float width;
uniform float height;

#define PI 3.141592654
#define ITERS 120

uniform float a;
uniform float phi;
uniform float omega;
uniform float N;
// taken from wikipedia and adapted to GLSL
// https://en.wikipedia.org/wiki/Julia_set
float julia(vec2 p, vec2 c, float n) {
  float x = p.x;
  float y = p.y;
  for (int i = 0; i < ITERS; i++) {
    if (x * x + y * y >= 4.0) {
      return float(i);
    }
    float x1 = x * x - y * y;
    float y1 = 2.0 * x * y;
    x = x1 + c.x; 
    y = y1 + c.y;
  }
  return -1.0;
}
  
float multijulia(vec2 p, vec2 c, float n) {
  float x = p.x;
  float y = p.y;
  for (int i = 0; i < ITERS; i++) {
    if (x * x + y * y >= 4.0) {
      return float(i);
    }
    float x1 = pow(x * x + y * y, n / 2.0) * cos(n * atan(y, x));
    float y1 = pow(x * x + y * y, n / 2.0) * sin(n * atan(y, x));
    x = x1 + c.x;
    y = y1 + c.y;
  }
  return -1.0;
}
  
// by @mattdesl    
float hue2rgb(float f1, float f2, float hue) {
    if (hue < 0.0)
        hue += 1.0;
    else if (hue > 1.0)
        hue -= 1.0;
    float res;
    if ((6.0 * hue) < 1.0)
        res = f1 + (f2 - f1) * 6.0 * hue;
    else if ((2.0 * hue) < 1.0)
        res = f2;
    else if ((3.0 * hue) < 2.0)
        res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
    else
        res = f1;
    return res;
}

vec3 hsl2rgb(vec3 hsl) {
    vec3 rgb;   
    if (hsl.y == 0.0) {
        rgb = vec3(hsl.z); // Luminance
    } else {
        float f2;
        
        if (hsl.z < 0.5)
            f2 = hsl.z * (1.0 + hsl.y);
        else
            f2 = hsl.z + hsl.y - hsl.y * hsl.z;
            
        float f1 = 2.0 * hsl.z - f2;
        
        rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0));
        rgb.g = hue2rgb(f1, f2, hsl.x);
        rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0));
    }   
    return rgb;
}  

void main () {
  float vmin = min(width, height);
  vec3 black = vec3(0.0);
  vec3 white = vec3(1.0);
  vec3 c = vec3(1.0, 0.0, 1.0);
  vec2 p0 = vec2((gl_FragCoord.x - width * .5) / vmin, 
                (gl_FragCoord.y - height * .5) / vmin);
  vec2 p1 = p0 + vec2(cos(time * .2), sin(time * .3)) * .01;
  vec2 p = p1 * (0.9 + 0.9 * (1.0 + sin(time * .1)));
  float t = sin(time * omega) * PI * phi;
  float j = multijulia(p, a * vec2(cos(t), sin(t)), N);
  vec3 color = j < 0.0 ? black : 
    hsl2rgb(vec3(mod(time * .05 + j * 4.0 / float(ITERS), 1.0), 1.0, .7 - 2.0 * j / float(ITERS)));
  gl_FragColor = vec4(vec3(color), 1.0);
}
</script>
<script id="vertexShader" type="x-shader/vertex">
precision mediump float;
attribute vec2 position;

void main () {
  gl_Position = vec4(position, 0, 1);
} 
</script>
<div class="ui">
  <div class="ui__row">
    <label for="a">a</label>
    <input id="a" type="range" min="0.1" max="0.8" step="0.0001" value="0.28543">
  </div>
  <div class="ui__row">
    <label for="phi">ϕ</label>
    <input id="phi" type="range" min=".0001" max="1.0" step="0.0001" value="0.0125"> 
  </div>
  <div class="ui__row">
    <label>ω</label>
    <input id="omega" type="range" min=".0001" max="1.0" step="0.0001" value="0.2"> 
  </div>
  <div class="ui__row">
    <label>N</label>
    <input id="N" type="range" min="1" max="20" step="1" value="2.0">
  </div>
</div>
              
            
!

CSS

              
                

* {
  box-sizing: border-box;
}

body {
  font-size: 18px;
  font-family: sans-serif;
}

.ui {
  opacity: 0;
  transition: opacity 200ms ease-in-out; 
  position: absolute;
  z-index: 1;
  width: 100%;
  height: auto;
  padding: 4px;
  background: rgba(0,0,0,.6);
  display: flex;
  flex-wrap: wrap;
}

.ui__row {
  display: flex;
  flex: 1;
  padding: 0 32px 0 0;
  align-items: center;
}

label {
  width: 24px;
  display: block;
  color: white;
  font-size: 14px;
}

input[type=range] {
  display: block;
  width: 150px;
  position: relative;
}

input[type=range]::after {
  position: absolute;
  left: calc(100% + 8px);
  top: 4px;
  display: block;
  content: attr(value);
  color: #fff;
  font-size: 12px;
  font-family: sans-serif;
}

body:hover .ui, body:active .ui {
  opacity: 1.0;
}
              
            
!

JS

              
                const d = document
const $ = d.querySelector.bind(d)
const regl = createREGL()
const $code = (sel) => (
  document.getElementById(sel) || {}
).textContent || "void main() {}"



const drawFrame = regl({
  frag: $code('fragmentShader'),
  vert: $code('vertexShader'),
  
  attributes: {
    position: [[-1,-1],
               [-1, 1],
               [ 1,-1],
               [ 1,-1],
               [-1, 1],
               [ 1, 1]]
  },
  
  uniforms: {
    color: [1,0,0],
    width: ctx => ctx.viewportWidth,
    height: ctx => ctx.viewportHeight,
    time: ctx => ctx.tick*.05,
    a: () => parseFloat($('#a').value, 10),
    phi: () => parseFloat($('#phi').value, 10),
    omega: () => parseFloat($('#omega').value, 10),
    N: () => parseFloat($('#N').value, 10)
  },
  
  count: 6
})

regl.frame(ctx => {
  regl.clear({
    color: [1,1,1,1],
    depth: 1
  })
  drawFrame()
})

window.addEventListener('input', (evt) => {
  const { target } = evt
  target.setAttribute('value', target.value)
})
              
            
!
999px

Console