source: code/Website/open-flash-chart/charts/series/bars/Plastic.as@ 7849

Last change on this file since 7849 was 7849, checked in by dennisw, 15 years ago
File size: 11.9 KB
Line 
1package charts.series.bars {
2 import flash.filters.DropShadowFilter;
3 import flash.geom.Matrix;
4
5 public class Plastic extends Base
6 {
7
8 public function Plastic( index:Number, props:Properties, group:Number ) {
9
10 super(index, props, group);
11
12 var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
13 dropShadow.blurX = 5;
14 dropShadow.blurY = 5;
15 dropShadow.distance = 3;
16 dropShadow.angle = 45;
17 dropShadow.quality = 2;
18 dropShadow.alpha = 0.4;
19 // apply shadow filter
20 this.filters = [dropShadow];
21 }
22
23 public override function resize( sc:ScreenCoordsBase ):void {
24
25 this.graphics.clear();
26 var h:Object = this.resize_helper( sc as ScreenCoords );
27
28 this.bg( h.width, h.height, h.upside_down );
29 this.glass( h.width, h.height, h.upside_down );
30 }
31
32 private function bg( w:Number, h:Number, upside_down:Boolean ):void {
33
34 var rad:Number = w/3;
35 if ( rad > ( w / 2 ) )
36 rad = w / 2;
37
38 this.graphics.lineStyle(0, 0, 0);// this.outline_colour, 100);
39
40 var allcolors:Array = GetColours(this.colour);
41 var lowlight:Number = allcolors[2];
42 var highlight:Number = allcolors[0];
43 var bgcolors:Array = [allcolors[1], allcolors[2], allcolors[2]];
44 var bgalphas:Array = [1, 1, 1];
45 var bgratios:Array = [0, 115, 255];
46 //var bgcolors:Array = [allcolors[1], allcolors[2]];
47 //var bgalphas:Array = [1, 1];
48 //var bgratios:Array = [0, 255];
49 var bgmatrix:Matrix = new Matrix();
50 var xRadius:Number;
51 var yRadius:Number;
52 var x:Number;
53 var y:Number;
54 var bevel:Number = 0.02 * w;
55 var div:Number = 3;
56
57 bgmatrix.createGradientBox(w, h, (180 / 180) * Math.PI );
58 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
59
60 if ( h > 0 || h < 0)
61 { /* height is not zero */
62
63 /* draw outline darker rounded rectangle */
64 this.graphics.beginFill(0x000000, 1);
65 this.graphics.drawRoundRect(0, 0, w, h, w/div, w/div);
66
67 /* draw inner highlight rounded rectangle */
68 this.graphics.beginFill(highlight, 1);
69 this.graphics.drawRoundRect(0 + bevel, 0 + bevel, w - 2 * bevel, h - 2 * bevel, w/div - 2*bevel, w/div - 2 * bevel);
70
71 /* draw inner gradient rounded rectangle */
72 bevel = bevel * 3;
73 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
74 this.graphics.drawRoundRect(0 + bevel, 0 + bevel, w - 2 * bevel, h - 2 * bevel, w/div - 2*bevel, w/div - 2 * bevel);
75
76 }
77 else
78 {
79
80 /* draw outline darker rounded rectangle */
81 this.graphics.beginFill(0x000000, 1);
82 this.graphics.drawRoundRect(0, 0 - 2*bevel, w, h + 4*bevel, w/div, w/div);
83
84 /* draw inner highlight rounded rectangle */
85 this.graphics.beginFill(highlight, 1);
86 this.graphics.drawRoundRect(0 + bevel, 0 - 2*bevel + bevel, w - 2 * bevel, h + 4*bevel - 2 * bevel, w/div - 2*bevel, w/div - 2 * bevel);
87
88 /* draw inner gradient rounded rectangle */
89 bevel = bevel * 3;
90 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, bgcolors, bgalphas, bgratios, bgmatrix, 'pad'/*SpreadMethod.PAD*/ );
91 this.graphics.drawRoundRect(0 + bevel, 0 - 2*bevel + bevel, w - 2 * bevel, h + 4*bevel - 2 * bevel, w/div - 2*bevel, w/div - 2 * bevel);
92
93 }
94
95
96 this.graphics.endFill();
97 }
98
99 private function glass( w:Number, h:Number, upside_down:Boolean ): void {
100
101 /* if this section is commented out, the white shine overlay will not be drawn */
102
103 this.graphics.lineStyle(0, 0, 0);
104 var bgcolors:Array = GetColours(this.colour);
105 var bgmatrix:Matrix = new Matrix();
106 var bgalphas:Array = [1, 1];
107 var bgratios:Array = [0, 255];
108 /*var colors:Array = [0xFFFFFF, 0xFFFFFF];
109 var alphas:Array = [0, 0.75];
110 var ratios:Array = [127,255]; */
111 var colors:Array = [0xFFFFFF, 0xFFFFFF, 0xFFFFFF];
112 var alphas:Array = [0, 0.05, 0.75];
113 var ratios:Array = [0, 123, 255];
114 var xRadius:Number;
115 var yRadius:Number;
116 var x:Number;
117 var y:Number;
118 var matrix:Matrix = new Matrix();
119 var bevel:Number = 0.02 * w;
120 var div:Number = 3;
121
122 matrix.createGradientBox(width, height, (180 / 180) * Math.PI );
123 this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );
124 var rad:Number = w / 3;
125
126 if ( h > 0 || h < 0 )
127 {
128 /* draw shine rounded rectangle */
129 this.graphics.drawRoundRect(0 + bevel, 0 + bevel, w - 2 * bevel, h - 2 * bevel, w/div - 2*bevel, w/div - 2 * bevel);
130 }
131 else
132 {
133 /* draw shine rounded rectangle */
134 this.graphics.drawRoundRect(0 + bevel, 0 - 2*bevel + bevel, w - 2 * bevel, h + 4*bevel - 2 * bevel, w/div - 2*bevel, w/div - 2 * bevel);
135 }
136 this.graphics.endFill();
137
138 }
139
140 /* function to process colors */
141 /* returns a base color, a lowlight color, and a highlight color for the gradients based on the color passed in */
142 public static function GetColours( col:Number):Array {
143 var rgb:Number = col; /* decimal value for color */
144 var red:Number = (rgb & 16711680) >> 16; /* extacts the red channel */
145 var green:Number = (rgb & 65280) >> 8; /* extacts the green channel */
146 var blue:Number = rgb & 255; /* extacts the blue channel */
147 var shift:Number = 0.15; /* shift factor */
148 var loshift:Number = 1.75; /* lowlight shift factor */
149 var basecolor:Number = col; /* base color to be returned */
150 var lowlight:Number = col; /* lowlight color to be returned */
151 var highlight:Number = col; /* highlight color to be returned */
152 var bgred:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
153 var bggreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
154 var bgblue:Number = rgb & 255; /* blue channel for highlight */
155 var lored:Number = (rgb & 16711680) >> 16; /* red channel for lowlight */
156 var logreen:Number = (rgb & 65280) >> 8; /* green channel for lowlight */
157 var loblue:Number = rgb & 255; /* blue channel for lowlight */
158 var hired:Number = (rgb & 16711680) >> 16; /* red channel for highlight */
159 var higreen:Number = (rgb & 65280) >> 8; /* green channel for highlight */
160 var hiblue:Number = rgb & 255; /* blue channel for highlight */
161
162 /* set base color components based on ability to shift lighter and darker */
163 if (red + red * shift < 255 && red - loshift * red * shift > 0)
164 { /* red can be shifted both lighter and darker */
165 bgred = red;
166 }
167 else
168 { /* red can be shifter either lighter or darker */
169 if (red + red * shift < 255)
170 { /* red can be shifter lighter */
171 bgred = red + red / shift;
172 }
173 else
174 { /* red can be shifted darker */
175 bgred = red - loshift * red * shift;
176 }
177 }
178
179 if (blue + blue * shift < 255 && blue - loshift * blue * shift > 0)
180 { /* blue can be shifted both lighter and darker */
181 bgblue = blue;
182 }
183 else
184 { /* blue can be shifter either lighter or darker */
185 if (blue + blue * shift < 255)
186 { /* blue can be shifter lighter */
187 bgblue = blue + blue * shift;
188 }
189 else
190 { /* blue can be shifted darker */
191 bgblue = blue - loshift * blue * shift;
192 }
193 }
194
195 if (green + green * shift < 255 && green - loshift * green * shift > 0)
196 { /* green can be shifted both lighter and darker */
197 bggreen = green;
198 }
199 else
200 { /* green can be shifted either lighter or darker */
201 if (green + green * shift < 255)
202 { /* green can be shifter lighter */
203 bggreen = green + green * shift;
204 }
205 else
206 { /* green can be shifted darker */
207 bggreen = green - loshift * green * shift;
208 }
209 }
210
211 /* set highlight and lowlight components based on base colors */
212 hired = bgred + red * shift;
213 lored = bgred - loshift * (red * shift);
214 hiblue = bgblue + blue * shift;
215 loblue = bgblue - loshift * (blue * shift);
216 higreen = bggreen + green * shift;
217 logreen = bggreen - loshift * (green * shift);
218
219 /* reconstruct base and highlight */
220 basecolor = bgred << 16 | bggreen << 8 | bgblue;
221 highlight = hired << 16 | higreen << 8 | hiblue;
222 lowlight = lored << 16 | logreen << 8 | loblue;
223
224 /* return base, lowlight, and highlight */
225 return [highlight, basecolor, lowlight];
226 }
227
228 /* ellipse cos helper function */
229 public static function magicTrigFunctionX (pointRatio:Number):Number{
230 return Math.cos(pointRatio*2*Math.PI);
231 }
232
233 /* ellipse sin helper function */
234 public static function magicTrigFunctionY (pointRatio:Number):Number{
235 return Math.sin(pointRatio*2*Math.PI);
236 }
237
238 /* ellipse function */
239 /* draws an ellipse from passed center coordinates, x and y radii, and number of sides */
240 public function Ellipse(centerX:Number, centerY:Number, xRadius:Number, yRadius:Number, sides:Number):Number{
241
242 /* move to first point on ellipse */
243 this.graphics.moveTo(centerX + xRadius, centerY);
244
245 /* loop through sides and draw curves */
246 for(var i:Number=0; i<=sides; i++){
247 var pointRatio:Number = i/sides;
248 var xSteps:Number = magicTrigFunctionX(pointRatio);
249 var ySteps:Number = magicTrigFunctionY(pointRatio);
250 var pointX:Number = centerX + xSteps * xRadius;
251 var pointY:Number = centerY + ySteps * yRadius;
252 this.graphics.lineTo(pointX, pointY);
253 }
254
255 /* return 1 */
256 return 1;
257 }
258
259 }
260 }
Note: See TracBrowser for help on using the repository browser.