📄 fsshapeconstructor.java
字号:
x = (COORDINATES_ARE_PIXELS ? x * 20 : x) - currentX;
y = (COORDINATES_ARE_PIXELS ? y * 20 : y) - currentY;
rcurve(x1, y1, x2, y2, x, y);
}
/**
* draw a cubic bezier curve relative to the current point. The first control point
* is the one defined for the previously drawn curve. The second control point is the
* relative point (x2, y2).
*
* If no curve has been drawn previously then a control point midway along the previous line or
* move is used.
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* @param x2 the distance along the x-axis from the current point to the second control point.
* @param y2 the distance along the y-axis from the current point to the second control point.
* @param x the distance along the x-axis from the current point to the end of the curve.
* @param y the distance along the y-axis from the current point to the end of the curve.
*/
public void rreflect(int x2, int y2, int x, int y)
{
int x1 = currentX - controlX;
int y1 = currentY - controlY;
x2 = COORDINATES_ARE_PIXELS ? x2 * 20 : x2;
y2 = COORDINATES_ARE_PIXELS ? y2 * 20 : y2;
x = COORDINATES_ARE_PIXELS ? x * 20 : x;
y = COORDINATES_ARE_PIXELS ? y * 20 : y;
rcurve(x1, y1, x2, y2, x, y);
}
/**
* Creates a closed path in the shape of a rectangle with the specified width and height.
* The centre of the rectangle is located at the point (x,y).
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* The origin of the shape can be used to control the relative placement of the rectangle
* when it is placed on the Flash Player's display list using either the FSPlaceObject or
* FSPlaceObject2 class.
*
* @param x the x-coordinate of the centre of the rectangle.
* @param y the y-coordinate of the centre of the rectangle.
* @param width the width of the rectangle.
* @param height the height of the rectangle.
*/
public void rect(int x, int y, int width, int height)
{
newPath();
selectStyle(0, 0);
move(x-width/2, y-height/2);
rline(width, 0);
rline(0, height);
rline(-width, 0);
rline(0, -height);
closePath();
}
/**
* Creates a closed path in the shape of a rectangle with the specified width and height.
* The centre of the rectangle is located at the point (0,0).
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* @param width the width of the rectangle.
* @param height the height of the rectangle.
*/
public void rect(int width, int height)
{
rect(0, 0, width, height);
}
/**
* Creates a closed path in the shape of a rectangle with rounded corners. The shape is drawn
* with specified width and height and the radius argument specified the radius of the quarter
* circle used to draw the corners.
*
* The centre of the rectangle is located at the point (x,y).
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* The origin of the shape can be used to control the relative placement of the rectangle
* when it is placed on the Flash Player's display list using either the FSPlaceObject or
* FSPlaceObject2 class.
*
* @param x the x-coordinate of the centre of the rectangle.
* @param y the y-coordinate of the centre of the rectangle.
* @param width the width of the rectangle.
* @param height the height of the rectangle.
* @param radius the radius of the quarter circle used to draw the corners.
*/
public void rect(int x, int y, int width, int height, int radius)
{
int shortestSide = (height < width) ? height : width;
if (radius > shortestSide/2)
radius = shortestSide/2;
newPath();
selectStyle(0, 0);
move(x, y-height/2);
rline(width/2-radius, 0);
rcurve(radius, 0, 0, radius);
rline(0, height - 2*radius);
rcurve(0, radius, -radius, 0);
rline(-(width-2*radius), 0);
rcurve(-radius, 0, 0, -radius);
rline(0, -(height-2*radius));
rcurve(0, -radius, radius, 0);
closePath();
}
/**
* Creates a closed path in the shape of a rectangle with rounded corners. The shape is drawn
* with specified width and height and the radius argument specified the radius of the quarter
* circle used to draw the corners. The centre of the rectangle is located at the point (0,0).
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* @param width the width of the rectangle.
* @param height the height of the rectangle.
* @param radius the radius of the quarter circle used to draw the corners.
*/
public void rect(int width, int height, int radius)
{
rect(0, 0, width, height, radius);
}
/**
* Creates a closed path in the shape of an ellipse. The arguments rx and ry specify the radius
* of the ellipse in the x and y directions respectively.
*
* The centre of the ellipse is located at the point (x,y).
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* The origin of the shape can be used to control the relative placement of the ellipse
* when it is placed on the Flash Player's display list using either the FSPlaceObject or
* FSPlaceObject2 class.
*
* @param x the x-coordinate of the centre of the ellipse.
* @param y the y-coordinate of the centre of the ellipse.
* @param rx the radius of the ellipse in the x direction.
* @param ry the radius of the ellipse in the y direction.
*/
public void ellipse(int x, int y, int rx, int ry)
{
int startX = (int) (0.707 * rx) + x;
int startY = (int) (0.707 * ry) + y;
int ax = (int) (0.293 * rx);
int ay = (int) (0.293 * ry);
int cx = (int) (0.414 * rx);
int cy = (int) (0.414 * ry);
newPath();
selectStyle(0, 0);
move(startX, startY);
rcurve(-ax, ay, -cx, 0);
rcurve(-cx, 0, -ax, -ay);
rcurve(-ax, -ay, 0, -cy);
rcurve(0, -cy, ax, -ay);
rcurve(ax, -ay, cx, 0);
rcurve(cx, 0, ax, ay);
rcurve(ax, ay, 0, cy);
rcurve(0, cy, -ax, ay);
closePath();
}
/**
* Creates a closed path in the shape of an ellipse. The arguments rx and ry specify the radius
* of the ellipse in the x and y directions respectively.
*
* The centre of the ellipse is located at the point (0,0).
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* @param rx the radius of the ellipse in the x direction.
* @param ry the radius of the ellipse in the y direction.
*/
public void ellipse(int rx, int ry)
{
ellipse(0, 0, rx, ry);
}
/**
* Creates a closed path in the shape of a circle. The centre of the circle is located at
* the point (x,y) with radius r.
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* The origin of the shape can be used to control the relative placement of the circle
* when it is placed on the Flash Player's display list using either the FSPlaceObject or
* FSPlaceObject2 class.
*
* @param x the x-coordinate of the centre of the circle.
* @param y the y-coordinate of the centre of the circle.
* @param r the radius of the circle.
*/
public void circle(int x, int y, int r)
{
ellipse(x, y, r, r);
}
/**
* Creates a closed path in the shape of a circle. The centre of the circle is located at
* the point (0,0) with radius r.
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* @param r the radius of the circle.
*/
public void circle(int r)
{
ellipse(0, 0, r, r);
}
/**
* Create a closed shape with vertices defines by pairs of coordinates from the array argument.
* The first pair of points in the array specifies a move. Line segments a drawn relative to
* the current point which is updated after each segment is drawn.
*
* If the number of points is an odd number then the last point will be ignored.
*
* If the COORDINATES_ARE_PIXELS attribute is true then the coordinates are specified in pixels,
* otherwise the coordinates are specified in twips.
*
* @param points and array of coordinate pairs. The first pair of points defines the coordinates
* of a move operation, successive pairs define the coordinates for relative lines.
*/
public void polygon(int[] points)
{
int i;
int length = points.length;
if (length % 2 == 1)
length -= 1;
rmove(points[0], points[1]);
for (i=2; i<length; i+=2)
rline(points[i], points[i+1]);
closePath();
}
private void setInitial(int x, int y)
{
initialX = x;
initialY = y;
}
private void setCurrent(int x, int y)
{
currentX = x;
currentY = y;
if ((x - lineWidth/2) < minX) minX = x - lineWidth/2;
if ((y - lineWidth/2) < minY) minY = y - lineWidth/2;
if ((x + lineWidth/2) > maxX) maxX = x + lineWidth/2;
if ((y + lineWidth/2) > maxY) maxY = y + lineWidth/2;
}
private void setControl(int x, int y)
{
controlX = x;
controlY = y;
if ((x - lineWidth/2) < minX) minX = x - lineWidth/2;
if ((y - lineWidth/2) < minY) minY = y - lineWidth/2;
if ((x + lineWidth/2) > maxX) maxX = x + lineWidth/2;
if ((y + lineWidth/2) > maxY) maxY = y + lineWidth/2;
}
private void setBounds(int xl, int yl, int xu, int yu)
{
minX = xl;
minY = yl;
maxX = xu;
maxY = yu;
}
private void flatten()
{
double[] Qx = new double[] {0.0, 0.0, 0.0, 0.0};
double[] Qy = new double[] {0.0, 0.0, 0.0, 0.0};
double u;
double Ax, Ay, Bx, By;
for (;;)
{
Ax = 2.0 * Px[0] + Px[3] - 3.0 * Px[1]; Ax *= Ax;
Bx = 2.0 * Px[3] + Px[0] - 3.0 * Px[2]; Bx *= Bx;
if (Ax < Bx) Ax = Bx;
Ay = 2.0 * Py[0] + Py[3] - 3.0 * Py[1]; Ay *= Ay;
By = 2.0 * Py[3] + Py[0] - 3.0 * Py[2]; By*= By;
if (Ay < By) Ay = By;
if ((Ax + Ay) < flattenLimit)
{
objects.add(new FSLine((int)(Px[3])-currentX, (int)(Py[3])-currentY));
setControl((int)(Px[1]), (int)(Py[1]));
setControl((int)(Px[2]), (int)(Py[2]));
setCurrent((int)(Px[3]), (int)(Py[3]));
break;
}
else
{
Qx[3] = Px[3];
u = (Px[1] + Px[2]) / 2;
Px[1] = (Px[0] + Px[1]) / 2;
Qx[2] = (Px[2] + Px[3]) / 2;
Px[2] = (Px[1] + u) / 2;
Qx[1] = (u + Qx[2]) / 2;
Px[3] = Qx[0] = (Px[2] + Qx[1]) / 2;
Qy[3] = Py[3];
u = (Py[1] + Py[2]) / 2;
Py[1] = (Py[0] + Py[1]) / 2;
Qy[2] = (Py[2] + Py[3]) / 2;
Py[2] = (Py[1] + u) / 2;
Qy[1] = (u + Qy[2]) / 2;
Py[3] = Qy[0] = (Py[2] + Qy[1]) / 2;
flatten();
Px[0] = Qx[0];
Py[0] = Qy[0];
Px[1] = Qx[1];
Py[1] = Qy[1];
Px[2] = Qx[2];
Py[2] = Qy[2];
Px[3] = Qx[3];
Py[3] = Qy[3];
continue;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -