Skip to content

Instantly share code, notes, and snippets.

@june29
Created January 2, 2011 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/762282 to your computer and use it in GitHub Desktop.
Save june29/762282 to your computer and use it in GitHub Desktop.
require "rubygems"
require "opengl"
require "glut"
include GL, Glut
MARGIN = 10
WIDTH = 34
HEIGHT = 12
SCALE = 15
LINE_WIDTH = 3
TOTAL_W = WIDTH + MARGIN * 2
TOTAL_H = HEIGHT + MARGIN * 2
class Kanji
def initialize(lines)
@lines = lines
end
def draw
@lines.each { |line|
GL.Begin LINES
Vertex3f (line.x1 + MARGIN) * 2 / TOTAL_W.to_f - 1.0,
- (line.y1 + MARGIN) * 2 / TOTAL_H.to_f + 1.0,
0.0
Vertex3f (line.x2 + MARGIN) * 2 / TOTAL_W.to_f - 1.0,
- (line.y2 + MARGIN) * 2 / TOTAL_H.to_f + 1.0,
0.0
GL.End
}
end
end
class Line
attr_reader :x1, :y1, :x2, :y2
def initialize(x1, y1, x2, y2)
@x1, @y1, @x2, @y2, = x1, y1, x2, y2
end
end
l00 = Line.new(3, 0, 3, 1)
l01 = Line.new(1, 1, 5, 1)
l02 = Line.new(2, 1, 2, 3)
l03 = Line.new(4, 1, 4, 3)
l04 = Line.new(0, 3, 6, 3)
l05 = Line.new(3, 3, 3, 6)
l06 = Line.new(1, 4, 5, 4)
c1 = Kanji.new([l00, l01, l02, l03, l04, l05, l06])
l07 = Line.new(10, 0, 6, 3 )
l08 = Line.new( 6, 3, 6, 9 )
l09 = Line.new( 6, 9, 10, 6 )
l10 = Line.new(10, 3, 10, 9 )
l11 = Line.new(10, 9, 6, 12 )
l12 = Line.new(12, 3, 12, 12 )
l13 = Line.new(12, 3, 16, 3 )
l14 = Line.new(16, 3, 16, 9 )
l15 = Line.new(16, 9, 14, 10.5)
c2 = Kanji.new([l07, l08, l09, l10, l11, l12, l13, l14, l15])
l16 = Line.new(19, 0, 16, 3)
l17 = Line.new(19, 0, 22, 3)
l18 = Line.new(18, 2, 20, 2)
l19 = Line.new(17, 3, 21, 3)
l20 = Line.new(19, 0, 19, 6)
l21 = Line.new(18, 5, 19, 6)
l22 = Line.new(20, 5, 19, 6)
l23 = Line.new(16, 6, 22, 6)
c3 = Kanji.new([l16, l17, l18, l19, l20, l21, l22, l23])
l24 = Line.new(22, 2, 28, 2)
l25 = Line.new(25, 0, 25, 6)
l26 = Line.new(25, 2, 22, 5)
l27 = Line.new(25, 2, 28, 5)
c4 = Kanji.new([l24, l25, l26, l27])
l28 = Line.new(16, 9, 22, 9)
l29 = Line.new(19, 6, 19, 12)
c5 = Kanji.new([l28, l29])
l30 = Line.new(25 , 6, 25, 8)
l31 = Line.new(22 , 8, 28, 8)
l32 = Line.new(25 , 8, 22, 12)
l33 = Line.new(24.25, 9, 27, 9)
l34 = Line.new(27 , 9, 27, 12)
l35 = Line.new(27 , 12, 26, 11)
c6 = Kanji.new([l30, l31, l32, l33, l34, l35])
l36 = Line.new(28 , 7 , 34, 7 )
l37 = Line.new(30 , 6.5 , 30, 7.5 )
l38 = Line.new(32 , 6.5 , 32, 7.5 )
l39 = Line.new(30 , 8 , 30, 9.5 )
l40 = Line.new(30 , 8 , 32, 8 )
l41 = Line.new(32 , 8 , 32, 9.5 )
l42 = Line.new(30 , 8.75, 32, 8.75)
l43 = Line.new(30 , 9.5 , 32, 9.5 )
l44 = Line.new(28 , 10 , 34, 10 )
l45 = Line.new(30.5, 9.5 , 28, 12 )
l46 = Line.new(31.5, 9.5 , 34, 12 )
l47 = Line.new(30 , 10.5 , 30, 12 )
l48 = Line.new(30 , 10.5 , 32, 10.5 )
l49 = Line.new(32 , 10.5 , 32, 12 )
l50 = Line.new(30 , 11.25, 32, 11.25)
l51 = Line.new(30 , 12 , 32, 12 )
c7 = Kanji.new([l36, l37, l38, l39, l40, l41, l42, l43,
l44, l45, l46, l47, l48, l49, l50, l51])
display = proc {
Clear(GL::COLOR_BUFFER_BIT)
Color3f 1.0, 1.0, 1.0
LineWidth(LINE_WIDTH)
[c1, c2, c3, c4, c5, c6, c7].each(&:draw)
glutSwapBuffers
}
timer = proc {
Rotate(1.0, 0.0, 1.0, 0.0)
Rotate(1.0, 0.0, 0.0, 0.2)
glutPostRedisplay
glutTimerFunc(100, timer, 0)
}
glutInit
glutInitWindowSize(*[WIDTH, HEIGHT].map { |e| (e + MARGIN * 2) * SCALE })
glutCreateWindow("Usagi")
glClearColor(0.0, 0.0, 0.0, 0.0)
glutDisplayFunc(display)
glutTimerFunc(100, timer, 0)
Enable(GL_LINE_SMOOTH);
Enable(GL_BLEND);
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment