I remembered a pattern a few days ago, so I had an inspiration and recorded the pen. However, when I encountered some problems, I could not draw the plot. I would like to ask my college students, he used C ++ to draw a pie chart. At the beginning, the following figure can be drawn by drawing several circles. However, when we find that there is a problem with the fill color, we have to change our thinking, the original technique was to change the big circle into the slices on both sides. From this, we were inspired to use the slices to draw half the circles. Then the problem of filling images is solved. The key point is to achieve a sector. Draw through API. However, the API provided by as3 does not have a method for creating a sector chart. After a wide range of online data queries, it was easily modified.
The initial idea is to know how to draw a slice: Let's simply write it to achieve the effect of slice.
View plaincopy to clipboardprint?
- Function pie (G: graphics, startangle: Number, endangle: Number, radius: Number, color: uint): void
- {
- G. linestyle (1 );
- G. moveTo (0, 0 );
- G. beginfill (color );
- For (var I: Number = startangle; I <= endangle; I ++)
- {
- VaR angle: Number = I * Math. PI/180;
- VaR pointx: Number = math. Cos (angle) * radius;
- VaR pointy: Number = math. Sin (angle) * radius;
- G. lineto (pointx, pointy );
- }
- G. lineto (0, 0 );
- G. endfill ();
- }
The parameters include graphic objects, start angles, end angles, radius, and color fill values. In this way, we can basically achieve the expected results.
This method achieves the effect of Slice by drawing points.
After implementation, we continue to follow the following pattern to describe the circle. There are 5 circles in total, and the largest circle is completed by two slices. Others are filled by drawing API drawcircl.
When filling the color, the key point is to deal with the color, in order to achieve the Taiji pattern.
Rows graph row class:
Draw based on the above diagram.
View plaincopy to clipboardprint?
- Package
- {
- // Draw Tai Chi
- Import flash. display. Sprite;
- Import flash. Events .*;
- Import flash. display. graphics;
- Import flash. Geom. Point;
- Public class Taiji extends Sprite
- {
- Private var shape: SPRITE = new sprite ();
- Private var contain: SPRITE = new sprite ();
- Private var shape2: SPRITE = new sprite ();
- Private var shape3: SPRITE = new sprite ();
- Private var R: int; // radius
- Private var startx: Number = 0;
- Private var starty: Number = 0;
- Public Function Taiji (r: INT)
- {
- This. r = R;
- Addchild (SHAPE );
- Shape. x = startx;
- Shape. Y = starty;
- Addchild (shape2 );
- Addchild (shape3 );
- Creatsprite ();
- }
- Private function creatsprite (): void
- {
- Pie (shape. Graphics, 90,270, R, 0x000000); // draw the left side of the slice
- Pie (shape. Graphics, 270,450, R, 0 xffffff); // draw the right side of the slice
- Shape2.graphics. beginfill (0 xffffff); // draw the lower circle
- Shape2.graphics. drawcircle (startx, starty + R/2, R/2 );
- Shape2.graphics. endfill ();
- Shape2.graphics. beginfill (0x000000); // draw the Upper circle
- Shape2.graphics. drawcircle (startx, starty-r/2, R/2 );
- Shape2.graphics. endfill ();
- Shape3.graphics. beginfill (0 xffffff );
- Shape3.graphics. drawcircle (startx, starty-r/2, R/4 );
- Shape3.graphics. endfill ();
- Shape3.graphics. beginfill (0x000000 );
- Shape3.graphics. drawcircle (startx, starty + R/2, R/4 );
- Shape3.graphics. endfill ();
- }
- // Draw slices
- Private function pie (G: graphics, startangle: Number, endangle: Number, radius: Number, color: uint): void
- {
- G. linestyle (1 );
- G. moveTo (0, 0 );
- G. beginfill (color );
- For (var I: Number = startangle; I <= endangle; I ++)
- {
- VaR angle: Number = I * Math. PI/180;
- VaR pointx: Number = math. Cos (angle) * radius;
- VaR pointy: Number = math. Sin (angle) * radius;
- G. lineto (pointx, pointy );
- }
- G. lineto (0, 0 );
- G. endfill ();
- }
- }
- }
Test code: Add a luminous filter effect to the code.
View plaincopy to clipboardprint?
- Package
- {
- // Draw Tai Chi
- Import flash. display. movieclip;
- Import flash. Events .*;
- Import flash. display. Bitmap;
- Import flash. display. bitmapdata;
- Import flash. Geom .*;
- Import flash. Filters. glowfilter; // Add a luminous filter.
- Public class main2 extends movieclip
- {
- Private var R: Int = 120;
- Private var contain: movieclip = new movieclip ();
- Public Function main2 ()
- {
- Creatsprite ();
- }
- Private function creatsprite (): void
- {
- Addchild (contain );
- VaR sprite: Taiji = new Taiji (r); // create a taiji object
- Contain. addchild (sprite );
- Contain. x = stage. stagewidth/2;
- Contain. Y = stage. stageheight/2;
- VaR glow: glowfilter = new glowfilter (0 xffffff, 0.3, 60, 60, 3); // luminous Filter
- VaR array: array = new array ();
- Array. Push (glow );
- Contain. Filters = array;
- }
- }
- }
To add some effects, we can also add filter effects to the image and import the filter package. Use glowfilter to add a filter light to it
VaR glow: glowfilter = new glowfilter (0 xffffff, 0.3, 60, 60, 3); // luminous Filter
VaR array: array = new array ();
Array. Push (glow );
Contain. Filters = array;
Luminous filter, which can achieve good results.
Similarly, in order to add interesting meanings, we searched online for some pictures of our hands and then made them with two verses, which looked cool.
The second version.