Mercurial > MadButterfly
comparison nodejs/svg.js @ 713:e60ae262127b
Recognize color name
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 13 Aug 2010 20:41:00 +0800 |
parents | 54618e0cd36b |
children | f53e45d1fcd0 |
comparison
equal
deleted
inserted
replaced
712:54618e0cd36b | 713:e60ae262127b |
---|---|
5 var ldr = mbfly.img_ldr_new("."); | 5 var ldr = mbfly.img_ldr_new("."); |
6 var background = mb_rt.rect_new(0, 0, 720, 480, 0, 0); | 6 var background = mb_rt.rect_new(0, 0, 720, 480, 0, 0); |
7 var paint = mb_rt.paint_color_new(1, 1, 1, 1); | 7 var paint = mb_rt.paint_color_new(1, 1, 1, 1); |
8 paint.fill(background); | 8 paint.fill(background); |
9 mb_rt.root.add_shape(background); | 9 mb_rt.root.add_shape(background); |
10 | |
11 var _std_colors = { | |
12 "white": [1, 1, 1], | |
13 "black": [0, 0, 0], | |
14 "red": [1, 0, 0] | |
15 }; | |
10 | 16 |
11 function MB_loadSVG(mb_rt,root,filename) { | 17 function MB_loadSVG(mb_rt,root,filename) { |
12 var doc = libxml.parseXmlFile(filename); | 18 var doc = libxml.parseXmlFile(filename); |
13 var nodes = doc.root().childNodes(); | 19 var nodes = doc.root().childNodes(); |
14 var coord = mb_rt.coord_new(root); | 20 var coord = mb_rt.coord_new(root); |
118 } | 124 } |
119 } | 125 } |
120 | 126 |
121 function _prepare_paint_color(color, alpha) { | 127 function _prepare_paint_color(color, alpha) { |
122 var paint; | 128 var paint; |
129 var c; | |
123 | 130 |
124 if (color[0]=='#') { | 131 if (color[0]=='#') { |
125 var r,g,b; | 132 var r,g,b; |
126 r = parseInt(color.substring(1,3),16)/256; | 133 r = parseInt(color.substring(1,3),16)/256; |
127 g = parseInt(color.substring(3,5),16)/256; | 134 g = parseInt(color.substring(3,5),16)/256; |
128 b = parseInt(color.substring(5,7),16)/256; | 135 b = parseInt(color.substring(5,7),16)/256; |
129 paint = mb_rt.paint_color_new(r, g, b, alpha); | 136 paint = mb_rt.paint_color_new(r, g, b, alpha); |
137 } else if(_std_colors[color]) { | |
138 c = _std_colors[color]; | |
139 paint = mb_rt.paint_color_new(c[0], c[1], c[2], alpha); | |
130 } else { | 140 } else { |
131 paint = mb_rt.paint_color_new(0,0,0,1); | 141 paint = mb_rt.paint_color_new(0,0,0,1); |
132 } | 142 } |
133 return paint; | 143 return paint; |
134 } | 144 } |