<!--CSS -- >
<!-- CSS -->
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'>
<!-- / CSS -->
<canvas id="canvas"></canvas>
<footer class="source">
Little color composition stikes animation
</footer>
<!-- Javascript -->
<script src="https://cdn.rawgit.com/Phrogz/context-blender/master/context_blender.js"></script>
<!-- / Javascript -->
html, body{
html, body{
height: 100%;
}
body{
font-family: 'Ubuntu Mono';
background-color: #111;
color: #eee;
}
footer {
position: absolute;
bottom: 0;
padding: 10px;
}
#canvas {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: -1;
margin: auto;
}
x
minScreenSize = (Math.min window.innerWidth, window.innerHeight) / 4
w = minScreenSize
h = minScreenSize
slice = w / 8
domCanvas = document.getElementById("canvas")
domCanvasCtx = domCanvas.getContext "2d"
domCanvas.width = w
domCanvas.height = h
roundRect = (ctx, x, y, width, height, radius, fill, stroke) ->
stroke = true if typeof stroke is "undefined"
radius = 5 if typeof radius is "undefined"
ctx.beginPath()
ctx.moveTo x + radius, y
ctx.lineTo x + width - radius, y
ctx.quadraticCurveTo x + width, y, x + width, y + radius
ctx.lineTo x + width, y + height - radius
ctx.quadraticCurveTo x + width, y + height, x + width - radius, y + height
ctx.lineTo x + radius, y + height
ctx.quadraticCurveTo x, y + height, x, y + height - radius
ctx.lineTo x, y + radius
ctx.quadraticCurveTo x, y, x + radius, y
ctx.closePath()
ctx.stroke() if stroke
ctx.fill() if fill
return
#
#
#
#
#
#
class Layer
constructor: (@speed, @color) ->
@element = document.createElement "canvas"
@element.width = w
@element.height = h
@ctx = @element.getContext "2d"
clear: () ->
@element.width = @element.width
@ctx.translate w / 2, h / 2
draw: (dt) ->
@ctx.fillStyle = @color
@ctx.rotate (dt / 15) * Math.PI / @speed
roundRect @ctx, slice / -2, h / -2, slice, h, slice / 1.7, yes, no
@ctx.blendOnto domCanvasCtx, 'add'
#
#
#
#
#
#
layers = [
new Layer(90, '#00f')
new Layer(60, '#0f0')
new Layer(45, '#f00')
]
#
#
#
#
#
#
render = (dt)->
domCanvas.width = domCanvas.width
for layer in layers
layer.clear()
layer.draw(dt)
return
(animationLoop = (dt) ->
render(dt)
requestAnimationFrame animationLoop
return
)()