DrawCylinder.as
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Point;
public class DrawCylinder extends Sprite
{
public function DrawCylinder()
{
var p1:Point=new Point(10,50);
var w:Number=75;
var h:Number=100;
var endH:Number=30;
var bottomH:Number=endH;
var bottom:Shape=drawBottom(p1.x, p1.y+h-bottomH/2, w, bottomH);
drawSides( p1,w,h);
var topH:Number=endH;
var top:Shape=drawTopEclipse(p1.x,p1.y-topH/2,w,topH);
}
private function drawSides( p1:Point, w:Number, h:Number):Shape {
var shape:Shape=new Shape();
addChild(shape);
var g:Graphics=shape.graphics;
g.lineStyle(1,0xffffff,0);
g.beginFill(0xffffff,1);
g.drawRect(p1.x, p1.y,w,h);
g.endFill();
g.lineStyle(1,0x000000,1);
g.moveTo(p1.x, p1.y);
g.lineTo(p1.x, p1.y+h);
g.moveTo(p1.x+w, p1.y);
g.lineTo(p1.x+w, p1.y+h);
return shape;
}
private function drawTopEclipse(x:Number, y:Number, w:Number, h:Number):Shape {
var shape:Shape=new Shape();
var g:Graphics=shape.graphics;
g.lineStyle(1,0x000000);
addChild(shape);
g.drawEllipse(x,y,w,h);
return shape;
}
private function drawBottom(x:Number, y:Number, w:Number, h:Number):Shape {
var shape:Shape=new Shape();
var g:Graphics=shape.graphics;
addChild(shape);
g.lineStyle(1,0x000000);
g.drawEllipse(x,y,w,h);
/*
g.moveTo(x,y+h/2);
g.curveTo(x,y+h, x+w/2,y+h);
g.curveTo(x+w,y+h, x+w,y+h/2);
*/
return shape;
}
}
}