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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!--
 * createShaderPlugin.js v1.0.1 Demo
 * https://github.com/magig/createShaderPlugin
 *
 * licensed under the MIT License.
 * http://www.opensource.org/licenses/mit-license
 * -->


<script id="rectangleFragShader" type="x-shader/x-fragment">
varying vec2 vTextureCoord;

uniform vec4 uTintAlpha;    // this special uniform is handled automatically (not part of sprite.pluginUniforms)
uniform float uTime;        // for this and all others, the name and type must match with sprite.pluginUniforms

void main(void) {
    float y = vTextureCoord.y + 0.0001 * uTime;
    if (y > 1.0) {
        y = 1.0;
    }
    vec4 top = vec4(1.0, 0.25, 0.0, 1.0);
    vec4 bottom = vec4(0.25, 0.5, 1.0, 1.0);
    vec4 pixel = (1.0 - y) * top + y * bottom;
    
    // apply tint and alpha
    gl_FragColor = pixel * uTintAlpha;
}
</script>


<script id="circleFragShader" type="x-shader/x-fragment">
varying vec2 vTextureCoord;

uniform vec4 uTintAlpha;
uniform vec4 uColor;

const vec2 center = vec2(0.5, 0.5);
const vec4 clearColor = vec4(0.0, 0.0, 0.0, 0.0);

void main(void) {
    float dist = distance(vTextureCoord, center);

    if (dist > 0.5) {
        gl_FragColor = clearColor;
    }
    else {
        vec4 pixel = uColor;

        // apply tint and alpha
        gl_FragColor = pixel * uTintAlpha;
    }
}
</script>


<script id="circleVertShader" type="x-shader/x-vertex">
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;

uniform mat3 projectionMatrix;

varying vec2 vTextureCoord;

void main(void) {
    gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
    vTextureCoord = aTextureCoord;
}
</script>
              
            
!

CSS

              
                body {
    padding: 0;
    margin: 0;
    overflow: hidden;
}

canvas {
    padding: 0;
    margin: 0;
    left: 0;
    top: 0;
    position: absolute;
    display: block;
    touch-action: none;
}
              
            
!

JS

              
                /*!
 * createShaderPlugin.js v1.0.1 Demo
 * https://github.com/magig/createShaderPlugin
 *
 * licensed under the MIT License.
 * http://www.opensource.org/licenses/mit-license
 */
    
    
// create the plugins before creating the app/renderer
// (if renderer was already created then it must be passed as param)
createShaderPlugin(
    'circle',                                           // name
    document.getElementById('circleVertShader').text,   // vertShader
    document.getElementById('circleFragShader').text,   // fragShader
    { uColor: new Float32Array([0.0, 1.0, 0.0, 1.0]) }  // default values
    // ,app.renderer                                    // renderer
);

// you can use the default vertShader by passing null
// you can leave out the default uniform values too
createShaderPlugin(
    'rectangle',
    null,
    document.getElementById('rectangleFragShader').text
);


// create app/renderer next
var app = new PIXI.Application({
    width: window.innerWidth,
    height: window.innerHeight,
    antialias: true,
    autoResize: true,
    backgroundColor: 0xFFFFFF
});
document.body.appendChild(app.view);


// create rectangleSprite: let's create this one manually, without the helper function
var rectangleSprite = new PIXI.Sprite();

// each uniform has a name and value
rectangleSprite.pluginUniforms = {
    uTime: 0.0
};

// world transform is applied, so E.G. when sprite is scaled 2X then your shader will draw (2 * pluginSize) pixels
rectangleSprite.pluginSize = new PIXI.Point(app.renderer.width, app.renderer.height);

// the plugin name used here must match the one passed to createShaderPlugin()
rectangleSprite.pluginName = 'rectangle';

app.stage.addChild(rectangleSprite);


// create circleSprite: lets use the helper function this time
var circleSprite = createShaderPluginSprite(
    'circle',
    new PIXI.Point(100.0, 100.0),
    { uColor: new Float32Array([0.0, 1.0, 0.0, 1.0]) }
);
    
circleSprite.anchor.set(0.5);
circleSprite.position.set(app.screen.width / 4.0, app.screen.height / 2.0);
app.stage.addChild(circleSprite);

   
// Animate
app.ticker.add(function (delta) {
    rectangleSprite.pluginUniforms.uTime += delta * 16.67;
    
    circleSprite.position.x += 1.5 * delta;
    
    var inc = 0.003 * delta;
    circleSprite.pluginUniforms.uColor[0] += inc;
    circleSprite.pluginUniforms.uColor[1] -= inc;
    if (circleSprite.pluginUniforms.uColor[0] > 1.0) {
        circleSprite.pluginUniforms.uColor[0] = 1.0;
        circleSprite.pluginUniforms.uColor[1] = 0.0;
    }
});
 

// that's about it -there's just a few more comments towards the top of the HTML tab about the uniforms - have fun:)

              
            
!
999px

Console