04 - FractalBlue.lua

Last-modified: 2009-02-06 (金) 09:34:22

(scrpts/04 - FractalBlue.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:for i=0,(depth-2) do
15:	b = math.floor(i / depth * 128)
16:	if b > 31 then
17:		b = 31
18:	end
19:	g = math.floor((i - depth / 3) / depth * 128)
20:	if g > 31 then
21:		g = 31
22:	end
23:	if g < 0 then
24:		g = 0
25:	end
26:	r = math.floor((i - depth / 3 * 2) / depth * 128)
27:	if r > 31 then
28:		r = 31
29:	end
30:	if r < 0 then
31:		r = 0
32:	end
33:  BGTopBit8:SetPaletteColor( i, r, g, b )
34:end
35:BGTopBit8:SetPaletteColor( depth-1, 0, 0, 0 )
36:
37:BGBotText:PrintXY( 0, 0, "Please wait..." )
38:
39:w = 256
40:h = 192
41:dx = x1 - x0
42:dy = y1 - y0
43:for y=0,h-1 do
44:	for x=0,w-1 do
45:		r = 0; n = 0; b = x / w * dx + x0; e = y / h * dy + y0; i = 0
46:		while i < depth-1 and r * r < 4 do
47:			d = r
48:      r = r * r - n * n + b
49:      n = 2 * d * n + e
50:      i = i + 1
51:		end
52:    BGTopBit8:Plot( x, y, i )
53:	end
54:end
55:
56:while true do
57:  BGBotText:PrintXY( 0, 0, "Press any button to exit" )
58:  if Pads.AnyKey() then
59:    break
60:  end
61:  Screen.WaitForVBL()
62: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:for i=0,(depth-2) do
15:	b = math.floor(i / depth * 128)
16:	if b > 31 then
17:		b = 31
18:	end
19:	g = math.floor((i - depth / 3) / depth * 128)
20:	if g > 31 then
21:		g = 31
22:	end
23:	if g < 0 then
24:		g = 0
25:	end
26:	r = math.floor((i - depth / 3 * 2) / depth * 128)
27:	if r > 31 then
28:		r = 31
29:	end
30:	if r < 0 then
31:		r = 0
32:	end
33:  BGTopBit8:SetPaletteColor( i, r, g, b )
34:end
35:BGTopBit8:SetPaletteColor( depth-1, 0, 0, 0 )
36:
37:BGBotText:PrintXY( 0, 0, "Please wait..." )
38:
39:w = 256
40:h = 192
41:dx = x1 - x0
42:dy = y1 - y0
43:for y=0,h-1 do
44:	for x=0,w-1 do
45:		r = 0; n = 0; b = x / w * dx + x0; e = y / h * dy + y0; i = 0
46:		while i < depth-1 and r * r < 4 do
47:			d = r
48:      r = r * r - n * n + b
49:      n = 2 * d * n + e
50:      i = i + 1
51:		end
52:    BGTopBit8:Plot( x, y, i )
53:	end
54:end
55:
56:while true do
57:  BGBotText:PrintXY( 0, 0, "Press any button to exit" )
58:  if Pads.AnyKey() then
59:    break
60:  end
61:  Screen.WaitForVBL()
62:end

コメント