#!/usr/bin/perl -w # generate_starfield.pl - Don Yang (uguu.org) # # Generate edit log to simulate star field motion. This is just to # show that with sufficient effort, Homura can be used to produce # animated HTML that are not limited to text editing sessions. use strict; use constant WIDTH => 132; use constant HEIGHT => 40; use constant FPS => 8; use constant STAR_COUNT => 40; use constant SCALE_X => 1.2; use constant SCALE_Y => 1.2; use constant MAX_Z => 3.0; use constant MIN_Z => 1.0; use constant Z_SPEED => 0.09; # Initialize stars my @stars = (); for(my $i = 0; $i < STAR_COUNT; $i++) { # (x, y, z) push @stars, [rand(1.0) - 0.5, rand(1.0) - 0.5, rand(MAX_Z - MIN_Z) + MIN_Z]; } # Animate stars for(my $frame = 0; $frame <= FPS * 60; $frame++) { my @pixels = (); for(my $i = 0; $i < $#stars; $i++) { # Plot a single star my $x = WIDTH * SCALE_X * $stars[$i][0] / $stars[$i][2]; my $y = HEIGHT * SCALE_Y * $stars[$i][1] / $stars[$i][2]; my $sx = int($x + WIDTH / 2); my $sy = int($y + HEIGHT / 2); if( $sx >= 0 && $sx < WIDTH && $sy >= 0 && $sy < HEIGHT ) { $pixels[$sy][$sx] = (($i & 1) == 0) ? "\xe2\x98\x85" : "\xe2\x98\x86"; } # Output coordinates for debugging. These will be ignored by Homura. print "Point ($stars[$i][0], $stars[$i][1], $stars[$i][2]) ", "-> ($x, $y) -> ($sx, $sy)\n"; # Animate $stars[$i][2] -= Z_SPEED; if( $stars[$i][2] < MIN_Z ) { $stars[$i][0] = rand(1.0) - 0.5; $stars[$i][1] = rand(1.0) - 0.5; $stars[$i][2] += (MAX_Z - MIN_Z); } } # Write frame my $time = int($frame / FPS); print "Y", HEIGHT, "X", WIDTH, "F${frame}T${time}\n"; for(my $y = 0; $y < HEIGHT; $y++) { print "L", $y + 1, "E", HEIGHT, "="; if( defined $pixels[$y] ) { my $scanline = ""; for(my $x = 0; $x < $#{$pixels[$y]}; $x++) { if( defined $pixels[$y][$x] ) { $scanline .= $pixels[$y][$x]; $x++; } else { $scanline .= " "; } } $scanline =~ s/\s*$//; print $scanline; } print "\n"; } }