class Bitmap def to_int self.object_id end # src_bitmap 源位图,必须与自身位图同尺寸 # wave_length 【无符号整型】 波长对应一个Math::PI # wave_amp 【无符号整型】 波高 # wave_speed 【基本整型】 影响波动快慢 # wave_phase 【基本整型】 波动起始的角度值(一般0...360) def wave(src_bitmap, wave_length, wave_amp, wave_speed = 1, wave_phase = 0) @src_bitmap = src_bitmap @wave_length = wave_length @wave_amp = wave_amp @wave_speed = wave_speed @wave_phase = wave_phase @waving = (wave_length * wave_amp * wave_speed != 0) # 说明用变量 @wave_step = Math::PI / wave_length @wave_dcos = Math.cos(@wave_step) * 2 end # 说明用方法: WaveH 的RGSS 实现 def wave_update return unless @waving self.clear rad = @wave_phase * Math::A2R s0 = Math.sin(rad) s1 = Math.sin(rad + @wave_step) s2 = 0 src_rect = Rect.new(0, 0, @src_bitmap.width, 1) self.blt((s0 * @wave_amp).round, 0, @src_bitmap, src_rect) src_rect.y += 1 self.blt((s1 * @wave_amp).round, 1, @src_bitmap, src_rect) 2.upto(self.height - 1) do |y| s2 = @wave_dcos * s1 - s0 s0, s1 = s1, s2 src_rect.y += 1 self.blt((s2 * @wave_amp).round, y, @src_bitmap, src_rect) end @wave_phase = (@wave_phase + @wave_speed) % 360 end dll = "Wave.dll" WaveH = Win32API.new(dll, 'bitmapWaveH', 'LLLLLL', 'V') def wave_update_dllH return unless @waving @wave_phase = WaveH.call(self, @src_bitmap, @wave_phase, @wave_length, @wave_amp, @wave_speed) end # 适用于250 * 250大小以下的位图 WaveV = Win32API.new(dll, 'bitmapWaveV', 'LLLLLL', 'L') def wave_update_dllV return unless @waving @wave_phase = WaveV.call(self, @src_bitmap, @wave_phase, @wave_length, @wave_amp, @wave_speed) end WaveV_line4 = Win32API.new(dll, 'bitmapWaveV_line4', 'LLLLLL', 'L') def wave_update_dllV_line4 return unless @waving @wave_phase = WaveV_line4.call(self, @src_bitmap, @wave_phase, @wave_length, @wave_amp, @wave_speed) end WaveHV = Win32API.new(dll, 'bitmapWaveHV', 'LLLLLL', 'L') def wave_update_dllHV return unless @waving @wave_phase = WaveHV.call(self, @src_bitmap, @wave_phase, @wave_length, @wave_amp, @wave_speed) end end src = Bitmap.new("temp2.jpeg") #src.fill_rect(src.rect, Color.new(0, 255, 255)) sprite = Sprite.new sprite.bitmap = Bitmap.new(src.width, src.height) sprite.bitmap.wave(src, 50, 10, 2, 0) sprite.x = 320 sprite.y = 240 sprite.ox = src.width / 2 sprite.oy = src.height / 2 str = "Bitmap(#{src.width} * #{src.height})\n" count, t = 0, Time.now loop do sprite.bitmap.wave_update_dllH break if Time.now - t >= 1.0 count += 1 end str << "Bitmap#wave_update_dllH => #{count} 次/秒\n" count, t = 0, Time.now loop do sprite.bitmap.wave_update_dllV break if Time.now - t >= 1.0 count += 1 end str << "Bitmap#wave_update_dllV => #{count} 次/秒\n" count, t = 0, Time.now loop do sprite.bitmap.wave_update_dllV_line4 break if Time.now - t >= 1.0 count += 1 end str << "Bitmap#wave_update_dllV_line4 => #{count} 次/秒\n" count, t = 0, Time.now loop do sprite.bitmap.wave_update_dllHV break if Time.now - t >= 1.0 count += 1 end str << "Bitmap#wave_update_dllHV => #{count} 次/秒\n" print str loop do Graphics.update #sprite.bitmap.wave_update_dllH #sprite.bitmap.wave_update_dllV #sprite.bitmap.wave_update_dllV_line4 sprite.bitmap.wave_update_dllHV end
temp.png (18.04 KB, 下载次数: 17)
迭代计算的误差
waveHV.jpg (114.15 KB, 下载次数: 14)
WaveHV的示意图
waveHV.gif (900.74 KB, 下载次数: 17)
4.31 KB, 下载次数: 6
Wave.dll
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |