Fill the DATA section with the things you want on the bingo card (maybe it's just numbers, in my case it was words). Remember to include at least 16 or you end up in an infinite loop ;-)#!/usr/bin/perl -w use strict; use PDFLib; my @words = <DATA>; chomp @words; warn("got @words\n"); my $cards = shift @ARGV || die "Must supply number of cards\n"; print "Making $cards bingo cards\n"; my $pdf = PDFLib->new( filename => "bingo.pdf", papersize => "a4", creator => "Matt Sergeant", author => "Heather Sergeant", title => "Bingo!", ); foreach my $i (1..$cards) { my %seen; print "Card $i\n"; $pdf->start_page; $pdf->set_font(face => "Helvetica", size => 30, bold => 1); $pdf->print_boxed("Bingo!", mode => "center", x => 0, y => 740, w +=> 595, h => 50); $pdf->rect(x => 100, y => 200, w => 400, h => 400); $pdf->stroke; $pdf->set_font(face => "Helvetica", size => 20, bold => 0); for my $x (1..4) { for my $y (1..4) { my $word; while (1) { my $index = rand(@words); $word = $words[$index]; if (!$seen{$word}) { $seen{$word}++; last; } } $pdf->print_boxed($word, mode => "center", x => (100 + (($ +x - 1) * 100)), y => (160 + (($y - 1) * 100)), w => 100, h => 100); if ($y != 1) { $pdf->move_to( 100, (200 + (($y - 1) * 100)) ); $pdf->line_to( 500, (200 + (($y - 1) * 100)) ); $pdf->stroke; } } if ($x != 1) { $pdf->move_to( (100 + (($x - 1) * 100)), 200 ); $pdf->line_to( (100 + (($x - 1) * 100)), 600 ); $pdf->stroke; } } } $pdf->finish; 1; __DATA__ WORDS HERE
In reply to Re: Bingo Challenge
by Matts
in thread Bingo Challenge
by Matts
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |