Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Crossword Table Maker

by Adam (Vicar)
on Aug 24, 2000 at 23:58 UTC ( #29533=sourcecode: print w/ replies, xml ) Need Help??

Category:
Author/Contact Info Adam
Description: I wrote this script to generate an html table of a crossword puzzle for KM. I figure that someone else might need to make a crossword puzzle into a table, so here it is.
#!perl -w
use strict;
# I wrote this to generate a file, not be a cgi script, but you could.
+..
# use CGI.pm; 

open GRID, '>grid.html' or die $!;
select GRID;

print "<HTML><BODY>\n"; 

my $cellwidth = '20';  # pixel or percent
my $cellheight = '4'; # pixels only
my $counter = 0;

sub Solid 
{ 
    return "<TD WIDTH='$cellwidth' HEIGHT='$cellheight' ".
           "BGCOLOR='BLACK'>&nbsp;</TD>\n";
}

sub Open
{
    return "<TD WIDTH='$cellwidth' HEIGHT='$cellheight' ".
           "BGCOLOR='WHITE'>&nbsp;</TD>\n";
}

sub Numbered
{
    ++$counter;
    return "<TD WIDTH='$cellwidth' HEIGHT='$cellheight' BGCOLOR='WHITE
+'".
           "ALIGN='LEFT' VALIGN='TOP'><FONT SIZE=-2>$counter</FONT></T
+D>\n";
}

# These two arrays are used to generate the grid.
# numbers in @line correspond to the functions in @type.
# 0 black box, 1, white box, 2, numbered box.
my @type = ( \&Solid, \&Open, \&Numbered );
my @line = ( 
'020000002000002000000000000',
'010200201021111110000020000',
'010100101000001002111110000',
'010102111121111111000010020',
'010100000010001001000202010',
'211121111110001021111101010',
'100010000010001001000101010',
'100010212111001002111111110',
'100010001010000001000101010',
'100010001000021111120001010',
'102111001000000000010001010',
'101010211000000000010200200',
'101010001000000000211111111',
'101010000000211111010100100',
'102211111111100000000100100',
'100100000000102020000100100',
'000100000000101010000100100',
'002111000211111111100000000',
'000000000000101000000000000',
'000000211111111000000000000',
);

print "<TABLE BORDER=1 SHADE=0>\n";
foreach ( @line )
{
    print "<TR>\n";
    print map { &{$type[$_]} } split //;
    print "</TR>";
}
print "\n</TABLE>\n\n";

Comment on Crossword Table Maker
Download Code
RE: Crossword Table Maker
by vroom (Pope) on Aug 25, 2000 at 00:27 UTC
      Pretty cool. I'd be willing to take a crack at merging the two if I hade nate's source.

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://29533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-25 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls