-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.rb
71 lines (58 loc) · 1.73 KB
/
render.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
require 'byebug'
require 'RMagick'
require_relative 'src/attributes'
require_relative 'src/circle'
require_relative 'src/constants'
require_relative 'src/gap'
require_relative 'src/leaf_image'
require_relative 'src/plant_collection'
require_relative 'src/rectangle'
require_relative 'src/splat'
require_relative 'src/watercolor'
SHADOW_OFFSET = 7
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def render_image(attributes:, image_number:)
watercolor = Watercolor.new(attributes: attributes, image_number: image_number)
plant_collection = PlantCollection.new(attributes: attributes, image_number: image_number)
final_image = Magick::Image.new(Constants::IMAGE_WIDTH, Constants::IMAGE_HEIGHT) do
self.background_color = "##{Color.random_color(background: true, palette: attributes.palette).to_rgb}"
end
final_image = final_image.composite(
plant_collection.shadow_image,
SHADOW_OFFSET,
SHADOW_OFFSET,
Magick::OverCompositeOp
)
final_image.mask(plant_collection.plants_image)
final_image = final_image.composite(
watercolor.get_image,
0,
0,
Magick::AtopCompositeOp
)
final_image.write('image-precrop.png') do
self.format = 'png'
end
img = Magick::Image.read('image-precrop.png')[0]
img.crop!(
25,
25,
Constants::IMAGE_WIDTH - 25,
Constants::IMAGE_HEIGHT - 25
)
img.write("image#{image_number}.png") do
self.format = 'png'
end
end
1.upto(25) do |idx|
attributes = Attributes.new
puts "Rendering image #{idx}"
puts attributes.inspect
render_image(attributes: attributes, image_number: idx)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength