#!/usr/bin/perl # Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. use strict; use warnings; =pod =head1 NAME double-helix - output two lines of text, entwined as a double helix =head1 SYNOPSIS Set $config_name in this script. Run double-helix. Maybe use the command suggested in config_as($config_name). View output in browser. =head1 CAVEATS IE cannot handle the CSS z-index rule, without which the helix is imperfect. As a workaround, take images from Firefox, and use those instead. (Use the same 'backgound-color' as suggested config_as($config_name).) This too is imperfect, if the ultimate page background differs much. =cut my $config_name = 'logo-light'; sub char_span( $$ ); # $line, $c sub config_as( $ ); # $name my $amplitude = 0.5; # In 'em' units. 0.5 is roughly the limit of the layout box; so add margins/pads for anything greater. my $angular_velocity = 1; # radians per character my @hue; # 0..360, for each line my @line; # two lines of text my @luminosity_amplitude; my @luminosity_mean; my @luminosity_min; my @luminosity_max; # 0..1, at back/front of curve, for each line my @phase_shift; # in radians, for each line my $PI = atan2(1,1) * 4; # approx. my @saturation; # 0..1, for each line { config_as( $config_name ); my $cN = length $line[0]; print "
"; for( my $c = 0; $c < $cN; ++$c ) { print char_span( 0, $c ); } print "
\n"; print "
"; for( my $c = 0; $c < $cN; ++$c ) { print char_span( 1, $c ); } print "
\n"; } sub char_span( $$ ) { use Graphics::ColorUtils qw( hls2rgb hsv2rgb ); use POSIX qw( floor ); my $line = shift; my $c = shift; my $angular_distance = $angular_velocity * $c + $phase_shift[$line]; # OK, but angle is easier in comparison tests # my $angle = $angular_distance % (2 * $PI ); ## remainder not defined for floats (apparently truncates to int) so: my $angle = $angular_distance - floor($angular_distance / 2 / $PI) * 2 * $PI; my $luminosity = $luminosity_mean[$line] + $luminosity_amplitude[$line] * sin( $angle + $PI/2); # my $color = hsv2rgb( $hue[$line], $saturation[$line], $luminosity ); ### bug, purely saturated at max brightness is white, so no choice but HLS my $color = hls2rgb( $hue[$line], $luminosity, $saturation[$line] ); my $y = $amplitude * sin( $angle ); my $z; if( $angle > $PI/2 && $angle <= 3*$PI/2 ) { $z = 0; } # behind (redundant if parent bounding box, itself, specifies a z-index) else { $z = 1; } # in front my $char = substr( $line[$line], $c, 1 ); $char eq ' ' and $char = ' '; return "$char"; } sub config_as( $ ) { my $name = shift; if( $name eq 'DNA-to-binary' ) # (f=~/_/scratch.html; echo '


' > $f; ~/project/textbender/_/double-helix >> $f; echo '' >> $f; ) { config_as( 'logo-dark' ); $line[0] = ' GTGAGTGCAACTGGAC recombinant text 1011010001101101001101'; $line[1] = 'TCACTCACGTTGACCTGA recombinant text 1011011010011101101 '; $amplitude = 0.95; $angular_velocity = 0.465; @hue = ( 30 , 210 ); @luminosity_min = ( 0.40 , 0.50 ); @luminosity_max = ( 0.57 , 0.65 ); @saturation = ( 0.2 , 0.0 ); } elsif( $name eq 'logo-dark' ) # (f=~/_/scratch.html; echo '


' > $f; ~/project/textbender/_/double-helix >> $f; echo '' >> $f; ) { # or logo-dark-large # (f=~/_/scratch.html; echo '


' > $f; ~/project/textbender/_/double-helix >> $f; echo '' >> $f; ) # $line[0] = 'textbendertextbendertext'; # $line[1] = 'rtextbendertextbendertex'; $line[0] = 'textbender '; $line[1] = ' textbender'; $amplitude = 0.65; $angular_velocity = 0.65; @hue = ( 5 , 185 ); @luminosity_min = ( 0.40 , 0.54 ); @luminosity_max = ( 0.60 , 0.70 ); @saturation = ( 0.5 , 0.0 ); my $phase_shift = 3*$PI/2 - 0.3; @phase_shift = ( $phase_shift, $phase_shift + $PI ); } elsif( $name eq 'logo-light' ) # (f=~/_/scratch.html; echo '


' > $f; ~/project/textbender/_/double-helix >> $f; echo '' >> $f; ) { # or logo-light-large # (f=~/_/scratch.html; echo '


' > $f; ~/project/textbender/_/double-helix >> $f; echo '' >> $f; ) config_as( 'logo-dark' ); $amplitude = 0.75; @luminosity_min = ( 0.8 , 0.8 ); @luminosity_max = ( 0.58 , 0.6 ); @saturation = ( 0.6 , 0.0 ); } elsif( $name eq 'test' ) # (f=~/_/scratch.html; echo '


' > $f; ~/project/textbender/_/double-helix >> $f; echo '' >> $f; ) { $line[0] = 'OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO'; $line[1] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; @hue = ( 120 , 300 ); @luminosity_min = ( 0.4 , 0.5 ); @luminosity_max = ( 0.60, 0.75 ); @saturation = ( 1.0 , 1.0 ); @phase_shift = ( 0 , $PI ); } else { die "unrecognized config name: '$name'\n"; } $luminosity_amplitude[0] = $luminosity_max[0] - $luminosity_min[0]; $luminosity_amplitude[1] = $luminosity_max[1] - $luminosity_min[1]; $luminosity_mean[0] = ($luminosity_min[0] + $luminosity_max[0]) / 2; $luminosity_mean[1] = ($luminosity_min[1] + $luminosity_max[1]) / 2; }