Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- local tArgs={...}
- loading = false
- if shell==nil then
- loading=true
- end
- tx,ty=term.getSize()
- tx,ty=math.floor(tx),math.floor(ty)
- pi=math.pi
- px=tx/2
- py=ty/2
- points={}
- if #tArgs>1 then
- if tonumber(tArgs[1]) and tonumber(tArgs[2]) then
- if tonumber(tArgs[2])/4~=math.floor(tonumber(tArgs[2])/4) then
- print("Usage: circles [radius] [npts]")
- print("npts must be divisible by 4")
- error()
- end
- r=tonumber(tArgs[1])
- d=tonumber(tArgs[2])
- else
- print("Usage: circles [radius] [npts]")
- error()
- end
- elseif not loading then
- print("Usage: circles [radius] [npts]")
- error()
- end
- --End Variables
- --Formulas/Functions
- local function getPoints(a)
- x = r * math.cos(a)
- y = r * math.sin(a)
- return x,y
- end
- ----Below functions are if you are using me as an API
- function setX(xval)
- local sxv = tostring(xval)
- local pos=0
- repeat
- pos=pos+1
- until sxv:sub(pos,pos)=="." or pos==#sxv
- if pos==#sxv then pos=pos+1 end
- local num=tonumber(sxv:sub(1,pos-1))+0.5
- px=num
- end
- function setY(yval)
- local syv = tostring(yval)
- local pos=0
- repeat
- pos=pos+1
- until syv:sub(pos,pos)=="." or pos==#syv
- if pos==#syv then pos=pos+1 end
- local num=tonumber(syv:sub(1,pos-1))+0.5
- py=num
- end
- function drawCircle(ra,da,cls)
- if ra and da then else
- return false
- end
- r=ra
- d=da
- ----Above functions are if you are using me as an API
- --End Formulas/Functions
- --[[ DEPRECATED
- repeat
- repeat
- shell.run("clear")
- write("Radius:")
- r = tonumber(read())
- until r~=nil
- until r>0
- repeat
- repeat
- shell.run("clear")
- write("Points (Must be divisible by 4):")
- d = tonumber(read())
- until d~=nil
- until d>3 and d/4==math.floor(d/4)
- ]]-- DEPRECATED
- if not loading and cls then shell.run("clear") elseif cls
- term.clear()
- end
- --Get All Points
- for i=1,4 do
- ip=d/4
- cpi=(pi/2)*(i-1)
- npi=(pi/2)*(i)
- for j=0,ip-1 do
- a=j*(pi/(ip+3))+cpi
- nx,ny = getPoints(a)
- table.insert(points,{nx,ny})
- --print("Angle: "..a)
- end
- end
- --End Point Getting
- term.setBackgroundColor(colors.white)
- for i=1,#points do
- --print(points[i][1])
- --print(points[i][2])
- term.setCursorPos(px-points[i][1],py-points[i][2])
- write(" ")
- end
- term.setBackgroundColor(colors.black)
- return true
- end
- if #tArgs>1 then drawCircle(r,d) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement