Advertisement
Guest User

CC Circle API

a guest
Jan 24th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. function drawCircle( centerX, centerY, radius, col, solid )
  2.     solid = solid or false
  3.     local isAdvanced = term.isColor and term.isColor()
  4.     local char = isAdvanced and " " or "|"
  5.     if isAdvanced then term.setBackgroundColor( col ) end
  6.     local radStep = 1/(1.5*radius)
  7.     for angle = 1, math.pi+radStep, radStep do
  8.         local pX = math.cos( angle ) * radius * 1.5
  9.         local pY = math.sin( angle ) * radius
  10.         if solid then
  11.             local chord = math.abs(pX)
  12.             term.setCursorPos( centerX - chord/2, centerY - pY )
  13.             write( char:rep( chord ) )
  14.             term.setCursorPos( centerX - chord/2, centerY + pY )
  15.             write( char:rep( chord ) )
  16.         else
  17.             for i=-1,1,2 do
  18.                 for j=-1,1,2 do
  19.                     term.setCursorPos( centerX + i*pX, centerY + j*pY )
  20.                     write( char )
  21.                 end
  22.             end
  23.         end
  24.     end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement