Advertisement
electronic_steve

test

Mar 29th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. while not shell.run("ESGraphics") do
  2. shell.run("pastebin","get","kDm3zq5E","ESGraphics")
  3. if  shell.run("ESGraphics") then print("ESGraphics launched") else print("ESGraphics not exist") end
  4.  end
  5. arg={...}
  6. radius=arg[1]
  7.  
  8. Model={}
  9.  
  10. LR={}
  11.  
  12.  
  13. scrX = {}
  14. scrY = {}
  15. zoom=30
  16. render={}
  17.  
  18. render[1]= function() --рендер 2
  19.   for i = 1, #Model, 1 do
  20.  
  21. local SX=limit(scrX[i],r.sx)
  22. local SY=limit(scrY[i],r.sy)
  23.   -- gh.text(1,1,1,16,"x:"..SX.."/"..r.sx)
  24.   -- gh.text(1,2,1,16,"y:"..SY.."/"..r.sy)
  25.  
  26.       gh.point(SX, SY,1,1," ")
  27.   for n = 1, #Model, 1 do
  28.  
  29. local SSX=limit(scrX[n],r.sx)
  30. local SSY=limit(scrY[n],r.sy)
  31.    gh.line(SX, SY,SSX,SSY,1,0,".")
  32. end
  33.      
  34.    
  35.    
  36.      end
  37.    
  38. end
  39. function limit(n,n1)
  40. local x=math.min(n,n1)
  41.  
  42. local nx=math.max(1,x)
  43.  
  44. return nx
  45.  
  46. end
  47. s = {}
  48. c1 = {}
  49.  
  50. PI = math.pi
  51.  
  52. for i = 1, 360, 1 do
  53.    s[i] = math.sin(i * (PI / 180))
  54.    c1[i] =  math.cos(i * (PI / 180))
  55.  
  56. end
  57.  
  58. function createsphere(R,quality)
  59.  
  60. local mapX=R
  61. local mapY=R
  62. local mapZ=R
  63. local map={}
  64.  
  65.  
  66.  
  67.  
  68. for x=-mapZ,mapX,1 do
  69. map[x]={}
  70. for y=-mapY,mapY,1 do
  71. map[x][y]={}
  72. for z=-mapZ,mapZ,1 do
  73. map[x][y][z]=false
  74.  
  75. end
  76. end
  77. end
  78. local i=0
  79. for RX=0,math.pi,quality do
  80. for RY=0,2*math.pi,quality do
  81. local x= R*math.sin(RX)*math.cos(RY)
  82. local y= R*math.sin(RX)*math.sin(RY)
  83. local z= R*math.cos(RX)
  84. i=i+1
  85.  
  86. map[math.floor(x)][math.floor(y)][math.floor(z)]=true
  87. end
  88. end  
  89. return map
  90. end
  91.  
  92.  
  93.  
  94.  
  95.  
  96. map=createsphere(radius,0.7)
  97. for x=-radius,radius,1 do
  98.  
  99. for y=-radius,radius,1 do
  100.  
  101. for z=-radius,radius,1 do
  102. if map[x][y][z] then
  103. Model[#Model+1]={x*10,y*10,z*10}
  104.  
  105. end
  106. end end end
  107. -- модель
  108.  
  109. for i = 1, #Model, 1 do
  110.    LR[i] = {0,0,0}
  111.  
  112.    scrX[i] = 0
  113.    scrY[i] = 0
  114. end
  115.  
  116. xCenter = math.floor(r.sx/2)
  117. yCenter = math.floor(r.sy/2)
  118. zCenter = 256
  119. HROT = 0
  120. VROT = 0
  121. HROTSpeed = 1
  122. VROTSpeed = 1
  123.  
  124. function ftw()
  125.    for i = 1, #Model, 1 do
  126.       LR[i][1] = (Model[i][1] * -1) * s[HROT+1] + Model[i][2] * c1[HROT+1] -- вычисление вершин
  127.       LR[i][2] = (Model[i][1] * -1) * c1[HROT+1] *s[VROT+1] - Model[i][2] * s[HROT+1] * s[VROT+1] - Model[i][3] * c1[VROT+1] + 1
  128.       LR[i][3] = (Model[i][1] * -1) * c1[HROT+1] *c1[VROT+1] - Model[i][2] * s[HROT+1] * c1[VROT+1] + Model[i][3] * s[VROT+1]
  129.  
  130.      
  131.  
  132.       if (LR[i][3] + zCenter) ~= 0 then
  133.          scrX[i] = math.floor(zoom * (LR[i][1] / (LR[i][3] + zCenter)) + xCenter)
  134.          scrY[i] = math.floor(zoom * (LR[i][2] / (LR[i][3] + zCenter)) + yCenter)
  135.       end
  136.  
  137.  
  138.    end
  139.    render[1]()
  140.  
  141.  
  142.   HROT =math.mod( HROT + HROTSpeed,360,0)-- повороты
  143.    VROT =math.mod( VROT + VROTSpeed,360,0)
  144.  
  145.  
  146.  
  147. end
  148.  
  149.  
  150. function math.mod(n,max,x)
  151. if n>=max then n=x end
  152. return n
  153. end
  154. function draw()
  155. ftw()
  156. end
  157. function update()
  158.  
  159. end
  160.  
  161. while true do
  162. r.systemupdate()
  163. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement