Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Some rotations (first JAPH)

by maard (Pilgrim)
on Feb 04, 2005 at 11:51 UTC ( [id://428020]=obfuscated: print w/replies, xml ) Need Help??

The only problem: screen size is constant. I just dont know how to determine terminal size under different OSes. Should I use curses for that?
#!/usr/bin/perl use strict; use Time::HiRes qw(usleep);my @j=split //,'just another perl hacker' ;my $clear =( $^O=~/win/i? 'cls':'clear' );my ($ +w,$h)=(80,23);my ($hw,$hh,$ky) =($w/2,int$h /2,0.5); my $times= +20;my @mix;my $M;my ($ofs,$len ,$hl)=($hh*$w+$hw-@j/2,scalar@j ,@j/2); +my $pi=3.1416;sub mix {for ( 1.. $times){my $f=int rand @j;my $t ;SAME: +$t= int rand @j ;my $r=int abs(($f-$t) /2);goto SAME if $r< +5|| $j[$f]eq $j [$t]||($j[ $f]eq"\040" &&$j[$t]eq" " );unshi +ft @mix,[$f,$t ,$r];@j[$f ,$t]=@j[$t, $f];} 1;} sub fill{$M +=' 'x($w*$h);}sub show (@){system "$clear +";print"$M\n";usleep( 10000)} sub line(@ ){subst +r($M,$ofs,$len)=join '',@j;} sub letter {my($l0,$l1 ,$a,$r,$c)=@_ ;substr +($M ,($hh+int (sin($a) * $r*$ky))*$w +$c+int(cos( $a)*$r) +,1) =$l0;substr($M,($hh-int (sin($a)*$r *$ky))*$w+$c- int(cos +($a )*$r),1)=$l1;} sub pair {my($f,$t,$r)=@_; my @c=(@j[$f, $t]); s +how line fill; $j[$f]=$j[$t ]="\040";my $xc=$hw-$hl+$r+($f <$t?$f: +$t) ;my $da=$pi/6;my $a= $da; while($a<$pi){ line fill and s +how letter(@c,$a ,$r,$xc);$a+= $da;}@j[$t, $f]=@c}sub go {pair(@$_) for@mix;show line fill}
mix and go

Replies are listed 'Best First'.
Re: Some rotations (first JAPH)
by dynamo (Chaplain) on Feb 11, 2005 at 05:41 UTC
    From perlfaq8:

    How do I get the screen size?

    If you have Term::ReadKey module installed from CPAN, you can use it to fetch the width and height in characters and in pixels:

    use Term::ReadKey; ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
    This is more portable than the raw "ioctl", but not as illustrative:
    require 'sys/ioctl.ph'; die "no TIOCGWINSZ " unless defined &TIOCGWINSZ; open(TTY, "+</dev/tty") or die "No tty: $!"; unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) { die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ; } ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize); print "(row,col) = ($row,$col)"; print " (xpixel,ypixel) = ($xpixel,$ypixel)" if $xpixel || $ypixel; print "\n";
    End FAQ Entry
    You can also use Curses.pm, check out the LINES and COLS variables.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://428020]
Approved by Limbic~Region
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found