(scrpts/04 - Fractal.lua)
01:SCREEN_BOTTOM = 0 02:SCREEN_TOP = 1 03:BGTopBit8 = Screen.Load8BitBG() 04:BGBotText = Screen.LoadTextBG() 05:Screen.Initialize( SCREEN_TOP, BGTopBit8 ) 06:Screen.Initialize( SCREEN_BOTTOM, BGBotText ) 07: 08:depth = 256 09:x0 = -0.65 10:y0 = -0.7 11:x1 = -0.5 12:y1 = -0.6 13: 14:nR = 0 15:nG = 0 16:nB = 0 17:nDiff = 4 18:for nLoop=0,(depth-1) do 19: BGTopBit8:SetPaletteColor( nLoop, nR, nG, nB ) 20: nR = nR+nDiff 21: if nR>31 then 22: nR = 0 23: nG = nG+nDiff 24: end 25: if nG>31 then 26: nG = 0 27: nB = nB+nDiff 28: end 29: if nB>31 then 30: nB=0 31: end 32:end; 33: 34:BGBotText:PrintXY( 0, 0, "Please wait..." ) 35: 36:w = 256 37:h = 192 38:dx = x1 - x0 39:dy = y1 - y0 40:for y=0,h-1 do 41: for x=0,w-1 do 42: r = 0; n = 0; b = x / w * dx + x0; e = y / h * dy + y0; i = 0 43: while i < depth-1 and r * r < 4 do 44: d = r 45: r = r * r - n * n + b 46: n = 2 * d * n + e 47: i = i + 1 48: end 49: BGTopBit8:Plot( x, y, i ) 50: end 51:end 52: 53:while true do 54: BGBotText:PrintXY( 0, 0, "Press any button to exit" ) 55: if Pads.AnyKey() then 56: break 57: end 58: Screen.WaitForVBL() 59:end
プログラムの解説
01:SCREEN_BOTTOM = 0 02:SCREEN_TOP = 1 03:BGTopBit8 = Screen.Load8BitBG() 04:BGBotText = Screen.LoadTextBG() 05:Screen.Initialize( SCREEN_TOP, BGTopBit8 ) 06:Screen.Initialize( SCREEN_BOTTOM, BGBotText ) 07: 08:depth = 256 09:x0 = -0.65 10:y0 = -0.7 11:x1 = -0.5 12:y1 = -0.6 13: 14:nR = 0 15:nG = 0 16:nB = 0 17:nDiff = 4 18:for nLoop=0,(depth-1) do 19: BGTopBit8:SetPaletteColor( nLoop, nR, nG, nB ) 20: nR = nR+nDiff 21: if nR>31 then 22: nR = 0 23: nG = nG+nDiff 24: end 25: if nG>31 then 26: nG = 0 27: nB = nB+nDiff 28: end 29: if nB>31 then 30: nB=0 31: end 32:end; 33: 34:BGBotText:PrintXY( 0, 0, "Please wait..." ) 35: 36:w = 256 37:h = 192 38:dx = x1 - x0 39:dy = y1 - y0 40:for y=0,h-1 do 41: for x=0,w-1 do 42: r = 0; n = 0; b = x / w * dx + x0; e = y / h * dy + y0; i = 0 43: while i < depth-1 and r * r < 4 do 44: d = r 45: r = r * r - n * n + b 46: n = 2 * d * n + e 47: i = i + 1 48: end 49: BGTopBit8:Plot( x, y, i ) 50: end 51:end 52: 53:while true do 54: BGBotText:PrintXY( 0, 0, "Press any button to exit" ) 55: if Pads.AnyKey() then 56: break 57: end 58: Screen.WaitForVBL() 59:end