Ломанная в движении (Иллюзия 3D)

Sep 5th, 2017
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. local size = 4 -- Больше 4 начинается мерцание некоторых линий
2. local x0,y0 = 160,50
3.
4. local component = require("component")
5. local gpu = component.gpu
6. local term = require('term')
7.
8. function line(x1,y1,x2,y2)
9.     x= x1
10.     y= y1
11.     for i = 1 , math.floor( ( (x2-x1 )^2+( y1-y2 )^2)^0.5) do
12.         gpu.set(math.floor(x),math.floor(y),'█')
13.
15.         x = x + math.cos(rad)
16.         y = y - math.sin(rad)
17.     end
18. end
19.
20. local t = {}
21.
22. function rnd()
23.     if math.random(0,1) == 0 then
24.         return -1
25.     else
26.         return 1
27.     end
28. end
29.
30. for i = 1, size do
31.     t[i] = {['x'] = math.random(1,120),['y'] = math.random(1,50),['dx'] = rnd(),['dy'] = rnd()}
32. end
33.
34. term.clear()
35.
36. while true do
37.     for i = 1, size do
38.         t[i].x = t[i].x + t[i].dx
39.         t[i].y = t[i].y + t[i].dy
40.
41.         if t[i].x > x0 then t[i].dx = -1 end
42.         if t[i].y > y0 then t[i].dy = -1 end
43.         if t[i].x < 1 then t[i].dx = 1 end
44.         if t[i].y < 1 then t[i].dy = 1 end
45.     end
46.     for i = 1, size-1 do
47.         line(t[i].x,t[i].y,t[i+1].x,t[i+1].y)
48.     end
49.     line(t[1].x,t[1].y,t[size].x,t[size].y)
50.     os.sleep(0.001)
51.     term.clear()
52. end