Advertisement
Doob

[OpenComputers] pnt

Aug 30th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. local component = require('component')
  2. local event = require('event')
  3. local gpu = component.gpu
  4. local color = 0xFF0000
  5. local tSize = {gpu.getResolution()}
  6.  
  7. local function line(x0, y0, x1, y1)
  8.   local dx = x1 - x0
  9.   local dy = y1 - y0
  10.   local d = 2 * dy - dx
  11.   set_pixel(x0, y0)
  12.   y = y0
  13.   for x = x0, x1 do
  14.     if d > 0 then
  15.       y = y + 1
  16.       set_pixel(x, y)
  17.       d = d + (2 * dy - 2 * dx)
  18.     else
  19.       set_pixel(x, y)
  20.       d = d + (2 * dy)
  21.     end
  22.   end
  23. end
  24.  
  25. local function circle(x0, y0, radius)
  26.   local x = radius
  27.   local y = 0
  28.   local d = 1 - x
  29.   while x >= y do
  30.     set_pixel(x + x0, y + y0)
  31.     set_pixel(y + x0, x + y0)
  32.     set_pixel(-x + x0, y + y0)
  33.     set_pixel(-y + x0, x + y0)
  34.     set_pixel(-x + x0, -y + y0)
  35.     set_pixel(-y + x0, -x + y0)
  36.     set_pixel(x + x0, -y + y0)
  37.     set_pixel(y + x0, -x + y0)
  38.     y = y + 1
  39.     if d <= 0 then
  40.       d = 2 * y + 1
  41.     else
  42.       x = x - 1
  43.       d = 2 * (y - x) + 1
  44.     end
  45.   end
  46. end
  47.  
  48. local function box(x0, y0, x1, y1)
  49.   for x = x0, x1 do
  50.     for y = y0, y1 do
  51.       set_pixel(x, y)
  52.     end
  53.   end
  54. end
  55.  
  56. local function clear()
  57.   gpu.setBackground(0x000000)
  58.   gpu.setForeground(0x000000)
  59.   gpu.fill(1, 1, tSize[1], tSize[2], ' ')
  60. end
  61.  
  62. local function fill_1()
  63.   local fg, bg = 0x000000, 0x222222
  64.   for x = 1, tSize[1], 2 do
  65.     for y = 1, tSize[2] do
  66.       gpu.setBackground(bg)
  67.       gpu.setForeground(fg)
  68.       gpu.set(x, y, '▄')
  69.       gpu.setBackground(fg)
  70.       gpu.setForeground(bg)
  71.       gpu.set(x+1, y, '▄')
  72.     end
  73.   end
  74. end
  75.  
  76. clear()
  77.  
  78. while 1 do
  79.   local e = {event.pull()}
  80.   if e[1] == 'touch' or e[1] == 'drag' or e[1] == 'drop' then
  81.     local pixel = {gpu.get(e[3], e[4])}
  82.     if e[5] == 0 then
  83.       gpu.setForeground(color)
  84.       gpu.setBackground(pixel[3])
  85.       gpu.set(e[3], e[4], '▄')
  86.     elseif e[5] == 1 then
  87.       gpu.setForeground(pixel[2])
  88.       gpu.setBackground(color)
  89.       gpu.set(e[3], e[4], '▄')  
  90.     end
  91.   end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement