aboutsummaryrefslogtreecommitdiff
path: root/Perl/demos/Tk/demos/zinc_lib/triangles.pl
blob: 4bc24c601d699367319b55a3fc8204e3f0a029bd (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
#!/usr/bin/perl
# $Id: triangles.pl 1420 2004-04-30 11:35:18Z lecoanet $
# these simple samples have been developped by C. Mertz mertz@cena.fr and N. Banoun banoun@cena.fr

use vars qw( $VERSION );
($VERSION) = sprintf("%d.%02d", q$Revision: 1420 $ =~ /(\d+)\.(\d+)/);

use Tk;
use Tk::Zinc;
use strict;


my $defaultfont = '-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*';
my $mw = MainWindow->new();
my $zinc = $mw->Zinc(-width => 700, -height => 300,
		     -font => "10x20", # usually fonts are sets in resources
		                       # but for this example it is set in the code!
		     -render => 1,
		     -borderwidth => 3, -relief => 'sunken',
		     )->pack;

# 6 equilateral triangles around a point 
$zinc->add('text', 1,
	     -position => [ 5,10 ],
	     -text => "Triangles item without transparency");

my ($x0,$y0) = (200,150);
my @coords=($x0,$y0);
for my $i (0..6) {
    my $angle =  $i * 6.28/6;
    push @coords, ($x0 + 100 * cos ($angle), $y0 - 100 * sin ($angle) );
}

my $tr1 = $zinc->add('triangles', 1,
		     \@coords,
		     -fan => 1,
		     -colors => ['white', 'yellow', 'magenta', 'blue', 'cyan', 'green', 'red', 'yellow'],
		     -visible => 1,			    
		     );

$zinc->add('text', 1,
	   -position => [ 370, 10 ],
	   -text => "Triangles item with transparency");


# using the clone method to make a copy and then modify the clone'colors
my $tr2 = $zinc->clone($tr1);
$zinc->translate($tr2,300,0);
$zinc->itemconfigure($tr2,
		     -colors => ['white;50', 'yellow;50', 'magenta;50', 'blue;50', 'cyan;50', 'green;50', 'red;50', 'yellow;50'],
		     );



MainLoop;