Mercurial > MadButterfly
annotate nodejs/canvas.js @ 750:199bac90b90a
Add linearGradient support.
author | wycc |
---|---|
date | Thu, 26 Aug 2010 00:16:12 +0800 |
parents | cdd578c1f866 |
children | 9f4a1134ec82 |
rev | line source |
---|---|
736
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
1 var mbfly = require("mbfly"); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
2 var sys=require("sys"); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
3 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
4 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
5 function canvas(app,root) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
6 this.mb_rt = app.mb_rt; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
7 this.root = this.mb_rt.coord_new(root); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
8 this.bg_r = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
9 this.bg_g = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
10 this.bg_b = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
11 this.bg_a = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
12 this.stroke_r = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
13 this.stroke_g = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
14 this.stroke_b = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
15 this.stroke_a = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
16 this.stroke_w = 1; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
17 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
18 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
19 canvas.prototype.background=function(r,g,b,a) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
20 this.bg_r = r; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
21 this.bg_g = g; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
22 this.bg_b = b; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
23 this.bg_a = a; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
24 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
25 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
26 canvas.prototype.rect=function(x,y,w,h) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
27 var rect = this.mb_rt.rect_new(x,y,w,h,0,0); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
28 var paint = this.mb_rt.paint_color_new(this.bg_r,this.bg_g,this.bg_b,this.bg_a); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
29 paint.fill(rect); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
30 this.root.add_shape(rect); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
31 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
32 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
33 canvas.prototype.stroke=function(r,g,b,a) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
34 this.stroke_r = r; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
35 this.stroke_g = g; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
36 this.stroke_b = b; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
37 this.stroke_a = a; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
38 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
39 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
40 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
41 canvas.prototype.line=function(x1,y1,x2,y2) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
42 var s = "M "+x1+","+y1+" L "+x2+","+y2; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
43 sys.puts(s); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
44 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
45 var p = this.mb_rt.path_new(s); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
46 this.root.add_shape(p); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
47 var paint = this.mb_rt.paint_color_new(this.stroke_r,this.stroke_g,this.stroke_b,this.stroke_a); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
48 paint.stroke(p); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
49 p.stroke_width = this.stroke_w; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
50 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
51 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
52 canvas.prototype.strokeWeight=function(w) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
53 this.stroke_w = w; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
54 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
55 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
56 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
57 exports.canvas = canvas; |