File: gradation.rb

package info (click to toggle)
tdiary 2.0.1-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,220 kB
  • ctags: 1,667
  • sloc: ruby: 20,044; lisp: 476; makefile: 91; sql: 32; sh: 31
file content (33 lines) | stat: -rw-r--r-- 910 bytes parent folder | download
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
# gradation.rb $Revision: 1.1 $
#
# gradation.rb: ʸ򥰥ǡɽ
#   ѥ᥿:
#     str:         ʸ
#     first_color: ǡ󳫻Ͽ(16 6)
#     last_color:  ǡλ(16 6)
#
# Copyright (C) 2002 by zoe <http://www.kasumi.sakura.ne.jp/~zoe/tdiary/>
#
# Original: http://www.kasumi.sakura.ne.jp/~zoe/tdiary/?date=20011229#p07
# Modified: by TADA Tadashi <http://sho.tdiary.net/>
#
def gradation( str, first_color, last_color )
	ary = str.split( // )
	len = ary.length - 1
	result = ""
	r = first_color[0..1].hex.to_f
	g = first_color[2..3].hex.to_f
	b = first_color[4..5].hex.to_f
	rd = ((last_color[0..1].hex - r)/len)
	gd = ((last_color[2..3].hex - g)/len)
	bd = ((last_color[4..5].hex - b)/len)
	ary.each do |x|
		c = sprintf( '%02x%02x%02x', r, g, b )
		result << %Q[<span style="color: ##{c}">#{x}</span>]
		r += rd
		g += gd
		b += bd
	end
	result
end