SHOW:
|
|
- or go back to the newest paste.
1 | local tArg = {...} | |
2 | local monitor = peripheral.wrap( "up" ) | |
3 | - | local scr_x, scr_y = term.getSize() |
3 | + | local scr_x, scr_y = monitor.getSize() |
4 | local mx, my = scr_x/2, scr_y/2 | |
5 | ||
6 | -- special modes for special people | |
7 | local mouseMode = tArg[1] == "mouse" or tArg[2] == "mouse" | |
8 | local fuck = tArg[1] == "fuck" or tArg[2] == "fuck" | |
9 | ||
10 | -- localize functions to increase speed, maybe, I think | |
11 | - | local concat, blit = table.concat, term.blit |
11 | + | local concat, blit = table.concat, monitor.blit |
12 | local sin, cos, rad, abs, sqrt, floor = math.sin, math.cos, math.rad, math.abs, math.sqrt, math.floor | |
13 | ||
14 | -- rainbow pattern | |
15 | local palette = {"e","1","4","5","d","9","b","a","2"} | |
16 | ||
17 | local distance = function(x1, y1, x2, y2) | |
18 | return sqrt( (x2 - x1) ^ 2 + (y2 - y1) ^ 2 ) | |
19 | end | |
20 | ||
21 | local randCase = function(str) | |
22 | local output = "" | |
23 | for i = 1, #str do | |
24 | output = output .. ((math.random(0,1) == 1) and str:sub(i,i):upper() or str:sub(i,i):lower()) | |
25 | end | |
26 | return output | |
27 | end | |
28 | ||
29 | local render = function(iterate, xscroll1, yscroll1, xscroll2, yscroll2) | |
30 | local buffer, cx, cy = {{},{},{}} | |
31 | for y = 1, scr_y do | |
32 | buffer[1][y] = {} | |
33 | buffer[2][y] = {} | |
34 | buffer[3][y] = {} | |
35 | for x = 1, scr_x do | |
36 | cx = 0.66 * ((x - mx) > 0 and 1 or -1) * (abs(x - mx) ^ 1.2) | |
37 | cy = ((y - my) > 0 and 1 or -1) * (abs(y - my) ^ 1.2) | |
38 | ||
39 | buffer[1][y][x] = fuck and randCase("fuck"):sub(1+(cx%4),1+(cx%4)) or "\127" | |
40 | ||
41 | buffer[2][y][x] = palette[1 + floor( | |
42 | iterate + distance( cx + xscroll1, cy + yscroll1, 0, 0 ) | |
43 | ) % #palette] or " " | |
44 | ||
45 | buffer[3][y][x] = palette[1 + floor( | |
46 | iterate + distance( cx + xscroll2, cy + yscroll2, 0, 0 ) | |
47 | ) % #palette] or " " | |
48 | end | |
49 | end | |
50 | ||
51 | for y = 1, scr_y do | |
52 | - | term.setCursorPos(1,y) |
52 | + | monitor.setCursorPos(1,y) |
53 | -- suka | |
54 | blit( | |
55 | concat(buffer[1][y]), | |
56 | concat(buffer[2][y]), | |
57 | concat(buffer[3][y]) | |
58 | ) | |
59 | end | |
60 | end | |
61 | ||
62 | local main = function() | |
63 | - | term.clear() |
63 | + | monitor.clear() |
64 | local wave, evt = 0 | |
65 | local xscroll1, yscroll1, xscroll2, yscroll2 = 0, 0, 0, 0 | |
66 | if mouseMode then | |
67 | parallel.waitForAny(function() | |
68 | while true do | |
69 | evt = {os.pullEvent()} | |
70 | if evt[1] == "mouse_click" or evt[1] == "mouse_drag" then | |
71 | if evt[2] == 1 then | |
72 | xscroll1 = mx - evt[3] | |
73 | yscroll1 = my - evt[4] | |
74 | elseif evt[2] == 2 then | |
75 | xscroll2 = mx - evt[3] | |
76 | yscroll2 = my - evt[4] | |
77 | end | |
78 | end | |
79 | end | |
80 | end, | |
81 | function() | |
82 | while true do | |
83 | render(wave, xscroll1, yscroll1, xscroll2, yscroll2) | |
84 | wave = (wave + 1) % (360 * 7) | |
85 | sleep(0.05) | |
86 | end | |
87 | end) | |
88 | else | |
89 | while true do | |
90 | xscroll1 = -sin(rad(wave * 2)) * scr_x * 0.4 | |
91 | yscroll1 = -cos(rad(wave * 3.5)) * scr_y * 0.4 | |
92 | xscroll2 = -xscroll1 | |
93 | yscroll2 = -yscroll1 | |
94 | render(wave, xscroll1, yscroll1, xscroll2, yscroll2) | |
95 | wave = (wave + 1) % (360 * 7) | |
96 | sleep(0.05) | |
97 | end | |
98 | end | |
99 | end | |
100 | ||
101 | -- wait for keypress to exit program | |
102 | local waitForInput = function() | |
103 | local evt | |
104 | sleep(0.25) | |
105 | os.pullEvent("key") | |
106 | end | |
107 | ||
108 | parallel.waitForAny(main, waitForInput) | |
109 | - | term.clear() |
109 | + | monitor.clear() |
110 | - | term.setCursorPos(1,1) |
110 | + | monitor.setCursorPos(1,1) |
111 | sleep(0.05) |