Created
April 8, 2016 12:38
-
-
Save takehiko/80f43a4cf4c4c21243ab939cdce198d6 to your computer and use it in GitHub Desktop.
Glyph drawer
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
#!/usr/bin/env ruby | |
# glyph-liner.rb : Glyph drawer | |
# by takehikom | |
# ImageMagick's "convert" command is required. | |
class GlyphLiner | |
def initialize(param) | |
@side = 320 | |
@filename = "#{param.to_s.downcase}.png" | |
@path = [[:outer, 210], [:inner, 210], [:inner, 330], [:outer, 330]] # stability | |
if param == :share | |
@path.unshift([:outer, 270]) | |
end | |
end | |
def start | |
r1 = @side / 70.0 | |
w1 = @side / 60.0 | |
w2 = w1 * 0.33 | |
cl = "LightGoldenrod" | |
@command = "convert -size #{@side}x#{@side} xc:gray10" | |
@command += " -fill none -stroke #{cl} -strokewidth #{w1}" | |
@command += " -draw \"stroke-linecap round stroke-linejoin round path \'" | |
xy_a = @path.map {|sym, angle| poler2xy(sym, angle)} | |
a1 = xy_a.map {|ary| ary.join(",")} | |
a1.unshift("M") | |
a1[3, 0] = "L" | |
path_s = a1.join(" ") | |
@command += path_s | |
@command += "\'\"" | |
@command += " -fill none -stroke white -strokewidth #{w2}" | |
@command += " -draw \"" | |
x, y = poler2xy(0, 0) | |
@command += "circle #{x},#{y} #{x + r1},#{y + r1} " | |
[30, 150, 210, 330].each do |angle| | |
next if @path.include?([:inner, angle]) | |
x, y = poler2xy(:inner, angle) | |
@command += "circle #{x},#{y} #{x + r1},#{y + r1} " | |
end | |
6.times do |i| | |
angle = 30 + 60 * i | |
next if @path.include?([:inner, angle]) | |
x, y = poler2xy(:outer, angle) | |
@command += "circle #{x},#{y} #{x + r1},#{y + r1} " | |
end | |
@command += "\"" | |
unless xy_a.empty? | |
@command += " -fill #{cl} -stroke #{cl} -strokewidth #{w2}" | |
@command += " -draw \"" | |
xy_a.each do |x, y| | |
@command += "circle #{x},#{y} #{x + r1},#{y + r1} " | |
end | |
@command += "\"" | |
end | |
@command += " -quality 95 #{@filename}" | |
puts @command | |
system @command | |
end | |
def poler2xy(r, angle) | |
case r | |
when :zero, :center | |
r = 0.0 | |
when :inner | |
r = @side * 0.2 | |
when :outer | |
r = @side * 0.4 | |
when :frame | |
r = @side | |
end | |
x = @side * 0.5 + r * Math.cos(Math::PI * (angle / 180.0)) | |
y = @side * 0.5 - r * Math.sin(Math::PI * (angle / 180.0)) | |
[x, y] | |
end | |
end | |
if __FILE__ == $0 | |
GlyphLiner.new(:share).start | |
GlyphLiner.new(:stability).start | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment