Edited at

rcairoのスクリプトをmruby-cairoで試してみた

こちらにあったrcairoのスクリプトをmruby-cairoで試してみました。

http://blawat2015.no-ip.com/~mieki256/diary/201201241.html

W = 128

H = 160

RST = 21

width, height = W, H

num_enable = true

fpsv = 24

fontname = "/root/fonts/6x13.pcf"

def radians(ang)
return (ang.to_f * Math::PI / 180.0)
end

def draw_watch(cr, cx, cy, r, fpsv, num_enable, fontname)
rd = [0.97, 0.90, 0.87, 0.84, 0.82]
rdnum = [0.80, 0.76, 0.63]
lv = [0.0, 0.0, 0.0, 0.0]
wd = 1.1

c = 0.0
cr.set_source_rgb(c, c, c)
cr.set_line_width(wd)
cr.arc( cx, cy, r * rd[0], 0, 2 * Math::PI)
cr.arc( cx, cy, r * rd[1], 0, 2 * Math::PI)
cr.arc( cx, cy, r * rd[2], 0, 2 * Math::PI)
cr.stroke()

(6*fpsv).times do |i|
ang = radians(360.0 * i / (6 * fpsv) - 90)

x0 = (r * rd[0]) * Math.cos(ang) + cx
y0 = (r * rd[0]) * Math.sin(ang) + cy

if ( i % fpsv ) == 0 then
rr = r * rd[4]
c = lv[3]
l = wd * 3.0
elsif (i % (fpsv / 4) ) == 0 then
rr = r * rd[3]
c = lv[2]
l = wd
elsif (i % (fpsv/8) ) == 0 then
rr = r * rd[2]
c = lv[1]
l = wd
else
rr = r * rd[1]
c = lv[0]
l = wd
end

x1 = rr.to_f * Math.cos(ang) + cx
y1 = rr.to_f * Math.sin(ang) + cy

cr.set_source_rgb(c, c, c)
cr.set_line_width(l)
cr.move_to(x0, y0)
cr.line_to(x1, y1)
cr.stroke()
end

if num_enable then

(6*4).times do |i|
ang = radians(360.0 * i / (6*4) - 90)
if (i % 4) == 0 then
s = [6,1,2,3,4,5][i/4]
fsize = r * 0.13
r5 = r * rdnum[1]
else
s = [0,6,12,18][i%4]
fsize = r * 0.07
r5 = r * rdnum[0]
end
s = s.to_s

x0 = r5 * Math.cos(ang) + cx
y0 = r5 * Math.sin(ang) + cy

cr.move_to(x0, y0)
cr.font_create(fontname)
cr.set_font_size(fsize)
cr.show_text(s)

end
6.times do |i|
ang = radians(360.0 * i / 6 - 90.0)
s = [-1,7,8,9,10,11][i]
next if s == -1
s = s.to_s
fsize = r * 0.07
r5 = r * rdnum[2]
x0 = r5 * Math.cos(ang) + cx
y0 = r5 * Math.sin(ang) + cy
cr.move_to(x0, y0)
cr.font_create(fontname)
cr.set_font_size(fsize)
cr.show_text(s)
end

end

end

tft = BsdTft.new(1, 0, BsdTft::S6D0151)

tft.setsize(W, H)
tft.setreset(RST)
tft.init

tft.cls(0)

c = Cairo.new(W, H)
c.set_source_rgb(1, 1, 1)
c.paint

cx = width / 2
cy = height / 2
rb = ([width,height].min) / 2

draw_watch(c, cx, cy, rb, fpsv, num_enable, fontname)

tft.lcdCopy(c.get_data)

文字の表示方法が違うところ以外はそのままでいけました。

写真(2019-05-02 8.38).jpg