Skip to content

Instantly share code, notes, and snippets.

@hannahwhy
Created July 18, 2009 17:19
Show Gist options
  • Save hannahwhy/149620 to your computer and use it in GitHub Desktop.
Save hannahwhy/149620 to your computer and use it in GitHub Desktop.
a background generator
#!/usr/bin/env ruby
require 'rubygems'
require 'RMagick'
Width = 960.0
TotalDivisions = 24
Divisions = [ 4 + 1, 16 - 1, 4 ]
Colors = [ '#6c7174', '#c3c7cb', '#4b4d4e' ]
BorderThickness = 8
BorderColor = '#000000'
BlueprintGridWidth = (Width + BorderThickness) / TotalDivisions - BorderThickness
Lengths = Divisions.map { |d| BlueprintGridWidth * d + (BorderThickness * (d - 1)) }
exit "TotalDivisions != Divisions total" if Divisions.inject(0) { |r,x| x += r } != TotalDivisions
canvas = Magick::Image.new(Width, 1)
gc = Magick::Draw.new
gc.stroke_width(1)
Lengths.zip(Colors).inject(0) do |last, (len,color)|
puts "drawing from #{last}, length=#{len}, color=#{color}"
gc.stroke(color)
gc.line(last, 0, last + len, 0)
gc.stroke(BorderColor)
gc.line(last + len, 0, last + len + BorderThickness, 0)
last + len + BorderThickness
end
gc.draw(canvas)
canvas.write(File.join(ARGV[0], 'bg.png'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment