<!DOCTYPE HTML>
<html>

<head>
    <title>proton.js-behaviour-RandomDirft3</title>
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <style type="text/css">
        body {
            font-family: Monospace;
            background-color: #f0f0f0;
            margin: 0px;
            overflow: hidden;
        }
        
        #testCanvas {
            background: #000000;
        }
    </style>
</head>

<body>
    <canvas id="testCanvas"></canvas>
    <script src="../../lib/requestAnimationFrame.min.js"></script>
    <script src="../../lib/stats.min.js"></script>
    <script src="//localhost:3001/build/proton.js"></script>
    <script>
        var canvas;
        var context;
        var proton;
        var renderer;
        var emitter;
        var stats;

        main();

        function main() {
            canvas = document.getElementById("testCanvas");
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
            context = canvas.getContext('2d');
            addStats();

            createProton();
            tick();
        }

        function addStats() {
            stats = new Stats();
            stats.setMode(2);
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.left = '0px';
            stats.domElement.style.top = '0px';
            document.body.appendChild(stats.domElement);
        }

        function createProton() {
            proton = new Proton;
            emitter = new Proton.Emitter();
            emitter.rate = new Proton.Rate(new Proton.Span(3, 6), new Proton.Span(.15, .3));
            
            emitter.addInitialize(new Proton.Body('image/bone.png', 93, 79));
            emitter.addInitialize(new Proton.Mass(1));
            emitter.addInitialize(new Proton.Life(2, 4));
            emitter.addInitialize(new Proton.V(new Proton.Span(1, 2), new Proton.Span(-80, 80), 'polar'));
            
            emitter.addBehaviour(new Proton.RandomDrift(15, 15, .05));
            emitter.addBehaviour(new Proton.Scale(Proton.getSpan(1, 0.5), 0));
            
            emitter.p.x = canvas.width / 2;
            emitter.p.y = canvas.height - 200;
            emitter.emit(5);
            proton.addEmitter(emitter);

            renderer = new Proton.CanvasRenderer(canvas);
            renderer.setStroke('#ff0000');
            renderer.onProtonUpdate = function() {};
            proton.addRenderer(renderer);

            window.onresize = function(e) {
                canvas.width = window.innerWidth;
                canvas.height = window.innerHeight;
                emitter.p.x = canvas.width / 2;
                emitter.p.y = canvas.height / 2;
            }
        }

        function tick() {
            requestAnimationFrame(tick);

            stats.begin();
            proton.update();
            stats.end();
        }
    </script>
</body>

</html>