Commit 074dfa94 authored by Samson Ootoovak's avatar Samson Ootoovak

Add temporary shakey circle placeholder.

parent ba7a09fd
......@@ -8,6 +8,15 @@ WorldView.prototype = {
initialize: function() {
this.canvas.width = window.innerWidth
this.canvas.height = window.innerHeight
var middlex = this.canvas.width/2
var middley = this.canvas.height/2
this.worlds = [
{ x: middlex, y: middley },
{ x: middlex + 50, y: middley + 50 },
{ x: middlex + 50, y: middley - 50 },
{ x: middlex - 50, y: middley + 50 },
{ x: middlex - 50, y: middley - 50 },
]
},
cycle: function() {
this.clear()
......@@ -19,14 +28,37 @@ WorldView.prototype = {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
},
update: function() {
console.log("update")
this.worlds.forEach(function(element, index, array) {
array[index] = this.sparkle(element.x, element.y)
}.bind(this))
},
draw: function() {
console.log("draw")
this.worlds.forEach(function(element) {
this.shine(element)
}.bind(this))
},
queue: function() {
window.requestAnimationFrame(this.cycle.bind(this))
},
sparkle: function(x, y) {
var dirx = Math.random() < 0.5 ? -1 : 1
var diry = Math.random() < 0.5 ? -1 : 1
return {
x: x + (dirx * Math.random()),
y: y + (diry * Math.random()),
r: Math.floor(Math.random() * (256 - 0)),
g: Math.floor(Math.random() * (256 - 0)),
b: Math.floor(Math.random() * (256 - 0)),
a: Math.random()
}
},
shine: function(data) {
this.ctx.fillStyle = 'rgba('+data.r+', '+data.g+', '+data.b+', '+data.a+')'
this.ctx.beginPath()
this.ctx.arc(data.x, data.y, 50, 0, Math.PI * 2)
this.ctx.closePath()
this.ctx.fill()
}
}
module.exports = WorldView
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment