View difference between Paste ID: vNmFEPpJ and hxbndyif
SHOW: | | - or go back to the newest paste.
1-
platform.apilevel = '2.4'     
1+
-- Localized math functions for faster access
2-
time=0
2+
local mathfloor = math.floor
3
local mathsqrt = math.sqrt
4
local mathsin = math.sin
5
6
-- Globals
7
screen1 = {}
8-
w=platform.window:width()
8+
9-
h=platform.window:height()
9+
10
screenlist = {}
11
screencount = 0
12
pallet = {}
13
plasma = {}
14-
      time=timer.getMilliSecCounter()/10
14+
w = platform.window:width()
15-
    local x = 0    
15+
h = platform.window:height()
16-
    local y=0     
16+
tsize = 5
17
18-
    while (x<w) do
18+
function on.arrowDown()
19-
    while (y<h) do
19+
    if tsize > 1 then tsize = tsize - 1 end
20-
    tempcol = math.floor((plasma[x][y]+ time) %256)
20+
end
21-
    color_r = math.floor(pallet[tempcol].r)
21+
function on.arrowUp()
22-
    color_g = math.floor(pallet[tempcol].g)
22+
    if tsize < 15 then tsize = tsize + 1 end
23-
    color_b = math.floor(pallet[tempcol].b)
23+
end
24
25-
    gc:setColorRGB(color_r,color_g,color_b)
25+
function on.resize(ww,hh)
26-
     gc:fillRect(x,y,5,5)
26+
    timer.stop()
27-
       y = y +5
27+
    w,h = ww,hh
28
    init()
29-
    x=x+5
29+
end
30-
    y=0
30+
31
function on.paint(gc)
32-
        screencount = screencount +1
32+
    local time = timer.getMilliSecCounter() / 10
33-
         if (screencount >2) then 
33+
    local x,y = 0,0
34-
             screencount = 0 
34+
    while (x < w) do
35-
         end  
35+
        while (y < h) do
36-
   time=math.random(255)
36+
            local color = pallet[mathfloor((plasma[x][y] + time) % 256)]
37
            gc:setColorRGB(color.r, color.g, color.b)
38-
  end
38+
            gc:fillRect(x, y, tsize, tsize)
39-
 
39+
            y = y + tsize
40-
 
40+
        end
41-
 function dist(a,b,c,d)
41+
        x = x + tsize
42-
    return math.sqrt(((a - c) * (a - c) + (b - d) * (b - d)))
42+
        y = 0
43
    end
44
    screencount = (screencount + 1) % 3
45-
  function on.timer()
45+
46-
  time  = timer.getMilliSecCounter()/1000
46+
end
47-
  platform.window:invalidate()
47+
48-
  end
48+
49-
  
49+
function dist(a, b, c, d)
50-
  
50+
    return mathsqrt(((a - c) * (a - c) + (b - d) * (b - d)))
51-
  function on.construction()
51+
end
52-
  r=0
52+
53-
  g=0
53+
function on.timer()
54-
  b=0
54+
    timer.stop()
55-
  for i=0,256 do
55+
    platform.window:invalidate()
56-
  pallet[i]={r=math.floor(128.0 + 128 * math.sin(3.1415 * i/ 16.0)),g=math.floor(128.0 + 128 * math.sin(3.1415 * i / 128.0)),b=0}
56+
end
57-
  end
57+
58-
  
58+
function init()
59-
  for a=0,w do
59+
    pallet = {}
60-
  plasma[a] = {}
60+
    plasma = {}
61-
  for b=0,h do
61+
62-
  plasma[a][b] = math.floor(
62+
    local r,g,b = 0,0,0
63-
                128.0 + (128.0 * math.sin(a / 16.0))
63+
    for i = 0, 256 do
64-
              + 128.0 + (128.0 * math.sin(b / 16.0))
64+
        pallet[i] = { r = mathfloor(128.0 + 128 * mathsin(3.1416 * i / 16.0)),
65-
          ) /2
65+
                      g = mathfloor(128.0 + 128 * mathsin(3.1416 * i / 128.0)),
66-
   end
66+
                      b = 0 }
67-
   end
67+
68-
  
68+
69-
  
69+
    for a = 0, w do
70-
  
70+
        plasma[a] = {}
71-
  end
71+
        for b = 0, h do
72
            plasma[a][b] = mathfloor(128.0 + (128.0 * mathsin(a / 16.0)) + 128.0 + (128.0 * mathsin(b / 16.0))) / 2
73
        end
74
    end
75
    
76
    timer.start(0.01)
77
end
78
79
init()