aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetWeb/logo/Sierpinski.pl
blob: b2970aa1dcb86f777a009d00f3e0ee9ec0363ab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /usr/bin/perl -w

use strict;

sub draw ($$$$);

my $levels = 3;
my $xpos = 0;
my $ypos = 0;
my $size = 100 * 3**$levels;

my $linewidth = 10;
my $linecolour = 32;

# 1=green, 2=blue, 4=red, 5=magenta
my @colours = (4, 2, 1, 5);

my $x1 = $xpos;
my $y1 = $ypos;
my $x2 = $xpos + $size;
my $y2 = $ypos + $size;

print <<EOF;
\#FIG 3.2  Produced for xfig version 3.2.5
Landscape
Center
Inches
Letter  
100.00
Single
-2
1200 2
0 32 \#c0c0c0
2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
	 $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1
EOF

draw 0, $xpos, $ypos, $size;
exit 0;



sub draw ($$$$)
{
    my ($level, $xpos, $ypos, $size) = @_;
    
    # coloured square
    {
        my $x1 = $xpos + $size/3;
        my $y1 = $ypos + $size/3;
        my $x2 = $xpos + 2*$size/3;
        my $y2 = $ypos + 2*$size/3;
        my $c = $colours[$level];
        
        print <<EOF;
2 2 0 1 $c $c 50 -1 20 0.000 0 0 -1 0 0 5
	 $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1
EOF
    }
    
    # horizontal grey line
    {
        my $x1 = $xpos;
        my $y1 = $ypos + $size/2 - $linewidth;
        my $x2 = $xpos + $size;
        my $y2 = $ypos + $size/2 + $linewidth;
        my $linecolour = 32;
        
        print <<EOF;
2 2 0 1 $linecolour $linecolour 100 -1 20 0.000 0 0 -1 0 0 5
	 $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1
EOF
    }
    
    # vertical grey line
    {
        my $x1 = $xpos + $size/2 - $linewidth;
        my $y1 = $ypos;
        my $x2 = $xpos + $size/2 + $linewidth;
        my $y2 = $ypos + $size;
        my $linecolour = 32;
        
        print <<EOF;
2 2 0 1 $linecolour $linecolour 100 -1 20 0.000 0 0 -1 0 0 5
	 $x1 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x1 $y1
EOF
    }
    
    # recur
    if ($level+1 < $levels) {
        for my $i (0, 1, 2) {
            for my $j (0, 1, 2) {
                if (! ($i==1 && $j==1)) {
                    draw $level+1, $xpos+$i*$size/3, $ypos+$j*$size/3, $size/3;
                }
            }
        }
    }
}