缶ラベル形状

また、お遊び外部変形です。 缶にラベルを貼ったような形状に変形させます。 (jw_cad上での色塗りは効率が悪いので、上の画像では結局GIMPで塗っています) 線を粉々に分割してX方向に縮めてY方向に楕円形状に歪ませています。 指定原点位置(#0)によってラベルがどちらに向いているかを調整することが出来ます。

変形することが出来るのは 線分、曲線、円だけです。 楕円は歪みを与えるため1個指定します。 変形前はこんなデータです。2本とも同一データから変形しています。

Beerの文字はSnap_Kin さんの袋文字の外部変形を使わせていただきました。

関数「hack_......」はもともと線をパターンで切断する目的で作成したものです。 ここではただ等距離で切断するために使用しています。切断パターンは無名配列をリファレンス に代入したものを関数の引数として渡します。値を[2,0,2,0]として空白部分の長さをゼロにしているの で連続した状態で分割されます。関数の返値は線分を双方向リストに入れたものですから そのままAddPolyLine(hack.....)とすれば曲線として追加されます


#缶ラベル形状

use strict;

require "Jwcpgh.pl";

my $data=Jwcpgh->new;

my $ellipse=$data->sqEllipse->CurrentObject;
my ($x,$y,$radius,$start,$end,$flattening,$axis_angle,$color,$type,$group,$layer)=$ellipse->Attributes();

my $pattern=[2,0,2,0];
my $step=1;

my @straight=$data->sqStraight->Array;
my @polyline=$data->sqPolyline->Array;
my @circle=$data->sqCircle->Array;

foreach my $polyline(@polyline){
    $polyline->SetAttributes(hack_polyline($polyline,$pattern,$step));
}
foreach my $straight(@straight){
    my $polyline=PolyLine->new(hack_straight($straight,$pattern,$step));
    push @polyline,$polyline;
    $data->sqPolyline->push($polyline);
}

foreach my $circle(@circle){
    my $polyline=PolyLine->new(hack_circle($circle,$pattern,$step));
    push @polyline,$polyline;
    $data->sqPolyline->push($polyline);
}


$data->ClearStraight;
$data->ClearCircle;

foreach my $polyline(@polyline){
    my ($pl,$color,$type,$group,$layer)=$polyline->Attributes();
    my @plStraight=$pl->Array;
    foreach my $plStraight(@plStraight){
        my ($x1,$y1,$x2,$y2)=$plStraight->Attributes();
        my ($xc1,$yc1,$xc2,$yc2);
        $xc1=$radius*sin($x1/$radius);
        $xc2=$radius*sin($x2/$radius);
        $yc1=$y1-$radius*$flattening*cos($x1/$radius);
        $yc2=$y2-$radius*$flattening*cos($x2/$radius);
        $plStraight->SetAttributes($xc1,$yc1,$xc2,$yc2);
    }
}


$data->write;

sub hack_circle{
    my ($circle,$pattern,$step)=@_;
    my $sqStraight=Jw_Objects->new();
    
    my ($xc,$yc,$radius,$color,$type,$group,$layer)=$circle->Attributes();
    my $theta;
    my $pi=atan2(1,1)*4;
    my ($x,$y,$xold,$yold);
    $xold=$radius*cos(0)+$xc;
    $yold=$radius*sin(0)+$yc;
    
    for($theta=5;$theta<=360;$theta+=5){
        $x=$radius*cos($theta*$pi/180)+$xc;
        $y=$radius*sin($theta*$pi/180)+$yc;
        $sqStraight->push(Straight->new($xold,$yold,$x,$y,$color,$type,$group,$layer));
        ($xold,$yold)=($x,$y);
    }
    
    return hack_polyline(PolyLine->new($sqStraight),$pattern,$step);

}



sub hack_straight{
    my ($straight,$pattern,$step)=@_;
        my $sqStraight=Jw_Objects->new();
        my ($lx1,$ly1,$lx2,$ly2,$color,$type,$group,$layer)=$straight->Attributes;
        my @pat;
        foreach my $temp(@{$pattern}){
            push @pat,$step*$temp;
        }

        my $theta=atan2($ly2-$ly1,$lx2-$lx1);
        my $radius=0;
        my ($start,$end);
        my $length=sqrt(($lx2-$lx1)**2+($ly2-$ly1)**2);
        my ($x1,$y1,$x2,$y2)=($lx1,$ly1,0,0);
        while(1){
            ($end,$start)=@pat;
            $radius+=$end;
            $x2=$radius*cos($theta)+$lx1;
            $y2=$radius*sin($theta)+$ly1;
            if($radius>$length){
                $sqStraight->push(Straight->new($x1,$y1,$lx2,$ly2,$color,$type,$group,$layer));
                last;
            }else{
                $sqStraight->push(Straight->new($x1,$y1,$x2,$y2,$color,$type,$group,$layer));
            }
            $radius+=$start;
            $x1=$radius*cos($theta)+$lx1;
            $y1=$radius*sin($theta)+$ly1;
            if($radius>$length){last;}
            push(@pat,shift(@pat));
            push(@pat,shift(@pat));
        }
    return $sqStraight;
}

sub hack_polyline{
    my ($polyline,$pattern,$step)=@_;
    my $sqStraight=Jw_Objects->new();
    my ($pl,$color,$type,$group,$layer)=$polyline->Attributes();
    my @pat;
    foreach my $temp(@{$pattern}){
        push @pat,$step*$temp;
    }

    my @plStraight=$pl->Array;
    my ($end)=@pat;
    push(@pat,shift(@pat));
    my $draw=1;
    foreach my $plStraight(@plStraight){
        my ($lx1,$ly1,$lx2,$ly2,$color,$type,$group,$layer)=$plStraight->Attributes;
        my $theta=atan2($ly2-$ly1,$lx2-$lx1);
        my $radius=0;
        my $length=sqrt(($lx2-$lx1)**2+($ly2-$ly1)**2);
        if($length<$end){
            $end-=$length;
            if($draw>0){$sqStraight->push($plStraight);}
            next;
        }
        my ($x1,$y1,$x2,$y2)=($lx1,$ly1,0,0);
        while(1){
            $radius+=$end;
            $x2=$radius*cos($theta)+$lx1;
            $y2=$radius*sin($theta)+$ly1;
            if($radius>$length){
                if($draw>0){
                    $sqStraight->push(Straight->new($x1,$y1,$lx2,$ly2,$color,$type,$group,$layer));
                }
                $end=$radius-$length;
                last;
            }else{
                if($draw>0){
                    $sqStraight->push(Straight->new($x1,$y1,$x2,$y2,$color,$type,$group,$layer));
                }
                $draw*=-1;
                $x1=$x2;
                $y1=$y2;
                ($end)=@pat;
                push(@pat,shift(@pat));
            }
        }

    }
    return $sqStraight;
}


rem 缶ラベル形状に変形
rem #jww :jww形式 文字フォント名,任意文字サイズ寸法,ブロック基点座標,ブロック名,寸法図形データ書出し
rem #h1 :範囲内データを選択
rem #g1 :全レイヤグループを選択 (g0では書込みレイヤのみ)
rem #hc :選択範囲
rem #0 :基準点の指定

perl ex12-0.pl


ダウンロード

御使用になる前に使用上の注意 をよくお読みください。 この外部変形プログラムとは別にライブラリ本体 Jwcpgh.plが必要になります。 ダウンロードファイルには以下のものが含まれています。

ダウンロードはこちら->ex12.lzh

underline-2.gif

TOP 前ページ 次ページ