#!/usr/bin/perl # Takes input from stdin in the format: # [ignored]: [ignored]: [nodes]: [edges] # Where "nodes" and "edges" are each a series of comma,delimited pairs # separated by semicolons; # The "node" pairs are expected to describe coordinates. # The "edge" pairs are expected to be pairs of node numbers, where nodes # 0 through 5 are the "fixed" nodes of the steiner problem, and nodes from # 6 on are specified in the [node] list. use strict; my @fixed = ([0,0], [0,300],[400,0],[400,300],[800,0],[800,300]); my @frames; while(<>) { chomp; my @a = split(': ', $_); my @p = (@fixed, map {[split(',',$_)]} split(';', $a[2])); my @g = map {[split(',',$_)]} split(';', @a[3]); push(@frames, [\@p, \@g]); } use GD::Image::AnimatedGif; # Set up the image my $image = GD::Image->new(820,320); my $white = $image->colorAllocate(0,0,0); my $red = $image->colorAllocate(127,255,255); # Set up some dummy variables my $fontcolor = $image->colorAllocate(255,255,255); my $font = GD::Font->Small(); # Set up some settings my $loop = 0; my $speed = 10; # 1/100 of a sec my $x_font = 2; # from right (x or y ??) my $y_font = 2; # from top (x or $y ??) sub optional_frame_handler { my ($frm, $dat) = @_; my ($n, $l) = @$dat; my @n = @$n; for my $key (@$l) { my @pair = @$key; my $a = $n[$pair[0]]; my $b = $n[$pair[1]]; $frm->line($$a[0]+10, $$a[1]+10, $$b[0]+10, $$b[1]+10, $red); } } print $image->animated_gif($loop,$font,$fontcolor,$speed,$x_font,$y_font,\@frames, \&optional_frame_handler);