ブレゼンハム直線描画その3(Ruby/SDL)
アルゴリズムと描画を分けると、いろいろ面白いことができるな。
別にドット描画じゃなくても良い訳で、ビットマップとか円も直線で描ける。
まあ、物体の直線進行のアニメーションにも使えそうだ。
前回のソースの後半を以下のように置き換えてみた。('testicon.bmp'が必要)
・・・
SDL.init( SDL::INIT_VIDEO )
screen = SDL.setVideoMode(640, 480, 16, SDL::SWSURFACE )
image = SDL::Surface.load('testicon.bmp')
image = image.displayFormat
b_draw_line(100,100,400,200) {|x,y|
SDL.blitSurface(image, 0,0,0,0, screen, x, y) if x%8==0
}
b_draw_line(600,400,400,200) {|x,y|
screen.draw_circle(x,y,8,[255,100,255]) if x%8==0
}
screen.updateRect(0,0,0,0)
loop do
while event = SDL::Event2.poll
case event
when SDL::Event2::Quit, SDL::Event2::KeyDown
exit
end
end
end
2013-09-07 23:32
nice!(0)
コメント(0)
トラックバック(0)
コメント 0