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

              
                <canvas id=a></canvas>
<script id=fs2 type=x-shader/x-fragment>
precision mediump float;

uniform float time;
uniform vec2 resolution;
varying vec4 vpos;
varying mat4 vM;

void main() {
	//gl_FragColor = vec4(1.0,1.0,1.0, 1.0);
	vec2 p = (gl_FragCoord.xy / resolution) - vec2(0.5,0.5);
	vec4 P = vM * vpos;
	float l1 = distance(vec4(p,0.0,1.0),P);
	float l2 = distance(vec4(p+vec2(sin(time),cos(time)),0.0,1.0),P);
	gl_FragColor = vec4(0.0,0.0,0.0,1.0)+abs(sin((l1+l2)*1.8))*1.0;
}
</script>
<script id=vs2 type=x-shader/x-vertex>
precision mediump float;

attribute vec4 pos;

uniform mat4 M;
varying vec4 vpos;
varying mat4 vM;
void main() {
	gl_Position=M*pos;
	vpos=pos;
	vM=M;
}
</script>
<script id=fs1 type=x-shader/x-fragment>
precision mediump float;

uniform float time;
uniform vec2 resolution;

void main() {
	vec2 uv = gl_FragCoord.xy / resolution;
	uv.x=(uv.x-0.5)+cos(time/2.0)*1.2;
	uv.y=(uv.y-0.5)+sin(time/2.0)*0.8;
	float l=1.0-sin(time+sin((uv.x+sin(uv.y)*sin(uv.x+time)*0.5)*3.0*uv.y)*uv.y*(300.0));
gl_FragColor = vec4( vec3( l, l, l), 1.0 );	
}
</script>
<script id=vs1 type=x-shader/x-vertex>
precision mediump float;
attribute vec4 pos;
uniform mat4 M;
void main(){
	gl_Position=M*pos;
}
</script>
              
            
!

CSS

              
                body{
  background: #fff;
  margin:0;
  overflow: hidden;
}

canvas{
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                w=a.width=innerWidth
h=a.height=innerHeight
g=a.getContext('webgl')||a.getContext('experimental-webgl')
g.enable(g.DEPTH_TEST)

// background	
p1=$prog(g,[vs1,fs1])
bkgBuf=$buf(sq(32))

// foreground
p2=$prog(g,[vs2,fs2])
diceBuf=$buf(qb())
P=perspective(45,w/h,0.1,100)

~function scene(time,m) {
	time/=1e3
	// clear screen
	g.clearColor(1/5,1/5,1/5,1)
	g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT)

	// program 1
	$prog(g,p1)
	$attr("pos")
	$bind("pos",bkgBuf,3)
	$uni("time",time)
	$uniV("resolution",[w,h])
	$uniM("M",mX(P, mT(0,0,-15)))
	g.drawArrays(g.TRIANGLE_STRIP,0,4)
	$attrOff("pos")
	
	// program 2
	$prog(g,p2) 
	$attr("pos")
	$bind("pos", diceBuf,3)
	// set uniforms
	$uni("time",time)
	$uniV("resolution",[w,h])
	// create transformation/rotation matrix
	// mX is matrix multiplication, mT is transformation, mR* is rotatio
	$uniM("M",mX(P,mX(mT(sin(time*2)*3,cos(time*3)*1.5,sin(time)*5-10),
	          mX(mX(mRx(time*0.1),mRy(time*4)),mRz(time*0.6)))))
	g.drawArrays(g.TRIANGLES,0,36)
	$attrOff("pos")

	requestAnimationFrame(scene)
}(0)
              
            
!
999px

Console