Thread RDW #A - Raetsel der Woche Nummer A (29 answers)
Opened by esskar at 2004-12-15 04:52

Crian
 2004-12-15 17:54
#49984 #49984
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
Ich hab mal ein Programm zum Anzeigen der Rechtecke geschrieben, ich hoffe das gilt nicht als Spoiler:

Code: (dl )
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
#!/usr/bin/perl
use strict;
use warnings;

use Tk;

main();
exit;


sub main {
my $mw = MainWindow->new();
$mw->title('RDW #A - Betrachter');

# Anzeigefeld:
my $cnv = $mw->Canvas(-background => 'white',
-state => 'disabled',
-width => 500,
-height => 500,
-relief => 'flat',
-cursor => 'crosshair',
)
->pack(-side => 'bottom',
-expand => 1,
-fill => 'none',
);

# Eingabefeld und Button:
my $f = $mw->Frame(-relief => 'groove',
-borderwidth => 2,
)
-> pack(-side => 'top',
-expand => 1,
-fill => 'x',
);
my $ent = $f->Entry(-width => 75,
)
->pack (-side => 'left',
-expand => 1,
-fill => 'x',
-anchor => 'w',
);
my $btn = $f->Button(-text => 'Anzeigen',
-command => [ \&show, $mw, $cnv, $ent ],
)
->pack (-side => 'top',
-expand => 1,
-fill => 'x',
);

$mw->bind ('<Return>', sub{$btn->invoke()} );
$mw->bind ('<Escape>', sub{$mw->destroy()} );

$ent->focus();

MainLoop();
}

sub show {
my ($mw, $cnv, $ent) = @_;
$cnv->delete('all'); # canvas leeren
(my $rect = $ent->get()) =~ tr~[] ~~d; # müll wegwerfen
my @koord = split /,/, $rect;
unless (@koord > 3 and @koord % 4 == 0) {
print "\a";
return;
}

# Koordinatentransformation:
my ($smin, $smax) = (15, 490);
my $min;
my $max;
$min = $max = $koord[0];
for (@koord) {
$min = $_ if $_ < $min;
$max = $_ if $_ > $max;
}
my $faktor = ($smax-$smin) / ($max-$min);
$_ = int(($_-$min)*$faktor) + $smin for @koord;

# Rechtecke einzeichnen:
while (@koord) {
my $xmin = shift @koord;
my $ymin = 500 - (shift @koord);
my $xmax = shift @koord;
my $ymax = 500 - (shift @koord);
$cnv->createRectangle($xmin, $ymin, $xmax, $ymax);
}
}
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite

View full thread RDW #A - Raetsel der Woche Nummer A