cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / tools / perf / page_sets / tough_canvas_cases / many_images / sprites.js
blob283c2b37ddb2e7cce9d58fd45409172057985f0f
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.
5 var sprites = (function() {
6 var objs;
7 var width;
8 var height;
9 var SPRITE_SPEED = 2;
11 var sprites = {};
12 sprites.init = function(w, h) {
13 objs = [];
14 width = w;
15 height = h;
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);
25 sprites.draw = function(context) {
26 for (var i = 0, len = objs.length; i < len; ++i) {
27 var obj = objs[i];
29 obj.x += obj.dx;
30 if ((obj.x > (width - obj.img.width)) || (obj.x < 0))
31 obj.dx *= -1;
33 obj.y += obj.dy;
34 if ((obj.y > (height - obj.img.height)) || (obj.y < 0))
35 obj.dy *= -1;
37 context.drawImage(obj.img, obj.x, obj.y);
40 return sprites;
41 })();