Flash / Flex / ActionScript/Graphics/lineStyle
Содержание
- 1 Apply a 3 pixel-thick blue stroke
- 2 Change line style while drawing
- 3 Set Caps style to Round
- 4 Set the line style to 1 pixel-thick, solid green
- 5 Set the line style to 2 pixels thick, 50% transparent green
- 6 The following code sets the line style to 1 pixel-thick, solid black:
- 7 To set the rendering style for corners, we use lineStyle( )"s joints parameter.
- 8 To turn the stroke off completely, set thickness to undefined or call lineStyle( ) with no parameters.
Apply a 3 pixel-thick blue stroke
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var canvas:Shape = new Shape( );
canvas.graphics.lineStyle(3, 0x0000FF); // Apply blue stroke
canvas.graphics.lineTo(25, 35);
addChild(canvas);
}
}
}
Change line style while drawing
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var canvas:Shape = new Shape( );
canvas.graphics.lineStyle(1, 0x000000);
canvas.graphics.lineTo(100, 0);
canvas.graphics.lineStyle(5, 0xFF0000);
canvas.graphics.lineTo(100, 100);
canvas.graphics.lineStyle(10, 0x00FF00);
canvas.graphics.lineTo(0, 100);
canvas.graphics.lineStyle(15, 0x0000FF);
canvas.graphics.lineTo(0, 0);
addChild(canvas);
}
}
}
Set Caps style to Round
package{
import flash.display.Sprite;
import flash.display.*;
public class Main extends Sprite{
public function Main(){
graphics.lineStyle(1, 0xff0000, 1, true, LineScaleMode.NONE, CapsStyle.ROUND, JointStyle.ROUND, 20);
for(var i:int=0;i<100;i++) {
graphics.lineTo(Math.random( ) * 400, Math.random( ) * 400);
}
}
}
}
Set the line style to 1 pixel-thick, solid green
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var canvas:Shape = new Shape( );
canvas.graphics.lineStyle(1, 0x00FF00)
canvas.graphics.lineTo(25, 35);
addChild(canvas);
}
}
}
Set the line style to 2 pixels thick, 50% transparent green
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var canvas:Shape = new Shape( );
canvas.graphics.lineStyle(1, 0x00FF00, 50)
canvas.graphics.lineTo(25, 35);
addChild(canvas);
}
}
}
The following code sets the line style to 1 pixel-thick, solid black:
lineStyle(thickness:Number = 1.0,
color:uint = 0,
alpha:Number = 1.0,
pixelHinting:Boolean = false,
scaleMode:String = "normal",
caps:String = null,
joints:String = null,
miterLimit:Number = 3)
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var canvas:Shape = new Shape( );
canvas.graphics.lineStyle(1)
canvas.graphics.lineTo(25, 35);
addChild(canvas);
}
}
}
To set the rendering style for corners, we use lineStyle( )"s joints parameter.
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var triangle:Shape = new Shape( );
triangle.graphics.lineStyle(20, 0, 1, false, LineScaleMode.NORMAL,
CapsStyle.ROUND, JointStyle.MITER);
triangle.graphics.beginFill(0xFF0000, 1);
triangle.graphics.lineStyle(20);
triangle.graphics.lineTo(125, 125); // Draw a line down and right
triangle.graphics.lineTo(250, 0); // Draw a line up and right
triangle.graphics.lineTo(0, 0); // Draw a line left
triangle.graphics.endFill( );
addChild(triangle);
}
}
}
To turn the stroke off completely, set thickness to undefined or call lineStyle( ) with no parameters.
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var canvas:Shape = new Shape( );
canvas.graphics.lineStyle(undefined); // Turn off lines in canvas
canvas.graphics.lineStyle( ); // Same thing
canvas.graphics.lineTo(25, 35);
addChild(canvas);
}
}
}