Created
July 10, 2014 17:19
-
-
Save grafi-tt/1071944ee24803474fca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w, h = 200.0, 200.0 | |
vertexes = [[130.0,80.0], [50.0,50.0], [60.0,140.0]] | |
def ext(a,b) 11*a-10*b end | |
lines = vertexes.combination(2).map do |(x1,y1),(x2,y2)| | |
[[ext(x1,x2),ext(y1,y2)],[ext(x2,x1),ext(y2,y1)]] | |
end | |
ratios = [[1,0,0].permutation, [1,1,0].permutation, [4,-1,0].permutation, [3,3,-2].permutation, [5,-1,-1].permutation, [[1,1,1]]].map(&:to_a).flatten(1).uniq | |
xsys = vertexes.transpose | |
points = ratios.map do |ratio| | |
xsys.map do |vs| | |
vs.zip(ratio).map{|v,r|v*r}.inject(&:+) / ratio.inject(&:+) | |
end | |
end | |
puts <<EOF | |
%!PS-Adobe-3.1 EPSF-3.0 | |
%%BoundingBox: 0 0 #{w} #{h} | |
#{lines.map{|(x1,y1),(x2,y2)|"#{x1} #{y1} moveto #{x2} #{y2} lineto stroke"}.join("\n")} | |
1 0 0 setrgbcolor | |
#{points.map{|x,y|"#{x} #{y} 3 0 360 arc closepath fill"}.join("\n")} | |
showpage | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment