Advertisement
King0fGamesYami

Ripple V3

Dec 22nd, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. --[[local function getY( centerx, centery, radius, x )
  2.     local origin = math.sqrt( radius^2 - (x - centerx) ^2 )
  3.     return math.floor(centery + origin), math.floor(centery - origin)
  4. end
  5. ]]
  6.  
  7. local tCircles = {}
  8. local function drawCircle( centerX, centerY, radius, col, solid )
  9.     solid = solid or false
  10.     local isAdvanced = term.isColor and term.isColor()
  11.     local char = isAdvanced and " " or "|"
  12.     if isAdvanced then term.setBackgroundColor( col ) end
  13.     local radStep = 1/(1.5*radius)
  14.     for angle = 1, math.pi+radStep, radStep do
  15.         local pX = math.cos( angle ) * radius * 1.5
  16.         local pY = math.sin( angle ) * radius
  17.         if solid then
  18.             local chord = 2*math.abs(pX)
  19.             term.setCursorPos( centerX - chord/2, centerY - pY )
  20.             write( char:rep( chord ) )
  21.             term.setCursorPos( centerX - chord/2, centerY + pY )
  22.             write( char:rep( chord ) )
  23.         else
  24.             for i=-1,1,2 do
  25.                 for j=-1,1,2 do
  26.                     term.setCursorPos( centerX + i*pX, centerY + j*pY )
  27.                     write( char )
  28.                 end
  29.             end
  30.         end
  31.     end
  32. end
  33.  
  34. local tWindows = { ["term"] = window.create( term.current(), 1, 1, term.getSize() ) }
  35.  
  36. local id = os.startTimer( 0.1 )
  37.  
  38. while true do
  39.     local event = { os.pullEvent() }
  40.     if event[ 1 ] == "mouse_click" then
  41.         tCircles[ #tCircles + 1 ] = { parent = "term", r = 1, x = event[ 3 ], y = event[ 4 ] }
  42.     elseif event[ 1 ] == "monitor_touch" then
  43.         if not tWindows[ event[ 2 ] ] then
  44.             peripheral.call( event[ 2 ], "setTextScale", 0.5 )
  45.             tWindows[ event[ 2 ] ] = window.create( peripheral.wrap( event[ 2 ] ), 1, 1, peripheral.call( event[ 2 ], "getSize" ) )
  46.         end
  47.         tCircles[ #tCircles + 1 ] = { parent = event[ 2 ], r = 1, x = event[ 3 ], y = event[ 4 ] }
  48.     elseif event[ 1 ] == "timer" and event[ 2 ] == id then
  49.         id = os.startTimer( 0.1 )
  50.         for k, v in pairs( tWindows ) do
  51.             v.setVisible( false )
  52.             v.setBackgroundColor( colors.lightBlue )
  53.             v.clear()
  54.         end
  55.         local origin = term.current()
  56.         for i, circle in pairs( tCircles ) do
  57.             local t = tWindows[ circle.parent ]
  58.             local maxx, maxy = t.getSize()
  59.             term.redirect( t )
  60.             --[[
  61.             for x = 1, maxx, 0.75 / circle.r do
  62.                 local y1, y2 = getY( circle.x, circle.y, circle.r, x )
  63.                 t.setCursorPos( x, y1 )
  64.                 t.write( " " )
  65.                 t.setCursorPos( x, y2 )
  66.                 t.write( " " )
  67.             end
  68.             ]]--
  69.             drawCircle( circle.x, circle.y, circle.r, colors.blue, false )
  70.             circle.r = circle.r + 1
  71.             if circle.r > ( maxx / 2 ) then
  72.                 table.remove( tCircles, i )
  73.             end
  74.         end
  75.         term.redirect( origin )
  76.         for _, v in pairs( tWindows ) do
  77.             v.setVisible( true )
  78.             v.redraw()
  79.         end
  80.     end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement