ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/lsys/fractint2lsys.pl
Revision: 1.1
Committed: Thu Nov 6 14:31:24 2008 UTC (15 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3     #
4     # convert (a subset) of fractint l-systems into
5     # lsys-lsystems
6     #
7     # version 1.0
8     #
9    
10     while (<>) {
11     chomp;
12     my $comment=$1 if s/\s*;+\s*(.*)$//;
13     my $o;
14     s/"/%/g;
15     if (/^\s*(\S+)\s+{\s*$/i) {
16     $lsys=$1;
17     $lsys=~s/[^A-Za-z_]/_/g;
18     $lsys=~s/([_a-z])([A-Z])/$1_@{[lc($2)]}/g;
19     $lsys=~s/__/_/g;
20     $lsys=~s/^_//;
21     $lsys=~s/_$//;
22     $s=$lsys{$lsys};
23     $lsys{$lsys}++;
24     $lsys.=$s;
25     $o="ruleset (";
26     } elsif (/Angle (\d+)/i) {
27     $angle=$1;
28     } elsif (/Axiom (\S+)/i) {
29     $o=" $lsys(n) => attr (delta, 360/$angle) ".mangle($1).", n;";
30     } elsif (/^\s*(\S+)\s*=(.*)$/) {
31     my($f,$g)=($1,$2);
32     $f=~y/a-z/A-Z/;
33     $f=~y/FGDM/FfFfFfFf/;
34     $o=" $f => ".mangle($g).";";
35     } elsif(/^\s*}\s*$/i) {
36     undef $lsys;
37     $o=")";
38     }
39     print $o,($comment ? " // $comment" : ""),"\n";
40     }
41    
42     sub mangle {
43     $_=$_[0];
44     s/([a-zA-Z])([a-z])/$1 $2/g;
45     y/a-z/A-Z/;
46     y/FGDM/FfFfFfFf/;
47     s/\/([0-9.]+)/ +($1) /g;
48     s/\\([0-9.]+)/ -($1) /g;
49     s/\@q\s*i([0-9.]+)/ attr (distance, distance\/0$1^0.5) /ig;
50     s/\@i\s*q([0-9.]+)/ attr (distance, distance\/0$1^0.5) /ig;
51     s/\@q([0-9.]+)/ attr (distance, distance*0$1^0.5) /ig;
52     s/\@i([0-9.]+)/ attr (distance, distance\/0$1) /ig;
53     s/\@([0-9.]+)/ attr (distance, distance*0$1) /ig;
54     s/c([0-9]+)//ig; # ignore all
55     s/<([0-9]+)//g; # kinds of
56     s/>([0-9]+)//g; # colours
57     s/ / /g;
58     s/^ //g;
59     s/ $//g;
60     $_;
61     }
62    
63