-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhitelines.rb
126 lines (111 loc) · 3.38 KB
/
whitelines.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require 'cairo'
# Device
devices = {
github: {
width: 1920,
height: 256,
pixels_per_mm: 12,
},
manta: {
abbrev: 'a5',
width: 1920,
height: 2560,
pixels_per_mm: 12,
},
nomad: {
abbrev: 'a6',
width: 1404,
height: 1872,
pixels_per_mm: 12,
}
}
# settings
colors = {
plain: {
background: 1,
dot_color: 0.5,
dot_radius: 2,
line_color: 0.2,
line_width: 1,
},
white: {
background: 0.80,
dot_color: 1,
dot_radius: 3,
line_color: 1,
line_width: 4,
},
"white dark": {
background: 0.78,
dot_color: 1,
dot_radius: 3,
line_color: 1,
line_width: 4,
}
}
devices.each do |device_name, specs|
width = specs[:width]
height = specs[:height]
pixels_per_mm = specs[:pixels_per_mm]
['dot grid', 'lines', 'grid'].each do |style|
colors.each do |theme, colors|
background = colors[:background]
dot_color = colors[:dot_color]
dot_radius = colors[:dot_radius]
line_color = colors[:line_color]
line_width = colors[:line_width]
(2..10).to_a.each do |grid_size_mm|
square_size = pixels_per_mm * grid_size_mm
background_color = [background, background, background]
dot_color_color = [dot_color, dot_color, dot_color]
line_color_color = [line_color, line_color, line_color]
rows = height % square_size != 0 ? height / square_size : height / square_size - 1
columns = width % square_size != 0 ? width / square_size : width / square_size - 1
offset_x = (width - (square_size * columns)) / 2
offset_y = (height - (square_size * rows)) / 2
# Create a PNG surface
surface = Cairo::ImageSurface.new(:argb32, width, height)
context = Cairo::Context.new(surface)
# Fill the background
context.set_source_rgb(*background_color)
context.paint
if (style == 'dot grid')
context.set_source_rgb(*dot_color_color)
(rows + 1).times do |row|
(columns + 1).times do |col|
x = offset_x + col * square_size
y = offset_y + row * square_size
context.arc(x, y, dot_radius, 0, 2 * Math::PI) # Draw a circle (dot)
context.fill # Fill the dot
end
end
else
# Draw the grid
context.set_source_rgb(*line_color_color)
context.set_line_width(line_width)
# Draw vertical grid lines
if (style == 'grid')
(columns + 1).times do |col|
x = offset_x + col * square_size
context.move_to(x, 0) # Start at the top edge
context.line_to(x, height) # Go to the bottom edge
end
end
# Draw horizontal grid lines
(rows + 1).times do |row|
y = offset_y + row * square_size
context.move_to(0, y) # Start at the left edge
context.line_to(width, y) # Go to the right edge
end
# Stroke the grid lines
context.stroke
end
# Save to a PNG file
output_file = "#{grid_size_mm}mm #{style} #{theme}.png"
surface.write_to_png("#{device_name}/#{output_file}")
surface.write_to_png("all_devices/#{specs[:abbrev]}_#{output_file}") unless specs[:abbrev].nil?
puts "PNG file saved as #{output_file}"
end
end
end
end