Skip to content

Instantly share code, notes, and snippets.

@ikr7
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikr7/9761203 to your computer and use it in GitHub Desktop.
Save ikr7/9761203 to your computer and use it in GitHub Desktop.
Ruby de 陰毛
# coding: utf-8
require 'cairo'
require './inmou.class.rb'
width = 256
height = 256
amount = 16
length = 1
curly = 30
surface = Cairo::ImageSurface.new(width, height)
context = Cairo::Context.new(surface)
context.set_source_rgba(1, 1, 1, 1)
context.rectangle(0, 0, width, height)
context.fill()
context.set_source_rgba(0, 0, 0, 1)
inmous = []
i = 0
while(i < width)
inmou = Inmou.new(
context,
i + (width / amount / 2),
height + height / 6,
(height / 6) * length,
Math::PI,
5,
curly
)
inmous << inmou
i += width / amount
end
inmous.each do | inmou |
20.times do ||
inmou.grow()
end
end
surface.write_to_png('inmou.png')
class Inmou
def initialize(context, startX, startY, length, angle, branchWidth, curly)
@context = context
@curly = curly
@maxAngle = @curly * Math::PI / 180
@angle = angle
@length = length
@startX = startX
@startY = startY
@endX = @startX + @length * Math.sin(@angle)
@endY = @startY + @length * Math.cos(@angle)
@branchWidth = branchWidth
end
def grow()
@context.set_line_cap('ROUND')
@context.set_line_width(@branchWidth)
@context.move_to(@startX, @startY)
@context.line_to(@endX, @endY)
@context.stroke()
@angle = @angle + Random.rand(1.0) * @maxAngle - @maxAngle * 0.5
@length = @length * (0.7 + Random.rand(1.0) * 0.3)
@startX = @endX
@startY = @endY
@endX = @startX + @length * Math.sin(@angle);
@endY = @startY + @length * Math.cos(@angle);
@branchWidth = @branchWidth * 0.8
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment