This file is indexed.

/usr/bin/springgraph is in signing-party 1.1.10-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
#!/usr/bin/perl -w

# springgraph v0.79, (c) 2002 Darxus@ChaosReigns.com, released under the GPL
# Download current version from:  http://www.chaosreigns.com/code/springgraph/
#
# This program attempts to render .dot files in a fashion similar to neato,
# which is part of graphviz:  http://www.research.att.com/sw/tools/graphviz/.
# I have never looked at any of the code in graphviz.
#
# Example usage:
#
# cat test.dot | ./springgraph.pl -s 3 > springgraph.png
#
# The "-s 3" specifies the scale, and is optional.  All of the node
# locations are multiplied by this.  Increase the scale to eliminate
# node overlaps.  Decrease the scale to make the graph smaller.
#
# Requirements:  GD.pm (http://www.perl.com/CPAN/authors/id/L/LD/LDS/)
# 
# Definition of the .dot files which springgraph renders
# can be found in the graphviz man pages.  A copy is here:
# http://www.unisa.edu.au/eie/csec/graphviz/dot.1.html.  Springgraph only
# supports the fillcolor and label node attributes, and can only handle
# two nodes per edge definition ("node1 -> node2", not "node1 -> node2
# -> node3").
# 
# Springgraph fully supports the .dot files generated by sig2dot
# (http://www.chaosreigns.com/code/sig2dot), which generates .dot files
# from GPG/PGP signature relationships.
# 
# Thanks to the following for help with the math for the arrowheads:
# Mike Joseph <mj@doze.net>
# Walt Mankowski <waltman@pobox.com>
# Jeff Weisberg <jaw+plug@tcp4me.com>
#
# Yes, the placement of the freaking arrowheads was by far the hardest
# part of writing this program.
#
# Thanks to Hartmut Palm for cylinder translation/rotation code in
# VRML.pm:  http://dc.gfz-potsdam.de/~palm/vrmlperl/

# v0.26 May 06 16:12:30 2002 
# v0.27 May 06 18:15:38 2002 cleanup
# v0.44 May 06 23:56:45 2002 
# v0.56 May 07 05:10:02 2002
# v0.60 May 07 23:27:29 2002 arrow heads !! (not filled in due to segfault)
# v0.61 May 07          2002 handle absence of beginning double-quote in fillcolor attribute
# v0.62 May 08 19:44:04 2002 use getopts to get scale argument
# v0.63 May 08 21:29:48 2002 made fillcolor optional again
# v0.64 May 08 22:28:40 2002 render http://www.research.att.com/sw/tools/graphviz/examples/undirected/ER.dot.txt
#                            and http://www.research.att.com/sw/tools/graphviz/examples/undirected/process.dot.txt
#                            (added support for undirected graphs ("--" links)
# v0.65 May 08 22:44:00 2002 render http://www.research.att.com/sw/tools/graphviz/examples/directed/fsm.dot.txt
#                            (do not attempt to draw a line from a node to itself and cause a devision by zero)
# v0.67 May 09 05:53:16 2002 support multiple nodes on one link line, adjusted detection of completion
#                            render http://www.research.att.com/sw/tools/graphviz/examples/directed/unix.dot.txt
#                            (support node names containing spaces)
# v0.68 May 09 17:29:06 2002 cleaned up link line processing a bit (removed extraneous define checks)
# v0.69 May 09 18:23:19 2002 render http://www.research.att.com/sw/tools/graphviz/examples/undirected/inet.dot.txt
#                            (support {} lists in link (edge) lines)
# v0.70 May 10 00:39:20 2002 Strip double-quotes that were getting missed to support sig2dot v0.27.
# v0.71 May 11 20:06:17 2002 don't draw twice, added some 3D math (but not output yet)
# v0.72 May 11 21:31:20 2002 3D output !!! (via -p flag)
# v0.73 May 11 22:34:23 2002 added labels to 3D output
# v0.74 May 12 02:07:29 2002 output 3D output suitable for animation
# v0.75 May 13 01:45:41 2002 beginnings of vrml output (-v) - colored spheres
# v0.76 May 13 04:30:13 2002 added connections between nodes to vrml
#                            output, thanks cylinder translation/rotation
#                            code from VRML.pm by Hartmut Palm:
#                            http://dc.gfz-potsdam.de/~palm/vrmlperl/
# v0.77 May 13 04:41:53 2002 made colors optional in pov and vrml output
# v0.78 May 13 06:31:34 2002 removed extra cylinders from vrml output
# v0.79 May 13 07:20:23 2002 made 2d output background transparent
# v0.80 Mar 19 2003 optimization patch from Marco Bodrato
# v0.81 Aug 20 2003 Caption stderr progress notes

