aboutsummaryrefslogtreecommitdiffhomepage
path: root/hoge.rb
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-15 03:02:28 +0900
committernsfisis <nsfisis@gmail.com>2026-02-15 03:02:28 +0900
commit182d78807519f0cc73f22dd3bef1084230809f35 (patch)
tree8249fe14c1d24263d9086fcd893d08a8eb7a16e6 /hoge.rb
parent65231c3aa748932e6c4543db86201d4ed2193d3a (diff)
downloadnsfisis-draw-icon.tar.gz
nsfisis-draw-icon.tar.zst
nsfisis-draw-icon.zip
wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip wip
Diffstat (limited to 'hoge.rb')
-rw-r--r--hoge.rb82
1 files changed, 82 insertions, 0 deletions
diff --git a/hoge.rb b/hoge.rb
new file mode 100644
index 0000000..4b47419
--- /dev/null
+++ b/hoge.rb
@@ -0,0 +1,82 @@
+H = 100
+W = 100
+C0 = [0] * 3
+C1 = [255] * 3
+
+I = Array.new(H) { Array.new(W) { C1.dup } }
+
+def p(y, x, c, a = 1.0)
+ y, x = y.to_i, x.to_i
+ return if x < 0 || x >= W || y < 0 || y >= H || a <= 0
+ I[y][x] = a >= 1.0 ? c : (0..2).map { (c[it] * a + I[y][x][it] * (1 - a)).round }
+end
+
+def c(cx, cy, r, c)
+ (2*r).times do |dy|
+ (2*r).times do |dx|
+ y = cy + dy - r
+ x = cx + dx - r
+ p(y, x, c) if (x-cx)**2 + (y-cy)**2 <= r**2
+ end
+ end
+end
+
+def l(y0, x0, y1, x1, c, w)
+ dy = y1 - y0
+ dx = x1 - x0
+ l = Math.hypot(dx, dy)
+ return if l == 0
+ s = (l * 2).to_i
+ (0..s).each do |i|
+ t = i.to_f / s
+ cy = y0 + dy * t
+ cx = x0 + dx * t
+ (-w..w).each do |oy|
+ (-w..w).each do |ox|
+ p(cy + oy, cx + ox, c) if ox**2 + oy**2 <= w**2
+ end
+ end
+ end
+end
+
+def r(x, y, w, h, c, a = 1)
+ h.times do |dy|
+ w.times do |dx|
+ p(y + dy, x + dx, c, a)
+ end
+ end
+end
+
+srand(42)
+
+c(H/2, W/2, 50, [255, 165, 0])
+c(H/2, W/2, 47, C1)
+c(H/2, W/2, 44, [255, 165, 0])
+
+10.times do |t|
+ u = t * Math::PI / 5
+ lx = 50 + 45 * Math.sin(u)
+ ly = 50 - 45 * Math.cos(u)
+ l(ly, lx, H/2, W/2, C1, 1)
+end
+10.times do |dy|
+ 10.times do |dx|
+ x = dx * 10
+ y = dy * 10
+ next if x < W/2
+ next if (x - 45)**2 + (y - 45)**2 > 55**2
+ next if rand < 0.5
+ c = [[255, 165, 0], [255, 140, 0], [255, 215, 0], [255, 205, 114],
+ [255, 210, 127], [255, 192, 76], [255, 169, 12], [255, 228, 178]].sample
+ r(x, y, 10, 10, c, 0.75)
+ end
+end
+r(30, 35, 6, 25, C0)
+r(64, 35, 6, 25, C0)
+
+puts "P3"
+puts "#{W} #{H}"
+puts "255"
+I.each do |l|
+ puts l.map { it * " " } * " "
+end