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

Side by Side Diff: canvas_bench/sprites.js

Issue 9355020: Added framework for canvas benchmark and two examples that stress drawImage. One example draws mult… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var sprites = (function() {
6 var objs;
7 var width;
8 var height;
9 var SPRITE_SPEED = 2;
10
11 var sprites = {};
12 sprites.init = function(w, h) {
13 objs = [];
14 width = w;
15 height = h;
16 };
17 sprites.add = function(img) {
18 var obj = { img: img,
19 x: Math.random() * (width - img.width),
20 y: Math.random() * (height - img.height),
21 dx: SPRITE_SPEED * (Math.random() < .5 ? -1 : 1),
22 dy: SPRITE_SPEED * (Math.random() < .5 ? -1 : 1) };
23 objs.push(obj);
24 };
25 sprites.draw = function(context) {
26 for (var i = 0, len = objs.length; i < len; ++i) {
27 var obj = objs[i];
28
29 obj.x += obj.dx;
30 if ((obj.x > (width - obj.img.width)) || (obj.x < 0))
31 obj.dx *= -1;
32
33 obj.y += obj.dy;
34 if ((obj.y > (height - obj.img.height)) || (obj.y < 0))
35 obj.dy *= -1;
36
37 context.drawImage(obj.img, obj.x, obj.y);
38 };
39 };
40 return sprites;
41 })();
OLDNEW
« canvas_bench/single_image.html ('K') | « canvas_bench/single_image.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698