RGSS3的交互式Console

用RGSS3画Julia集

Vector29 posted @ 2012年2月02日 19:46 in RGSS with tags RGSS3 Complex Julia , 1853 阅读

偶然间发现RGSS3内部定义了Complex类,于是拿他画了个Julia集.

 

以下为代码:

#===============================================================================
# Julia Set                                                        by Vctor29
#-------------------------------------------------------------------------------
# last update : 2012/2/3 23:06
#===============================================================================
 
Graphics.resize_screen(640, 480)
 
$sprite = Sprite.new 
$sprite.bitmap = Bitmap.new(640, 480) 
 
z = Complex(0, 0) 
c = Complex(-0.8, 0.156)
 
t = Time.now 
 
for x in 0..640 
  Graphics.update 
  for y in 0..480 
    z = Complex(-1.6 + x / 200.0, -1.2 + y / 200.0) 
    for k in 0..180 
      if z.real * z.real + z.imag * z.imag > 4.0 
        break 
      end 
      z = z * z + c 
    end 
    $sprite.bitmap.set_pixel(x, y, Color.new(0, k / 1.3, k * 1.3)) 
  end 
end 

msgbox "Done : #{Time.now - t}s" 
loop {Graphics.update}
  • 无匹配

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter