Snow

What

洋館に雪が降るアニメーション作品です。少しずつですが雪が積もっていきます。

How


var w = 400;
var h = 265;
var n = 5;
var snows = new Array(50);
var integrations = new Array(w / 4);
var v = 2;
var img;
function setup() {
  createCanvas(w, h);
  img = loadImage("castle.jpg");
  for(i = 0; i < snows.length; i++){
    snows[i] = [random(w), random(h), random(3,10)];
  }

  for(j = 0;j < integrations.length;j++){
    integrations[j] = 0;
  }
}
  
function draw() {
  image(img,0,0);
  noStroke();
  for(j = 0; j < snows.length; j++){
    drawLight(snows[j]);
    snows[j][1] += v;
  }

  drawIntegrate();
  var index = int(random(w/4));
  integrations[index] = integrations[index] + 1;
}

function drawLight(snow){
  for(i = 0;i < n;i++){
    fill(255, 255/n);
    ellipse(snow[0], (snow[1])%h, (snow[2] / n)*(n - i));
  }
}

function drawIntegrate(){
  for(j = 0;j < integrations.length;j++){
    fill(255, 200);
    ellipse(j * 4, h, integrations[j] * 4, integrations[j] * 2);
  }
}