icps

notes

Calendar

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
#!/usr/bin/env ruby
# encoding: utf-8
require 'rmagick'
require 'date'

def write_text(today, day, idy, idx)
    if idy == 0
        color = "blue"
        fix   = SIZEX / (-5)
    else
        day == today ? color = "red" : color = "grey"
        day.to_i > 9 ? fix = 0 : fix = SIZEX / 2
        fix += SIZEX / 10 * day.to_s.scan(/1/).count
    end
    lx        = X + idx * SIZEX * 2 + fix
    ly        = Y + idy * SIZEY
    TEXT.fill = "black"
    TEXT.annotate(CANVAS, 0, 0, lx, ly, day.to_s)
    TEXT.fill = color
    TEXT.annotate(CANVAS, 0, 0, lx-1, ly, day.to_s)
end

input, output  = ARGV
img            = Magick::Image.ping(input).first
X              = img.columns - 450
Y              = img.rows - 1100
CANVAS         = Magick::ImageList.new.read(input)
TEXT           = Magick::Draw.new
TEXT.pointsize = 32
SIZEX          = 32
SIZEY          = 42
today          = Time.now.getlocal('+08:00')
year           = today.year
month          = today.month
today          = today.day
first          = Date.new(year, month,  1).wday
days           = Date.new(year, month, -1).day
mdays          = %w(SU MO TU WE TH FR SA) + Array.new(first, "  ") + (1..days).to_a

(mdays).each_slice(7).to_a.each_with_index do |week, idy|
    week.each_with_index do |day, idx|
        write_text(today, day, idy, idx)
    end
end
CANVAS.write(output)