Skip to content

Commit 3f7088d

Browse files
committed
some simplifications
1 parent 5126825 commit 3f7088d

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

public/animations/carreQuiTourne.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
define({
2+
setup: function (context){
3+
this.rotation = 0;
4+
},
25
draw: function (context, borders){
36
context.fillStyle = "rgb(100,250,0)";
47
context.fillRect(0, 0, context.canvas.width, context.canvas.height);
58

69
context.save();
7-
context.translate(this.halfWidth, this.halfHeight);
8-
context.scale(3, 3);
9-
context.rotate(this.rotation* this.toRadians);
10-
11-
this.rotation = this.rotation + 1;
12-
10+
context.translate(75, 75);
11+
context.rotate(this.rotation);
1312
context.fillStyle = "rgb(150,20,200)";
14-
context.fillRect(-25, -25, 50, 50);
15-
13+
context.fillRect(-75, -75, 150, 150);
1614
context.restore();
17-
},
18-
setup: function (context){
19-
this.toRadians = Math.PI / 180;
20-
21-
this.rotation = 0;
22-
this.halfWidth = context.canvas.width / 2;
23-
this.halfHeight = context.canvas.height / 2;
15+
16+
this.rotation += Math.PI / 180;
2417
}});
+8-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
define([],
2-
function(){
1+
2+
define(["bibs/imageDataUtils"],
3+
function(idu){
34
return {
45
setup: function(context){
56
},
67
draw: function(context, borders){
7-
// paste current image one pixel down
8-
9-
// west
10-
var currentImage = context.getImageData(0, 0, context.canvas.width, context.canvas.height);
11-
context.putImageData(currentImage, 1, 0);
12-
// add new line
13-
context.putImageData(borders.west, 0, 0);
8+
var speed = 2;
149

10+
var vertical = true;
11+
idu.pushLine(context, borders, null, vertical, speed);
1512

16-
// north
13+
vertical = false
14+
idu.pushLine(context, borders, null, vertical, speed);
1715

18-
currentImage = context.getImageData(0, 0, context.canvas.width, context.canvas.height);
19-
context.putImageData(currentImage, 0, 1);
20-
// add new line
21-
context.putImageData(borders.north, 0, 0);
2216
}};
2317
});

public/animations/webCamQuiTourne.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
define(["bibs/webCam"], function(webCam){
22
return {
33
setup: function(context){
4-
if (this.v == null){
5-
this.v = webCam.provideVideoContext(320, 240);
6-
}
4+
this.webCam = webCam.makeWebCam();
75
this.rotation = 0;
8-
this.toRadians = Math.PI / 180;
9-
this.diagonal = Math.sqrt(2 * Math.pow(150,2));
106
},
117
draw: function(context, borders){
128

139
context.save();
1410
context.translate(75, 75);
15-
context.rotate(this.rotation * this.toRadians);
16-
var width = this.diagonal;
17-
var height = width * 240 / 320;
18-
context.drawImage(this.v, - width / 2, - height / 2,
19-
width, height);
11+
context.rotate(this.rotation );
12+
context.scale(0.8, 0.8);
13+
context.translate(- this.webCam.context.width / 2,
14+
- this.webCam.context.height / 2);
15+
this.webCam.copyFromCam(context);
2016
context.restore();
2117

22-
this.rotation = this.rotation + 1;
18+
this.rotation = this.rotation + Math.PI / 180 / 3;
2319
}
2420
};
2521
});

public/bibs/imageDataUtils.js

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ define({
168168
this.copyContextPixels(ctx, opts.copyRectangle, opts.pastePoint);
169169
},
170170
pushLine: function(ctx, borders, rec, horiz, speed, filter){
171+
rec = rec || this.rectangle(0, 0, ctx.canvas.width, ctx.canvas.height);
171172
var positiveDir = speed > 0,
172173
pixels = this.linePixels(ctx, borders, rec, horiz, positiveDir);
173174
this.pushPixels(ctx, pixels, rec, horiz, speed, filter);

public/bibs/webCam.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ define( function(context){
77
};
88

99
var provideVideoContext = function(width, height){
10-
applyVendorPrefix();
1110
var video = document.createElement("video");
1211
video.width = width;
1312
video.height = height;
@@ -41,5 +40,25 @@ define( function(context){
4140

4241
return video;
4342
};
44-
return {provideVideoContext: provideVideoContext};
43+
44+
var makeWebCam = function(width, height){
45+
if(!width){
46+
width = 320;
47+
height = 240;
48+
}
49+
50+
applyVendorPrefix();
51+
var videoContext = provideVideoContext(width, height);
52+
53+
return {
54+
context: videoContext,
55+
copyFromCam : function(context){
56+
context.drawImage(videoContext, 0, 0,
57+
videoContext.width, videoContext.height);
58+
}
59+
};
60+
61+
};
62+
63+
return {makeWebCam: makeWebCam };
4564
});

0 commit comments

Comments
 (0)