Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

CGI Colour Palette

by sabkat (Acolyte)
on Aug 08, 2002 at 20:43 UTC ( [id://188735]=perlquestion: print w/replies, xml ) Need Help??

sabkat has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone out there know of a cgi script that will return the RBG colour that a user clicks on? I can generate a HTML table with all the colours and then take a snapshot with GIMP, then use an image map to link on different spots, but this seems quite crude, and not like the work of a perl hacker. Any suggestions?

Replies are listed 'Best First'.
Re: CGI Colour Palette
by dws (Chancellor) on Aug 08, 2002 at 20:59 UTC
    Does anyone out there know of a cgi script that will return the RBG colour that a user clicks on?

    There are basically two approaches to this. They differ by where the mapping is done:

    You can use an image map, and handle the coordinate-to-RGB translation on the server side. This approach gives you a lot of flexibility with our graphics, at the expense of making the coordinate mapping more difficult the fancier you get.

    Alternatively, you do the "translation" on the client side, by doing something like filling a table with colors, and adding a link to each cell that embeds the RGB code in the URL. Such a table is easy to generate from Perl.

      Thanks for the help! I figured that I would have to do somthing like the second option above. The only drwaback here is that the table will size each cell by the text the cell, and will only link on the text and not the cell itself. argh!
      my @hex_numbers_row = ("ff","cc","99","66","33","00"); foreach $block (@hex_numbers_row) { + foreach $col (@hex_numbers_row) { + foreach $row (@hex_numbers_row) { + my $hex_colour = $block.$row.$col; + my $string_to_send = '<a', 'href="/ckoster-cgi/test_colour.pl?', 'action=colour&colour='.$hex_colour.'">'."What goes here?".'</a>'; + + print $q->th({-BGCOLOR=>"#$hex_colour", + -width=>"1"},$string_to_send),"\n"; + } }}
      ;
Re: CGI Colour Palette (Javascript Solution)
by BigLug (Chaplain) on Aug 09, 2002 at 01:42 UTC
    Although this is a JS solution, it could be modified to perl. The reason its in JS is that by sending the full table out (as you'd do with a perl solution), you're outputting a lot more data than is needed.

    I use the following javascript to let people select a color in a form text field. The text field lets them type a color if they know it, or they click a button to choose one:

    function choosecolor(form, name, title) { colorWindow=window.open("about:blank","colorWindow","width=400 +,height=120,resizable=yes") colorlist = new Array('00','33','66','99','CC','FF'); colorWindow.document.write("<table border=0 cellpadding=0 cell +spacing=0>"); colorWindow.document.write("<tr><td colspan=3 align=center><fo +nt face='arial,helvetica,sans' size=3><b>" + title + "</b></td></tr>" +); colorWindow.document.write(" <tr>"); for (var rcolor in colorlist) { colorWindow.document.write(" <td>"); colorWindow.document.write(" <table border=0 ce +llpadding=0 cellspacing=2>"); for (var gcolor in colorlist) { colorWindow.document.write(" <tr>"); for (var bcolor in colorlist) { colorWindow.document.write(" <t +d bgcolor='#" + colorlist[rcolor] + colorlist[bcolor] + colorlist[gco +lor] + "'><a href=\"javascript:window.opener.document." + form + "." ++ name + ".value='#" + colorlist[rcolor] + colorlist[bcolor] + colorl +ist[gcolor] + "'; self.close()\"><img src="./images/clearpixel.gif' w +idth=8 height=8 border=0></a></td>"); } colorWindow.document.write(" </tr>"); } colorWindow.document.write(" </table>"); colorWindow.document.write(" </td>"); } colorWindow.document.write(" </tr>"); colorWindow.document.write("</table></font><form><input type=b +utton value=' Cancel ' onclick='self.close()'></form></center>");
    Which works from a form like this:
    <form name=colorpicker> Enter a color:<input name=color type=text><input type=button value="Pi +ck" onclick="choosecolor('colorpicker', 'color', 'Pick a color for no + reason at all')"> </form>
    Hope this helps ... please forgive the lack of a perl solution, but note the above reasoning for it.
Re: CGI Colour Palette
by Anonymous Monk on Aug 09, 2002 at 09:21 UTC
    fill table with all combinations of basic colors (00,33,66,99,BB,FF), and let javascript do target href for you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://188735]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found