/*======================================================================*//**
* com.emzah.display.Shape Class for ActionScript 2.0
*
* @author Copyright (c) 2007 gen:emzah.com
* @version 0.1
*
* @link http://emzah.com
* @link http://blog.emzah.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*//*=======================================================================*/
/**
* Shape はプリミティブな図形を描くためのクラスです
* @data 2007/05/21
* @usage
*
* GenShape.box(mc,xp,yp,wp,hp,lp,lcp,pc);
*
*/
class com.emzah.display.Shape {
/**
* ラインを描く
*
* mc 描画するMovieClip
* x1 開始点X値
* y1 開始点Y値
* x2 終止点X値
* y2 終止点Y値
* line[1] 線幅
* line[0] 線色「0xFFFFFF」
*/
public static function line(mc :MovieClip,
x1 :Number,
y1 :Number,
x2 :Number,
y2 :Number,
line:Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
mc.beginFill();
mc.moveTo(x1, y1);
mc.lineTo(x2, y2);
mc.lineTo(x1, y1);
mc.endFill();
}
/**
* 四角のボックスを描く
*
* mc 描画するMovieClip
* x1 四角の左上のX値
* y1 四角の左上のY値
* width 横幅
* hight 高さ
* line 線色「0xFFFFFF」,線幅「1] :Array
* base 塗りつぶす色,アルファ :Array
* 単色 (color,alpha)
* グラデ色 (color,alpha)
*/
public static function box(mc:MovieClip,
x1 :Number,
y1 :Number,
width :Number,
hight :Number,
line :Array,
base :Array) : Void {
if(line[1] == undefined){line[1] = 1 }
if(line[0] == undefined){line[0] = 0x000000;}
if (line[0] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
//beginFill(色, アルファ);
//beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
if(base[0] == undefined || base[0] == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
mc.moveTo(x1, y1);
mc.lineTo(x1 + width, y1);
mc.lineTo(x1 + width, y1 + hight);
mc.lineTo(x1, y1 + hight);
mc.lineTo(x1, y1);
mc.endFill();
}
/**
* 放射状(イチョウ型)の図形を描く
*
* ※角度はXの正の数軸が0度でしたに向かって+です。
*
* mc 描画するMovieClip
* nX 円の中心点X
* nY 円の中心点Y
* nR 半径
* nStD 開始角度(度数)
* nInD 扇角度(度数)
* line[1] 線幅
* line[0] 線色「0xFFFFFF」
* base 塗りつぶす色
* 単色 (color,alpha)
* グラデ色 (color,alpha)
*/
public static function ginkgoCircle(mc:MovieClip,
nX:Number,
nY:Number,
nR:Number,
nStD :Number,
nInD :Number,
line :Array,
base :Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
//beginFill(色, アルファ);
//beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
if(base == undefined || base == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
/*
*segmentDegrees 曲線の精度のための区切りの角度(省略時:45度)
* ただし曲線の精度のため45度以上は円の弧がきれいにならない
* curveTo の仕様のため計算では非常に難しいようである。
*/
var segmentDegrees :Number = 45;
if(nInD <= segmentDegrees){
var pointlist :Array
= __ginkgoCircleBitPoint(nX,nY,nR,nStD,nInD);
mc.moveTo(pointlist[0], pointlist[1]);
mc.lineTo(pointlist[2], pointlist[3]);
mc.curveTo(pointlist[6], pointlist[7],
pointlist[4], pointlist[5]);
mc.lineTo(pointlist[0], pointlist[1]);
}else{
var segme :Number = Math.floor(nInD / segmentDegrees);
var amari :Number = nInD % segmentDegrees;
if(amari != 0){
var pointlist :Array
= __ginkgoCircleBitPoint(nX,nY,nR,nStD,amari);
mc.moveTo(pointlist[0], pointlist[1]);
mc.lineTo(pointlist[2], pointlist[3]);
mc.curveTo(pointlist[6], pointlist[7],
pointlist[4], pointlist[5]);
};
var deg = amari;
for(var i=0;i 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
//補正
if(round == undefined || isNaN(round) == true){
round = 0;
}
if(0 > (width - round) || 0 > (hight - round) ){
round = 0;
}
if(width > 0){
mc.moveTo(x1 + round, y1);//1
mc.lineTo(x1 + width - round, y1);//2
mc.lineTo(x1 + width, y1 + round);//3
mc.lineTo(x1 + width, y1 + hight - round);//4
mc.lineTo(x1 + width - round, y1 + hight);//5
mc.lineTo(x1 + round, y1 + hight);//6
mc.lineTo(x1 , y1 + hight - round);//7
mc.lineTo(x1 , y1 + round);//8
mc.lineTo(x1 + round, y1);//9
mc.endFill();
}else{
mc.moveTo(x1, y1);
mc.lineTo(x1 + 1, y1);
mc.lineTo(x1 + 1, y1 + hight);
mc.lineTo(x1, y1 + hight);
mc.lineTo(x1, y1);
mc.endFill();
}
}
/**
* 正角丸の図形(角の縦横サイズが同じ)
* target_mc
*
* まだ途中
*
* mc 描画するMovieClip
* x1 四角の左上のX値
* y1 四角の左上のY値
* width 横幅
* hight 高さ
* round 角 右回り[1,2,3,4]
* line[1] 線幅
* line[0] 線色「0xFFFFFF」
* base 塗りつぶす色
* 単色 (color,alpha)
* グラデ色 (color,alpha)
*/
public static function roundbox(mc:MovieClip,
x1:Number,
y1:Number,
width:Number,
hight:Number,
round:Array,
line:Array,
base:Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
//beginFill(色, アルファ);
//beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
if(base == undefined || base == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
//補正
if(round == undefined || round.length < 0 ){
var round:Array = [0,0,0,0];
}
if(0 > (width - round[0]) || 0 > (hight - round[0]) ){
var round:Array = [0,0,0,0];
}
if(width > 0){
if(width - (round[2]*2) < 0){
round[2] = width;
}
mc.moveTo(x1 + round[0], y1);//1
mc.lineTo(x1 + width - round[2], y1);//2
mc.curveTo(x1 + width , y1 ,x1 + width ,y1 + round[3]);
mc.lineTo(x1 + width, y1 + round[3] );//3
mc.lineTo(x1 + width, y1 + hight - round[3] );//4
mc.curveTo(x1 + width , y1 + hight, x1 + width - round[2] , y1 + hight);
mc.lineTo(x1 + width - round[2], y1 + hight);//5
mc.lineTo(x1 + round[0], y1 + hight );//6
mc.curveTo(x1, y1+ hight, x1,y1+hight- round[1]);
mc.lineTo(x1 , y1 + hight - round[1]); //7
mc.lineTo(x1 , y1 + round[1]); //8
mc.curveTo(x1, y1, x1 + round[0],y1);
mc.lineTo(x1 + round[0], y1);//9
mc.endFill();
}else{
mc.moveTo(x1, y1);
mc.lineTo(x1 + 1, y1);
mc.lineTo(x1 + 1, y1 + hight);
mc.lineTo(x1, y1 + hight);
mc.lineTo(x1, y1);
mc.endFill();
}
}
}