For some reason, I got the 8-ball bug.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::JPEG;
my $width = 300;
my $height = 300;
my $mw = MainWindow->new( -background => 'lightgreen' );
$mw->geometry( $width . 'x' . $height . '+40+40' );
#get answers
my $count = 0;
my %ans;
while(<DATA>){
my (@linedata) = split /\|/, $_;
$ans{$count} = join "\n", @linedata;
$count++;
}
$mw->fontCreate('medium',
-family=>'courier',
-weight=>'bold',
-size=>int(-14*14/10));
my $eightim = $mw->Photo(-data => get_img() );
my $canv = $mw->Canvas(
-width => $width,
-height => $height,
-background => 'lightgreen',
)->pack(-expand=>1, -fill=>'both');
my $ball = $canv->createOval( 0, 0, $width, $height,
-fill => 'black',
-tags => ['ball'],
);
my $hole = $canv->createOval(
$width * .25,( $height * .25 ) - 30,
$width * .75,( $height * .75 ) - 30,
-fill => '#7f7f7f',
-tags => ['hole'],
);
my $eight = $canv->createImage( ($width * .5), ($height * .5) - 20,
-image => $eightim,
-anchor => 's',
-tags => ['8im'],
);
my $text = $canv->createText( $width * .5, $height * .5 ,
-text => '',
-font => 'medium',
-fill => 'white',
-anchor => 's',
-tags => ['text'],
);
my $qtext = $canv->createText( $width/2, $height - 40 ,
-text => 'Click to ask',
-font => 'medium',
-fill => 'yellow',
-anchor => 's',
);
$mw->bind ('<Button 1>', \&conjure);
$canv->lower( 'text','hole');
MainLoop;
############################################
sub conjure{
$canv->lower('8im','hole');
$canv->raise('text','hole');
my $tempcount = int rand($count);
my $timer;
my $hexval = 0x7f7f7f; #background of hole
$timer = $mw->repeat(10,
sub{
$hexval += 0xffff;
if($hexval >= 0xffffff ) {
$hexval = 0xffffff;
$timer->cancel;
}
my $hcval = sprintf("%.2x" , $hexval );
my $color = '#';
$color .= $hcval;
$canv->itemconfigure($text,
-fill => $color,
-text => $ans{$tempcount},
);
$tempcount++;
if($tempcount == $count){$tempcount = 0 }
});
}
#########################################3
######################################################################
+#3
sub get_img{
my $ima8=
'/9j/4AAQSkZJRgABAQEASABIA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ag3aJQ0nX
+cctgby
re2V4+O+4M+wFNvTlutWgdFhiTLQhiOlTsh9fDfWeZ8/AD0FV413f16m1RLuxSUNuKCWUH
+9lCRhP
U4yfM0HCooooM20LccDTaCtajupSBkqJ4AY8c/Cnnsx2Zy7Spu6XS6zIkpaQTGiulGE88O
+KH4ufI
YA8/CG7AbQ1cNaKlPpC0QI5eQCM/eEhKT0BJ9QKZG3S/SbLpBLMNwtyJ73cFY4FKACVY+Q
+6mg6F+
2j6RsslcR+5d++g7q246C4U+RVyz5ZzWm0bUNHXB9LH6xXEWrl+kNFCffiB1IqtIGBgE4H
+Lj9cfP
jR68c8+FBYXaTs7XqhJnQbzJVIA3248hzfjq8k8PsE/HjSBnxJUGa9DmsrZksq3HELHFJH
+11507u
zxfpc61zLJKeLgg7q2Co5IQrI3fQEf3egri9o+0tMXS23htCUrlIW07jxKMbpPxOFY/lFA
+pKKKKB
o9nGY21qmdEWQlT8TeRnxKVA49iT0qYdoW2PzdJR5sdtSzCkguADOEKGCffd96R2nLvKsN
+7jXaGr
D0Ze+ATgLGMFJ8iOHWrN6U1NZNW2kqiuNLUpG7IiO43kZGCFJPNPyNBVTIxzHvR4cOfhT/
+v2xuwT
ZKn7dNk2zfOS2kBbY9ASCB1rTaditljvpduN0lzkpIPdpQGkn15n5ig8HZutbzbNzvDiFJ
+ZeKGGC
R+LGSr/n51h2lZbfd2WCD95l15Q+A+yB/umTdLnYNH2NK5TkeBEYQUsspwCfyoT4n/01Wz
+XOo5Oq
NRP3WQC2lQDbLROe7bGcD5k+pNBwqKKKA5ZPlW6JIkRXUvxH3Y7qRlK2llJHoQRiiigk8H
+aTrWI2
ENX15aR/GbQ6f6lJJ+dZydpmt5SVNqvi0Jxx7thtJ9wkEUUUEXnzptxfMmdLkSXVcCt5wr
+V7k15/
8UUUBRRRQf/Z';
return $ima8;
}
######################################################################
+######
__DATA__
Signs|point|to yes
Yes
Reply hazy|try again
Without|a doubt
My sources|say no
As I |see it| yes
You may| rely on it
Concentrate| and ask again
Outlook| not| so good
It is| decidedly| so
Better not| tell you| now
Yes
Very| doubtful
Yes | definitely
It is| certain
Cannot| predict| now
Most| likely
Ask| again| later
My reply| is no
Outlook| good
Don't| count| on it
Yes| in due| time
My sources |say no
Definitely| not
Yes
You will| have| to wait
I have| my| doubts
Outlook| so so
Looks |good| to me
Yes
Who knows
Looking| good
Probably
Are you| kidding
Go for it
Don't bet| on it
Forget| about it
Try Ketchup
Quantum|Field|Interference
I Know| but| can't tell
Ask again|at| Midnight
In reply to Tk 8-ball
by zentara
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.