Drawing of Flash as Curve

Source: Internet
Author: User
Tags relative

There are two ways to draw a curve : One is a curve drawn by innumerable or finite numbers, namely:lineTo .

The other one is computed by function and calculated by the curve function Curveto .

The emphasis is on the 2nd, simplest curve-drawing code:

This.linestyle (1);
This.moveto (50,50);
This.curveto (100,100,200,100);

The above three lines of code directly into an empty flash inside, the generation can see a curve, this is how to make it?

But we usually use such as painting a beautiful curve is a lot of symmetry and is very smooth, this as can do? The answer is yes. Now we are going to focus on the following issues: curves, symmetry, smoothing.

Curve:
It's clear enough, but why do you want to talk about it? The main use of as to control the curve must be based on the principle of the curve to segment the curve, so that the corresponding node. As shown above, the curve you see is split with the image below, perhaps drawing with the pen [the tool inside the drawing software] is the same line, but this is what you draw with AS. The curve above is a curve consisting of two points, the following are two curves consisting of three dots, which can be used to further study the construction of the as curve [but there are exceptions, even if a smooth single curve can be composed of more than one curve segment, but this does not make much sense]. [A ray can be made with two points of the curve, which is the position of the point that controls the curve in the Flash function]***

Smooth:



What is smoothing? The transition between the curve and the curve represents smoothness, such as circles, ellipses, and so on, smoothing can make the effect look very comfortable. The smoothest way is this, the simplest 3-point ABC, when the curve of AB is fixed, the C curve can be arbitrary but the C curve is subject to certain limitations because of the smoothness, that is, the control point of the front curve and the control point of the curve of B and BC are to be on a straight line, as shown below:



P2 can be moved on the extension lines of P1 and B, but cannot be moved to the left of B, otherwise the curve will not be smooth.

Symmetric:
For example, a circle, to do with as to draw, is very difficult, the most simple code mentioned above, if you use manual attempt to test again and again, like Edison repeatedly failure, can not achieve the desired effect, before this question should look at the example chart:



We will find that when the curve is symmetrical, the control point of the curve is also on the Street of the two-point line, so let's discuss how to get any points on the lines that are obtained with the midpoint perpendicular to the line.

Any point on the Street:
For geometry, you can easily get the answer to this question but let's think about it, it's obviously a bit difficult to get a segment of any angle from as. After all, programming, there is nothing difficult to pour everyone's, we look for materials. Found in the!flash8 inside a class point, in fact, this class is very simple, if you just to the point class and generate Flash8 files, it is too wasteful, because this class can write their own, I put it in the bottom up to help you use [ This class I combined the vect2d and point two methods summed up together, we do not think the code more AH hehe]. The midpoint of the method is Point.verticalpoint (point 1, point 2, and the distance from the midpoint [can be positive/negative]). The principle of this function I do not know is not the most convenient. In this way to tell everyone, take any two point AB, get the point O, copy ab point to a ' B ' point and let this clone dot [clone method], rotate at the original point [i.e. a ' relative to B rotation, B ' relative to a point rotation], and get this new two point, further to the midpoint o ' of the two new points, as shown in figure:



It is easy to take a relative O-fixed point on Oo '. It is easy to solve the problem of symmetry curve by going back to the problem. The curve is really a wonderful thing, Com_zszen is my custom class package [Pakage fits Flash7 version], which includes a math class and a point class, you can study my code to achieve the purpose of learning.

And the one thing I forgot to mention:
On the drawing of closed and non-closed smooth transition curves, obviously you can't do it by looking for something, or you can't do it, that is, give you more than two points, and their curve control points are arbitrary, which means that your first point determines the way you walk the curve. So obviously we can't get the curve we want. So I think it should be considered from the control point of the curve, that is to say, if the control points of the curve are known, then OK.
My method is to create an equation to P1=curvex (TARGET,P1,P2,P3), will be traced to the new control point, of course, the first run will not be drawn up, that is, running this program there is an efficiency problem, is the n point of the closed curve to run n+1 times, N-point of the closed curve to run N times, instead of the closed start point becomes the curve position can not be drawn, my program for the precise operation of the curve, not enough attention, if the implementation of some effects, it should be possible, [which used the noise of Lenovo ads sound Wave map].

static function Curveplus (Path:movieclip, A1, Control1, Control2, Donodraw:boolean) {
Path.moveto (a1.x, A1.Y);
var C1 = new Point (control1.x, CONTROL1.Y);
var C2 = new Point (control2.x, control2.y);
var m = point.interpolate (c1, c2, 0.5);
if (Donodraw = = True) {
Return (m);
}
Path.curveto (c1.x, C1.y, m.x, M.Y);
Curveto (c2.x, C2.y, a2.x, A2.Y);
Return (m);
}
To be continue ...



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.