Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: bower_components/gif.js/site/contents/tests/canvas.coffee

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 require '../scripts/vendor/mootools.js'
2 ready = require '../scripts/vendor/ready.js'
3
4 num_frames = 20
5 width = 600
6 height = 300
7 text = 'HYPNO TOAD'
8 textSize = 70
9
10 now = window.performance?.now?.bind(window.performance) or Date.now
11
12 rgb = (rgb...) -> "rgb(#{ rgb.map((v) -> Math.floor(v * 255)).join(',') })"
13 hsl = (hsl...) ->
14 hsl = hsl.map (v, i) -> if i is 0 then v * 360 else "#{ v * 100 }%"
15 return "hsl(#{ hsl.join(',') })"
16
17 ready ->
18 canvas = document.createElement 'canvas'
19 canvas.width = width
20 canvas.height = height
21
22 startTime = null
23 ctx = canvas.getContext '2d'
24 info = document.id 'info'
25
26 gif = new GIF
27 workers: 4
28 workerScript: '/gif.js/gif.worker.js'
29 width: width
30 height: height
31
32 gif.on 'start', -> startTime = now()
33
34 gif.on 'progress', (p) -> info.set 'text', Math.round(p * 100)+'%'
35
36 gif.on 'finished', (blob) ->
37 img = document.id 'result'
38 img.src = URL.createObjectURL(blob)
39 delta = now() - startTime
40 info.set 'text', """
41 100%
42 #{ (delta / 1000).toFixed 2 }sec
43 #{ (blob.size / 1000).toFixed 2 }kb
44 """
45
46 ctx.font = "bold #{ textSize }px Helvetica"
47 ctx.textAlign = 'center'
48 ctx.textBaseline = 'middle'
49 ctx.lineWidth = 3
50 w2 = width / 2
51 h2 = height / 2
52 for i in [0...num_frames]
53 p = i / (num_frames - 1)
54 grad = ctx.createRadialGradient w2, h2, 0, w2, h2, w2
55 grad.addColorStop 0, hsl p, 1, 0.5
56 grad.addColorStop 1, hsl (p + 0.2) % 1, 1, 0.4
57 ctx.fillStyle = grad
58 ctx.fillRect 0, 0, width, height
59 ctx.fillStyle = hsl (p + 0.5) % 1, 1, 0.7
60 ctx.strokeStyle = hsl (p + 0.8) % 1, 1, 0.9
61 ctx.fillText text, w2, h2
62 ctx.strokeText text, w2, h2
63 gif.addFrame ctx, {copy: true, delay: 20}
64
65 gif.render()
OLDNEW
« no previous file with comments | « bower_components/gif.js/site/contents/styles/vendor/reset.less ('k') | bower_components/gif.js/site/contents/tests/canvas.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698