#!/usr/bin/perl use warnings; die "need number of points\n" unless @ARGV; $n = shift; die "need valid number\n" if($n!~m/^\d+$/ || $n < 1); use constant PI => 4*atan2(1,1); $rad = 150; # radius of circunference, size of star $alpha = 3*PI/2; # angle of starting point $beta = 2*PI/$n; # angle variation for(0..$n-1) # finding necessary points { $x = $rad + $rad * cos($alpha); $y = $rad + $rad * sin($alpha); $pts{$_}{x} = $x; $pts{$_}{y} = $y; $alpha += $beta; } # svg header print " \n\n"; $mod = calcMagic($n); # interval of points print STDERR "mod: $mod\n"; $oldp = 0; $p = 1; while($p != 0) { $mod = hexMagic($oldp) if($n == 6); # hexagrams are irregular $p = ($oldp + $mod) % $n; # find next point print STDERR "LINE: $oldp <-> $p\n"; $x1 = $pts{$oldp}{x}; $y1 = $pts{$oldp}{y}; $x2 = $pts{$p}{x}; $y2 = $pts{$p}{y}; print "\n"; $oldp = $p; } print "\n\n"; # calculate the interval # based on number of points sub calcMagic { ($n) = @_; $m = -1; $mod = 1; for(1..$n) { $mod += $m; $m = nextMagic($m); } return $mod; } # have no idea sub nextMagic { ($oldm) = @_; return 3 if($oldm == -1); return -2 if($oldm == 3); return 2 if($oldm == -2); return -1 if($oldm == 2); } # special case, # hexagram intervals sub hexMagic { ($p) = @_; return 2 if($p == 0); return 3 if($p == 2); return 4 if($p == 5); return 4 if($p == 3); return 3 if($p == 1); return 2 if($p == 4); }