use Getopt::Std;
use strict;
use vars qw(
$push
$pull
%node
$im
$source
$dest
$nodenum
$blue
$black
$opt_b
$bgcol
@bgcolor
$dist
$iter
$maxiter
$percent
$xdist
$ydist
$newdist2
$xmove
$ymove
$movecount
$rate
$nodes
%link
$continue
$done
$line
@nodelist
%saw
$name
$label
$margin
$minx
$miny
$maxx
$maxy
$scale
$nodesize
$powderblue
$linecol
$h
$s
$v
$r
$g
$b
$color
$maxxlength
$minxlength
$pi
$twopi
$angle
@point
$width
$height
$arrowlength
$arrowwidth
$num
$opt_s
$edge
@parts
$part
@sources
@dests
$sourcesstring
$destsstring
$pov
$opt_p
$zdist
$zmove
$pov_or_vrml
$opt_v
$vrml
$opt_t
$trans
$opt_f
$font
$fontsize
$opt_h
$opt_l
@linecolor
);

$push = 2000;
$pull = .1;
$maxiter = 400;
$rate = 2;
$nodes = 5;
#$done = 0.1;
$done = 0.3;
#$done = 3;
$margin = 20;
#$nodesize = 80;
$nodesize = 40;
$arrowlength = 10; # pixels
$arrowwidth = 10; 

srand 1; #comment out this line to generate graphs differently every time

$pi = 3.141592653589793238462643383279502884197169399375105; # from memory
$twopi = $pi * 2;

getopts('s:pvhtb:l:f:');

# -h: Show some help
if ($opt_h) {
  usage();
  exit 1;
}
use GD;

# -s: set scale
if ($opt_s)
{
  $scale = $opt_s;
} else {
  $scale = 1;
}

# -p: Output as Pov-Ray
if ($opt_p)
{
  $pov = 1;
} else {
  $pov = 0;
}

# -v: Output as VRML
if ($opt_v)
{
  $vrml = 1;
} else {
  $vrml = 0;
}


# -t: Make background transparent
if ($opt_t)
{
  $trans = 1;
} else {
  $trans = 0;
}

# -b: Set background color
if ($opt_b)
{
  $trans = 0;
  $opt_b =~ m/^(..)(..)(..)$/ or die "Invalid color: $opt_b";
  @bgcolor = (hex($1), hex($2), hex($3));
} else {
  @bgcolor = (255, 255, 255);
}

# -l: Set line color
if ($opt_l)
{
  $trans = 0;
  $opt_l =~ m/^(..)(..)(..)$/ or die "Invalid color: $opt_l";
  @linecolor = (hex($1), hex($2), hex($3));
} else {
  @linecolor = (169, 169, 169);
}

# -f: Set TrueType font, style and size
if ($opt_f)
{
    $opt_f =~ m/^([^:]+)((:[^:]*)(:\d*)?)?$/ or die "Invalid font: $opt_f";
    $font = $1;
    $fontsize = 13;
    if ($2) {
        $2 =~ m/^(:[^:]*)(:\d*)?$/;
        $font    .= $1 if defined $1 and $1 ne ':';
        $fontsize = $2 if defined $2 and $2 ne ':';
        $fontsize =~ s/^://;
    }
}

$done = $done / $scale;

