#!/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 "<?xml version='1.0' standalone='no'?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg width='100%' height='100%' version='1.1' xmlns='http://www.w3.org/2000/svg'>\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 "<line x1='$x1' y1='$y1' x2='$x2' y2='$y2' style='stroke:rgb +(0,0,0);stroke-width:1'/>\n"; $oldp = $p; } print "\n</svg>\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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RFC: Creating unicursal stars
by huxtonr (Initiate) on Nov 06, 2009 at 16:27 UTC | |
by Fox (Pilgrim) on Nov 07, 2009 at 16:09 UTC | |
by Anonymous Monk on Nov 06, 2009 at 18:14 UTC | |
by Your Mother (Archbishop) on Nov 07, 2009 at 16:54 UTC | |
by tye (Sage) on Nov 09, 2009 at 20:35 UTC | |
by Your Mother (Archbishop) on Nov 09, 2009 at 23:09 UTC | |
| |
by ikegami (Patriarch) on Nov 09, 2009 at 21:05 UTC | |
| |
by ysth (Canon) on Dec 02, 2009 at 19:04 UTC | |
by Anonymous Monk on Nov 09, 2009 at 22:15 UTC | |
by Your Mother (Archbishop) on Nov 09, 2009 at 22:44 UTC | |
| |
by Anonymous Monk on Nov 09, 2009 at 22:29 UTC | |
Re: RFC: Creating unicursal stars
by zentara (Cardinal) on Nov 06, 2009 at 18:23 UTC | |
by Fox (Pilgrim) on Nov 07, 2009 at 16:13 UTC | |
Re: RFC: Creating unicursal stars
by hossman (Prior) on Nov 07, 2009 at 08:47 UTC | |
by Fox (Pilgrim) on Nov 07, 2009 at 16:20 UTC |