Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

0
ReferenceError: Vector2 is not defined
Post Body

var $ = require('jquery');

$(document).ready(() => {

jsCanvasSnow.init();

jsCanvasSnow.start();

}, false);

function jsParticle(origin, velocity, size, amplitude) {

this.origin = origin;

this.position = new Vector2(origin.x, origin.y);

this.velocity = velocity || new Vector2(0, 0);

this.size = size;

this.amplitude = amplitude;

this.dx = Math.random() * 100;

this.update = function(delta_time) {

this.position.y = this.velocity.y * delta_time;

this.dx = this.velocity.x * delta_time;

this.position.x = this.origin.x * (this.amplitude * Math.sin(this.dx));

};

}

var jsCanvasSnow =

{

canvas : null,

ctx : null,

particles : \[\],

running : false,

start\_time : 0,

frame\_time : 0,

init : function( )

{

    // use the container width and height

    this.canvas = document.getElementById('particle\_canvas');

    this.ctx = this.canvas.getContext('2d');

this.resize(window.innerWidth, window.innerHeight);

    // change these values

// the 2 element arrays represent min and max values

    this.pAmount = 5000;         // amount of particles

    this.pSize = \[0.5 , 1.5\];    // min and max size

    this.pSwing = \[0.1, 1\];      // min and max oscilation speed for x movement

    this.pSpeed = \[40, 100\],     // min and max y speed

    this.pAmplitude = \[25, 50\];  // min and max distance for x movement

this._init_particles();

},

start : function()

{

    this.running = true;

    this.start\_time = this.frame\_time = microtime();

    this.\_loop();

},

stop : function()

{

    this.running = false;

},

resize : function(w, h)

{

this.canvas.width = w;

this.canvas.height = h;

},

\_loop : function()

{

    if ( jsCanvasSnow.running )

    {

        jsCanvasSnow.\_clear();

        jsCanvasSnow.\_update();

        jsCanvasSnow.\_draw();

        jsCanvasSnow.\_queue();

    }

},

\_init\_particles : function()

{

    // clear the particles array

    this.particles.length = 0;

    for ( var i = 0 ; i < this.pAmount ; i  )

    {

        var origin = new Vector2(frand(0, this.canvas.width), frand(-this.canvas.height, 0));

        var velocity = new Vector2(frand(this.pSwing\[0\],this.pSwing\[1\]), frand(this.pSpeed\[0\],this.pSpeed\[1\]));

        var size = frand(this.pSize\[0\], this.pSize\[1\]);

        var amplitude = frand(this.pAmplitude\[0\], this.pAmplitude\[1\]);

        this.particles.push(new jsParticle(origin, velocity, size, amplitude));

    }

},

\_update : function()

{

    // calculate the time since the last frame

    var now\_time = microtime();

    var delta\_time = now\_time - this.frame\_time;

    for ( var i = 0 ; i < this.particles.length ; i  )

    {

        var particle = this.particles\[i\];

        particle.update(delta\_time);

        if (particle.position.y-particle.size > this.canvas.height)

        {

// reset the particle to the top and a random x position

particle.position.y = -particle.size;

particle.position.x = particle.origin.x = Math.random() * this.canvas.width;

particle.dx = Math.random() * 100;

        }

    }

    // save this time for the next frame

    this.frame\_time = now\_time;

},

\_draw : function()

{

    this.ctx.fillStyle = 'rgb(255,255,255)';

    for ( var i = 0 ; i < this.particles.length ; i  )

    {

        var particle = this.particles\[i\];

        this.ctx.fillRect(particle.position.x, particle.position.y, particle.size, particle.size);

    }

},

\_clear : function()

{

    this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);

},

\_queue : function()

{

    window.requestAnimationFrame( jsCanvasSnow.\_loop );

}

};

Author
Account Strength
80%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
251
Link Karma
97
Comment Karma
154
Profile updated: 5 days ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago