﹝學習記錄﹞- Perl – 畫圓

✎✎✎✎✎✎✎✎✎✎✎✎

◯ 畫圓 ◯●●○

 

弧度 = (π/180) x 角度

 

三角函數概念:

X長度 = r*cos ( 弧度 )

Y長度 = r*sin ( 弧度 )

 

CTXT, CLIB, CINC…

#!/usr/bin/perl -w

use strict;

 

##Generate ctxt file -----------------------------------------------------

my $stru_top='TOP';

my $stru_cellA='CELL_A';

my $in_point='0,0';

my $laye='1';

 

print "Please enter the divided sides: ";

chomp(my $num=<>);

print "Please enter the radius: ";

chomp(my $r=<>);

print "Please enter the number of column: ";

chomp(my $col=<>);

print "Please enter the pitch of column: ";

chomp(my $col_pitch=<>);

print "Please enter the number of row: ";

chomp(my $row=<>);

print "Please enter the pitch of row: ";

chomp(my $row_pitch=<>);

 

my $txtfile="./circle_A.ctxt";

open(F_CA, ">$txtfile") or die "Can't write to $txtfile: error $!\n";

print F_CA 'TEXTLIB 9.0.0',"\n";

print F_CA 'BEGLIB',"\n";

print F_CA '!',"\n";

print F_CA "STRUCT $stru_top\n";

print F_CA "AREF $stru_cellA \($in_point\) $col\($col_pitch,0\) $row\(0,$row_pitch\)\n";

print F_CA 'ENDSTRUCT',"\n";

print F_CA '!',"\n";

print F_CA "STRUCT $stru_cellA\n";

print F_CA "LAYER $laye\n";

print F_CA "B ";

  for(my $i=1;$i<=$num;$i++){

    my $arc=(3.1415/180)*(360/$num)*$i;

    my $x=sprintf("%.3f", $r*cos($arc));  #X方向座標

    my $y=sprintf("%.3f", $r*sin($arc));  #Y方向座標

    print F_CA "$x,$y ";

  }

print F_CA " ENDB\n";

print F_CA 'ENDSTRUCT',"\n";

print F_CA '!',"\n";

print F_CA 'ENDLIB',"\n";

close(F_CA);

print "output $txtfile\n";

##Generate ctxt file <END>--------------------------------------------------

 

##Generate csh file -----------------------------------------------------------

my $cshfile="./circle_A.csh";

my $clibfile="./circle_A.clib";

open (F_CSH, ">$cshfile") or die "Cannot write to $cshfile: $!\n";

print F_CSH '#!/bin/csh/ -f',"\n";

print F_CSH "textlib << TL_!\n";

print F_CSH "$txtfile\n";

print F_CSH "$clibfile\n";

print F_CSH 'TL_!',"\n";

close(F_CSH);

print "generate $cshfile\n";

##Generate csh file <END>---------------------------------------------------

`csh $cshfile`;   #鍵盤左方的 `

print "convert to $clibfile\n";

 

##Open cinc file by cats-------------------------------------------------------

my $cincfile="./circle_A.cinc";

open (F_CINC, "> $cincfile") or die "Cannot write to $cincfile: $!\n";

print F_CINC "Allocate_rects 1000000\n";

print F_CINC "Allocate_traps 1000000\n";

print F_CINC "Allocate_space 300000000\n";

print F_CINC "Format FLAT\n";

print F_CINC "Compact REDO\n";

print F_CINC "Join NO\n";

print F_CINC "Rule EXTEND\n";

print F_CINC "Border OUTSIDE\n";

print F_CINC "Resolution 0.01\n";

print F_CINC "Input $clibfile\n";

print F_CINC "Structure $stru_top\n";

print F_CINC "Layers $laye\n";

print F_CINC "ext\n";

 

print F_CINC "\nset view primary enable\n";

print F_CINC "set solid_fill primary on\n";

print F_CINC "set color primary file\n";

print F_CINC "set draw_mode primary input\n";

print F_CINC "set view_bound primary off\n";

print F_CINC "draw\n";

close(F_CINC);

print "include $cincfile\n";

system('xterm','-geometry','110x25','-e','cats',$cincfile);

##Open cinc file by cats <END>----------------------------------------------

 

 

, , , , , , ,

yunyun 發表在 痞客邦 PIXNET 留言(0) 人氣()