サーモグラフィー作成のためのRGB値の指定方法 - Ryota’s Research Diary
先に実行結果を
0.0から1.0までの値をとって、RGBを算出してカラーを設定します。
コードは以下。
gl_color.rb
module GL def GL.ThermoColor(t) case t when 0.0 .. 0.2 r=0; g=0; b=5*t when 0.2 .. 0.4 r=0; g=5*t-1; b=1 when 0.4 .. 0.6 r=0; g=1; b=3-5*t when 0.6 .. 0.8 r=5*t-3; g=1; b=0 when 0.8 .. 1.0 r=1; g=5-5*t; b=0 else r=1; g=1; b=1 end GL.Color(r,g,b) end end if $0 == __FILE__ HEIGHT = 400 WIDTH = 200 def display GL.Clear(GL::COLOR_BUFFER_BIT) hStep = 2.0/100 steps = 400 steps.times{|t| h = 2*t.to_f/steps - 1.0 GL.ThermoColor(t.to_f/steps) GL.Begin(GL::POLYGON) GL.Vertex(-1, h) GL.Vertex(1, h) GL.Vertex(1, h+hStep) GL.Vertex(-1, h+hStep) GL.End } GL.Flush() end GLUT.Init() GLUT.InitWindowSize(WIDTH, HEIGHT) GLUT.InitDisplayMode(GLUT::RGB) GLUT.CreateWindow("Thermo Color Sample") GLUT.DisplayFunc(method(:display).to_proc) GL.ClearColor(1.0, 1.0, 1.0, 1.0) GLUT.MainLoop(); end
0 件のコメント:
コメントを投稿