while ($line = <STDIN>)
{
  undef $name;
  next if ($line =~ m#^//#);
  chomp $line;
  # 2 = arro1, 1 = no arrow
  if ($line =~ m#^(.*-[>-][^\[]*)#)
  {
    $edge = $1;
    @parts = split(/(-[->])/,$edge);
    for $part (0 .. $#parts)
    {
      if (defined $parts[$part+2] and $parts[$part] ne '->' and $parts[$part] ne '--')
      {
        #print ":$parts[$part]:".$parts[$part+1].":".$parts[$part+2].":\n";
        undef @sources;
        undef @dests;
        $parts[$part] =~ s/^\s*"?//;
        $parts[$part] =~ s/"?\s*$//;
        $parts[$part+2] =~ s/^\s*"?//;
        $parts[$part+2] =~ s/"?\s*;?\s*$//;
        if ($parts[$part] =~ m#^{(.*)}$#)
        {
          $sourcesstring = $1;
          #print STDERR "sourcesstring:$sourcesstring:\n";
          @sources = split(/[\s*;?\s*]/,$sourcesstring);
        } else {
          $sources[0] = $parts[$part];
        }
        if ($parts[$part+2] =~ m#^{(.*)}$#)
        {
          $destsstring = $1;
          #print STDERR "destsstring:$destsstring:\n";
          @dests = split(/[\s*;?\s*]/,$destsstring);
        } else {
          $dests[0] = $parts[$part+2];
        }
        for $source (@sources)
        {
          next if ($source eq "");
          for $dest (@dests)
          {
            next if ($dest eq "");
            $source =~ s/^\s*"?//;
            $source =~ s/"?\s*$//;
            $dest =~ s/^\s*"?//;
            $dest =~ s/"?\s*;?\s*$//;
            $link{$source}{$dest} = 2 if ($parts[$part+1] eq '->');
            $link{$source}{$dest} = 1 if ($parts[$part+1] eq '--');
            push (@nodelist,$source,$dest);
            #print STDERR "$source ".$parts[$part+1]." $dest\n";
          }
        }
      }
    }

#    $source = $1;
#    $dest = $2;
#    $source =~ s/^\W*//;
#    $source =~ s/\W*$//;
#    $dest =~ s/^\W*//;
#    $dest =~ s/\W*$//;
#    $link{$source}{$dest} = 2;
#    push (@nodelist,$source,$dest);
#    print STDERR "source:$source:dest:$dest:\n";
  } else {
#    if ($line =~ m#^edge# or $line =~ m#^node#)
#    {
#      print STDERR "Skipping: $line\n";
#      next;
#    }
    if ($line =~ m#^(\S+).*\[.*\]#)
    {
      $name = $1;
      $name =~ tr/"//d;
      if ($name eq 'node' or $name eq 'edge')
      {
        next;
      }
      #print STDERR "name:$name:\n";
    }
    if ($line =~ m#\[.*label=([^,\]]*).*\]#)
    {
      $label = $1;
      $label =~ tr/"//d;
      $node{$name}{'label'} = $label;
      #print STDERR "label:$label:\n";
    }
    if ($line =~ m#\[.*fillcolor="?([\d\.]+),([\d\.]+),([\d\.]+).*\]#)
    {
      $h = $1;
      $s = $2;
      $v = $3;
      #print STDERR "hsv:$h:$s:$v:\n";
      $h = $h * 360;
      ($r,$g,$b) = &hsv2rgb($h,$s,$v);
      $node{$name}{r} = $r;
      $node{$name}{g} = $g;
      $node{$name}{b} = $b;
      #print STDERR "rgb:$r:$g:$b:\n";
    }
  }
}

undef %saw;
@saw{@nodelist} = ();
@nodelist = sort keys %saw;  # remove sort if undesired
undef %saw;

if ($pov or $vrml) {
  $pov_or_vrml = 1;
} else {
  $pov_or_vrml = 0;
}

for $nodenum (@nodelist)
{
  $node{$nodenum}{x}=rand;# $maxx;
  $node{$nodenum}{y}=rand;# $maxy;
  $node{$nodenum}{z}=rand if $pov_or_vrml;
  unless(defined $node{$nodenum}{'label'})
  {
    $node{$nodenum}{'label'} = $nodenum;
  }
}

print STDERR "springgraph iterating until reaches $done\n\n";

#&draw;
$continue = 1;
$iter = 0;
while($continue > $done)
{
  $continue = $done;
  $iter++;
  for $nodenum (@nodelist)
  {
    $node{$nodenum}{oldx} = $node{$nodenum}{x};
    $node{$nodenum}{oldy} = $node{$nodenum}{y};
    $node{$nodenum}{oldz} = $node{$nodenum}{z} if $pov_or_vrml;
    $xmove = 0;
    $ymove = 0;
    $zmove = 0 if $pov_or_vrml;
  }
  for $source (@nodelist)
  {
    $movecount = 0;
    for $dest (@nodelist)
    {
      next if $source eq $dest; # loops are not supported
      $xdist = $node{$source}{oldx} - $node{$dest}{oldx};
      $ydist = $node{$source}{oldy} - $node{$dest}{oldy};
      $dist = $xdist**2 + $ydist**2;
      if ($pov_or_vrml) {
        $zdist = $node{$source}{oldz} - $node{$dest}{oldz};
        $dist += $zdist**2;
      }
      # $distance = sqrt($dist);
      $percent = $push / $dist;
      if ($link{$source}{$dest})
      {
         $percent -= $pull;
      }
      if ($link{$dest}{$source})
      {
         $percent -= $pull;
      }
      $percent *= $rate;
      $xmove -= $xdist * $percent;
      $ymove -= $ydist * $percent;
      $zmove -= $zdist * $percent if $pov_or_vrml;
      $movecount++;
      # $pullmove = $pull * $dist;
      # $pushmove = $push / $dist;
      # print STDERR "dist: $dist, pull: $pullmove, push: $pushmove\n";
      # print STDERR "$source to ${dest}, Dist: $dist Want: $wantdist (${percent}x)\n";
      # print STDERR "is: $node[$source]{oldx} $node[$source]{oldy} $xdist $ydist, want: $wantxdist $wantydist ($newdist2)\n";

    }
    if ($movecount) {
        # renormalize if there are multiple nodes
        $xmove /= $movecount;
        $ymove /= $movecount;
        $zmove /= $movecount if $pov_or_vrml;
    }
    $node{$source}{x} -= $xmove;
    $node{$source}{y} -= $ymove;
    $node{$source}{z} -= $zmove if $pov_or_vrml;
    if ($xmove > $continue)
    {
      $continue = $xmove;
    }
    if ($ymove > $continue)
    {
      $continue = $ymove;
    }
    if (($pov_or_vrml) and $zmove > $continue)
    {
      $continue = $zmove;
    }
  }
  #print STDERR "$iter\n";
  if (0)
  {
    &draw;
    open XV,'|-', qw/xv -wait 1 -/;
    #open XV,'|-', qw/xloadimage -delay 1 stdin/;
    binmode XV;
    print XV $im->png;
    close XV;
  }
  if ($iter % 20 == 0)
  {
    print STDERR "$continue\n";
  }
}
print STDERR "Iterations: $iter\n";
for $source (@nodelist)
{
  for $color ('r', 'g', 'b')
  {
    $node{$source}{$color} = 255 unless (defined $node{$source}{$color});
  }
}
if ($pov)
{
  &drawpov;
} elsif ($vrml) {
  &drawvrml;
} else {
  &draw;
}

undef $maxx;
undef $maxy;
sub draw
{
  for $nodenum (@nodelist)
  {
    if (!(defined $maxx) or (($node{$nodenum}{x} + (length($node{$nodenum}{'label'}) * 8 + 16)/2) > $maxx + (length($node{$nodenum}{'label'}) * 8 + 16)/2))
    {
      $maxx = $node{$nodenum}{x};# + (length($node{$nodenum}{'label'}) * 8 + 16)/2/2
      $maxxlength = (length($node{$nodenum}{'label'}) * 8 + 16)/2;
    }
    if (!(defined $minx) or (($node{$nodenum}{x} - (length($node{$nodenum}{'label'}) * 8 + 16)/2) < $minx - (length($node{$nodenum}{'label'}) * 8 + 16)/2))
    {
      $minx = $node{$nodenum}{x};# - (length($node{$nodenum}{'label'}) * 8 + 16)/2/2
      $minxlength = (length($node{$nodenum}{'label'}) * 8 + 16)/2;
    }

    $maxy = $node{$nodenum}{y} if (!(defined $maxy) or $node{$nodenum}{y} > $maxy);
    $miny = $node{$nodenum}{y} if (!(defined $miny) or $node{$nodenum}{y} < $miny);
  }
  for $nodenum (@nodelist)
  {
    #$node{$nodenum}{x} = ($node{$nodenum}{x} - $minx) * $scale + $margin;
    $node{$nodenum}{x} = ($node{$nodenum}{x} - $minx) * $scale + $minxlength -1 ;# + $margin;
    $node{$nodenum}{y} = ($node{$nodenum}{y} - $miny) * $scale + $nodesize/2 - 1;
  }
  $maxx = ($maxx - $minx) * $scale + $minxlength + $maxxlength;# + $margin*2;
  $maxy = ($maxy - $miny) * $scale + $nodesize/2*2;
  $im = new GD::Image($maxx,$maxy);
  $bgcol = $im->colorAllocate(@bgcolor);
  $im->transparent($bgcol) if $trans; # make transparent
  $blue = $im->colorAllocate(0,0,255);
  $powderblue = $im->colorAllocate(176,224,230);
  $black = $im->colorAllocate(0,0,0);
  $linecol = $im->colorAllocate(@linecolor);
  $im->useFontConfig(1) if $opt_f;

  for $source (@nodelist)
  {
    #print STDERR "node: $source $node[$source]{x},$node[$source]{y}\n";
    for $dest (@nodelist)
    {
      if (defined $link{$source}{$dest} and $link{$source}{$dest} == 2 and $source ne $dest)
      {
        $dist = sqrt( abs($node{$source}{x}-$node{$dest}{x})**2 +  abs($node{$source}{y}-$node{$dest}{y})**2 );
        $xdist = $node{$source}{x} - $node{$dest}{x};
        $ydist = $node{$source}{y} - $node{$dest}{y};

        $angle = &acos($xdist/$dist);
        #$angle = atan2($ydist,$xdist);
        #$angle += $pi if $ydist < 0;
        #$dist = abs(cos($angle))*(length($node{$dest}{'label'}) * 8 + 16)/2 + abs(sin($angle))*$nodesize/2;
        $width = (length($node{$dest}{'label'}) * 8 + 16)/2;
        $height = $nodesize/2;
        $dist = sqrt( ($height**2 * $width**2) / ( ($height**2 * (cos($angle)**2) ) + ($width**2 * (sin($angle)**2) ) ));
        #$dist = $dist*40;
        $xmove = cos($angle)*$dist;
        $ymove = sin($angle)*$dist;
        #$ymove = -$ymove if $ydist < 0; # the part mj omitted
        $point[0]{x} = $xmove;
        $point[0]{y} = $ymove;

        $xmove = cos($angle)*($dist+$arrowlength-3);
        $ymove = sin($angle)*($dist+$arrowlength-3);
        #$ymove = -$ymove if $ydist < 0; # the part mj omitted
        $point[3]{x} = $xmove;
        $point[3]{y} = $ymove;

        #$angle = $angle + $arrowwidth/2;
        $dist = 4;
        $xmove = $xmove + cos($angle)*$dist;
        $ymove = $ymove + sin($angle)*$dist;
        #$ymove = -$ymove if $ydist < 0; # the part mj omitted

        $angle = $angle + $twopi/4; 
        $dist = $arrowwidth/2;
        $xmove = $xmove + cos($angle)*$dist;
        $ymove = $ymove + sin($angle)*$dist;
        #$ymove = -$ymove if $ydist < 0; # the part mj omitted
        $point[1]{x} = $xmove;
        $point[1]{y} = $ymove;

        $angle = $angle + $twopi/2;
        $dist = $arrowwidth;
        $xmove = $xmove + cos($angle)*$dist;
        $ymove = $ymove + sin($angle)*$dist;
        #$ymove = -$ymove if $ydist < 0; # the part mj omitted
        $point[2]{x} = $xmove;
        $point[2]{y} = $ymove;

        for $num (0 .. 3)
        {
          $point[$num]{y} = - $point[$num]{y} if $ydist < 0;
        }
        
        $im->line($node{$dest}{x}+$point[0]{x},$node{$dest}{y}+$point[0]{y},$node{$dest}{x}+$point[1]{x},$node{$dest}{y}+$point[1]{y},$linecol);
        $im->line($node{$dest}{x}+$point[1]{x},$node{$dest}{y}+$point[1]{y},$node{$dest}{x}+$point[2]{x},$node{$dest}{y}+$point[2]{y},$linecol);
        $im->line($node{$dest}{x}+$point[2]{x},$node{$dest}{y}+$point[2]{y},$node{$dest}{x}+$point[0]{x},$node{$dest}{y}+$point[0]{y},$linecol);
#        $xmove = int($node{$dest}{x}+$point[3]{x});
#        $ymove = int($node{$dest}{y}+$point[3]{y});
#        $im->fillToBorder($xmove,$ymove,$linecol,$powderblue);
        #$im->fillToBorder($node{$dest}{x}+$point[3]{x},$node{$dest}{y}+$point[3]{y},$linecol,$linecol);
        #$im->line($point[1]{x},$point[1]{y},$point[2]{x},$point[2]{y},$linecol);
        #$im->line($point[2]{x},$point[2]{y},$point[0]{x},$point[0]{y},$linecol);
        #$im->fillToBorder($point[3]{x},$point[3]{y},$linecol,$linecol);
        #$im->arc($point[3]{x},$point[3]{y},10,10,0,360,$black);

#        $im->arc($point[0]{x},$point[0]{y},20,20,0,360,$black);
#        $im->arc($point[1]{x},$point[1]{y},20,20,0,360,$black);
#        $im->arc($point[2]{x},$point[2]{y},20,20,0,360,$black);
        #$im->arc($node{$dest}{x}+$xmove,$node{$dest}{y}+$ymove,20,20,0,360,$black);
      }
    }
  }
  for $source (@nodelist)
  {
    for $dest (@nodelist)
    {
      if ($link{$source}{$dest})
      {
        $im->line($node{$source}{x},$node{$source}{y},$node{$dest}{x},$node{$dest}{y},$linecol);
      }
    }
  }

  for $source (@nodelist)
  {
    if ($opt_f) {
        my @bounds = GD::Image::->stringFT($black,$font,$fontsize,0,0,0,$node{$source}{'label'});
        $im->arc($node{$source}{x},$node{$source}{y},$bounds[2]-$bounds[0]+1.5*$fontsize,$nodesize,0,360,$black);
    } else {
        $im->arc($node{$source}{x},$node{$source}{y},(length($node{$source}{'label'}) * 8 + 16),$nodesize,0,360,$black);
    }
    if (defined $node{$source}{r} and defined $node{$source}{g} and defined $node{$source}{b})
    {
      $color = $im->colorResolve($node{$source}{r},$node{$source}{g},$node{$source}{b});
    } else
    {
      $color = $bgcol;
    }
    $im->fillToBorder($node{$source}{x},$node{$source}{y},$black,$color);
  }
  for $source (@nodelist)
  {
    if ($opt_f) {
        my @bounds = GD::Image::->stringFT($black,$font,$fontsize,0,0,0,$node{$source}{'label'});
        $im->stringFT($black,$font,$fontsize,0,$node{$source}{x} - ($bounds[0]+$bounds[2])/2.0,$node{$source}{y}+$fontsize/2.0,$node{$source}{'label'});
    } else {
        $im->string(gdLargeFont,$node{$source}{x} - (length($node{$source}{'label'}) * 8 / 2),$node{$source}{y}-8,$node{$source}{'label'},$black);
    }
  }


  binmode STDOUT;
  print $im->png;
}

sub drawpov
{
  print'// Generated by springgraph, by Darxus@ChaosReigns.com: 
// http://www.ChaosReigns.com/code/springgraph/

#include "colors.inc"
#include "shapes.inc"
#include "textures.inc"
#include "glass.inc"
#include "stones.inc"
light_source {<0, 400, -500> color White rotate <0, 360*clock, 0>}
light_source {<400, 0, -500> color White rotate <0, 360*clock, 0>}
';

  for $source (@nodelist)
  {
    $node{$source}{x} = $node{$source}{x} * $scale;
    $node{$source}{y} = $node{$source}{y} * $scale;
    $node{$source}{z} = $node{$source}{z} * $scale;
    $node{$source}{r} = $node{$source}{r} / 256;
    $node{$source}{g} = $node{$source}{g} / 256;
    $node{$source}{b} = $node{$source}{b} / 256;
  }
  for $source (@nodelist)
  {
    print "sphere { <$node{$source}{x},$node{$source}{y},$node{$source}{z}>, 15 pigment {color rgb<$node{$source}{r},$node{$source}{g},$node{$source}{b}>}}\n";
    print "text { ttf \"crystal.ttf\", \"$node{$source}{'label'}\", 0.5, 0 translate 2*x rotate <0, 360*clock, 0> translate -0.375*y scale 10 translate <$node{$source}{x},$node{$source}{y},$node{$source}{z}> pigment {color rgb<$node{$source}{r},$node{$source}{g},$node{$source}{b}>}}\n";
    #print "text { ttf \"crystal.ttf\", \"$node{$source}{'label'}\", 0.5, 0 translate -".scalar(length($node{$source}{'label'})*0.25)."*x scale 10 translate <$node{$source}{x},$node{$source}{y},$node{$source}{z}> pigment {color rgb<$node{$source}{r},$node{$source}{g},$node{$source}{b}>}}\n";
    for $dest (@nodelist)
    {
      if ($link{$source}{$dest})
      {
        print "cylinder {<$node{$source}{x},$node{$source}{y},$node{$source}{z}>,<$node{$dest}{x},$node{$dest}{y},$node{$dest}{z}> 0.5 pigment {color rgb<0.5,0.5,0.5>}}\n";
      }
    }
  }
  print 'camera {
   location  <0, 0, -500>
   up        <0.0,  1.0,  0>
   right     <4/3,  0.0,  0>
   look_at   <0,    0,   -1>
   rotate <0, 360*clock, 0>
}
';

}


sub drawvrml
{
  my ($t,$r,$length,$color);
  print'#VRML V2.0 utf8

WorldInfo {
  info ["Generated by springgraph, by Darxus@ChaosReigns.com: http://www.ChaosReigns.com/code/springgraph/"]
}

';

  for $source (@nodelist)
  {
    $node{$source}{x} = $node{$source}{x} * $scale;
    $node{$source}{y} = $node{$source}{y} * $scale;
    $node{$source}{z} = $node{$source}{z} * $scale;
    for $color ('r', 'g', 'b')
    {
      if (defined $node{$source}{$color})
      {
        $node{$source}{$color} = $node{$source}{$color} / 256;
      }
    }
  }
  for $source (@nodelist)
  {
print "
Transform {
  translation $node{$source}{x} $node{$source}{y} $node{$source}{z}
  children [
    Shape{
        appearance Appearance {
           material Material {
              diffuseColor $node{$source}{r} $node{$source}{g} $node{$source}{b}
           }
        }
        geometry Sphere{radius 15}
    }
  ]
}
";

    #print "sphere { <$node{$source}{x},$node{$source}{y},$node{$source}{z}>, 15 pigment {color rgb<$node{$source}{r},$node{$source}{g},$node{$source}{b}>}}\n";
    #print "text { ttf \"crystal.ttf\", \"$node{$source}{'label'}\", 0.5, 0 translate 2*x rotate <0, 360*clock, 0> translate -0.375*y scale 10 translate <$node{$source}{x},$node{$source}{y},$node{$source}{z}> pigment {color rgb<$node{$source}{r},$node{$source}{g},$node{$source}{b}>}}\n";
    #print "text { ttf \"crystal.ttf\", \"$node{$source}{'label'}\", 0.5, 0 translate -".scalar(length($node{$source}{'label'})*0.25)."*x scale 10 translate <$node{$source}{x},$node{$source}{y},$node{$source}{z}> pigment {color rgb<$node{$source}{r},$node{$source}{g},$node{$source}{b}>}}\n";
    for $dest (@nodelist)
    {
      if ($link{$source}{$dest})
      {
        ($t,$r,$length) = &cylinder($node{$source}{x},$node{$source}{y},$node{$source}{z},$node{$dest}{x},$node{$dest}{y},$node{$dest}{z});
        print "
Transform {
  translation $t
  rotation $r
  children [
    Shape{
        appearance Appearance {
           material Material {
              diffuseColor 0.5 0.5 0.5
           }
        }
        geometry Cylinder {
          radius 0.5
          height $length
          top FALSE
          bottom FALSE
        }
    }
  ]
}
";


        
      }
    }
  }
#  print 'camera {
#   location  <0, 0, -500>
#   up        <0.0,  1.0,  0>
#   right     <4/3,  0.0,  0>
#   look_at   <0,    0,   -1>
#   rotate <0, 360*clock, 0>
#}
#';

}




sub hsv2rgb
{
#from http://faqchest.dynhost.com/prgm/perlu-l/perl-01/perl-0101/perl-010100/perl01010410_17820.html

# Given an h/s/v array, return an r/g/b array.
# The r/g/b values will each be between 0 and 255.
# The h value will be between 0 and 360, and
# the s and v values will be between 0 and 1.
#

                      my $h = shift;
                      my $s = shift;
                      my $v = shift;

                      # limit this to h values between 0 and 360 and s/v values
                      # between 0 and 1

                      unless (defined($h) && defined($s) && defined($v) &&
                             $h >= 0 && $s >= 0 && $v >= 0 &&
                             $h <= 360 && $s <= 1 && $v <= 1) {
                        return (undef, undef, undef);
                      }

                      my $r;
                      my $g;
                      my $b;

                      # 0.003 is less than 1/255; use this to make the floating point
                      # approximation of zero, since the resulting rgb values will
                      # normally be used as integers between 0 and 255.  Feel free to
                      # change this approximation of zero to something else, if this
                      # suits you.
                      if ($s < 0.003) {
                        $r = $g = $b = $v;
                      }
                      else {

                        $h /= 60;
                        my $sector = int($h);
                        my $fraction = $h - $sector;

                        my $p = $v * (1 - $s);
                        my $q = $v * (1 - ($s * $fraction));
                        my $t = $v * (1 - ($s * (1 - $fraction)));

                        if ($sector == 0) {
                          $r = $v;
                          $g = $t;
                          $b = $p;
                        }
                        elsif ($sector == 1) {
                          $r = $q;
                          $g = $v;
                          $b = $p;
                        }
                        elsif ($sector == 2) {
                          $r = $p;
                          $g = $v;
                          $b = $t;
                        }
                        elsif ($sector == 3) {
                          $r = $p;
                          $g = $q;
                          $b = $v;
                        }
                        elsif ($sector == 4) {
                          $r = $t;
                          $g = $p;
                          $b = $v;
                        }
                        else {
                          $r = $v;
                          $g = $p;
                          $b = $q;
                        }
                      }

                      # Convert the r/g/b values to all be between 0 and 255; use the
                      # ol' 0.003 approximation again, with the same comment as above.

                      $r = ($r < 0.003 ? 0.0 : $r * 255);
                      $g = ($g < 0.003 ? 0.0 : $g * 255);
                      $b = ($b < 0.003 ? 0.0 : $b * 255);

                      return ($r, $g, $b);
                    }

# from perlfunc(1)
sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }


sub cylinder {
    my ($x1,$y1,$z1,$x2,$y2,$z2) = @_;
    my ($t, $r, $length, $rx, $ry, $rz, $dist);

    $x1 = 0 unless $x1;
    $x2 = 0 unless $x2;
    $y1 = 0 unless $y1;
    $y2 = 0 unless $y2;
    $z1 = 0 unless $z1;
    $z2 = 0 unless $z2;
    my $dx=$x1-$x2;
    my $dy=$y1-$y2;
    my $dz=$z1-$z2;
    $length = sqrt($dx**2 + $dy**2 + $dz**2);
    $rx = $dx;
    $ry = $dy+$length;
    $rz = $dz;
    $dist = sqrt($rx**2 + $ry**2 + $rz**2);
    if ($dist) {
        # renormalize if the cylinder is not degenerated
        $rx /= $dist;
        $ry /= $dist;
        $rz /= $dist;
    }
    $t = ($x1-($dx/2))." ".($y1-($dy/2))." ".($z1-($dz/2));
    $r = "$rx $ry $rz $pi";
    return ($t,$r,$length);
}

sub usage {
print <<END
springgraph - Render a .dot file into a graphic, taking that dot file
              on standard in and delivering a PNG on standard out.

Usage:
  springgraph [-p] [-v] [-s scale] [-t] [-b color] [-l color] \\
              [-f font[:[style]:size]] [-h]
  < example.dot > example.png

   -p   Create a file that can be rendered with POV-Ray
   -v   Create a VRML file
   -s   This option specifies the scale. All of the node locations
        are multiplied by this. Increase the scale to eliminate node
        overlaps. Decrease the scale to make the graph smaller. 
   -t   Make the background of the resulting image transparent.
   -b   Set background color of image, specify it in the form RRGGBB,
        in hex digits, e.g. FFFFFF is white, 000000 is black, FF0000
        is red, ...
   -l   Set the line color, same format as the background color
   -f   Set the (TrueType) font, and optionally the style and size, to
        use for labels.  Example: "DejaVu Serif:Italic:12".
   -h   Show this help

END
}