Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- print(" Analog Clock ")
- sleep(3.0)
- gpuCount = 0
- gpus = {}
- gpuSide = ""
- --detecting gpus
- sides = {"back","front","left","right","top"}
- for i = 1, 5, 1 do
- if peripheral.isPresent(sides[i]) then
- if peripheral.getType(sides[i]) == "gpu" then
- gpuCount = gpuCount + 1 --increasing gpu count
- table.insert(gpus, (#gpus + 1), sides[i]) --adding gpu to list
- end
- end
- end
- --tell User
- exit = false
- if gpuCount == 0 then
- print("No gpu found!")
- exit = true
- elseif (gpuCount > 1) then
- print("More than 1 gpu found!")
- print()
- local reading = true
- while reading do
- print("Please choose:")
- for i = 1, #gpus, 1 do
- print("GPU at side: " .. gpus[i])
- end
- print()
- gpuSide = read()
- for i = 1, #gpus, 1 do
- if gpuSide == gpus[i] then
- reading = false
- end
- end
- if reading == true then
- print("Invaild input!! Please repeat")
- sleep(1.5)
- end
- end
- elseif gpuCount == 1 then
- gpuSide = gpus[1]
- end
- if not exit then
- print("GPU at side " .. gpuSide .. " selected")
- print("Hold [Ctrl] + [T] to terminate!")
- sleep(2)
- print("Starting Clock")
- while true do
- time = os.time()
- hours = math.floor(time)
- minutes = math.floor((time-hours)*60)
- --clocCode
- clockCode = "glColor3f(0,0.3,1) glBegin(GL_POINTS)"
- for i = 0,360,1 do
- clockCode = clockCode .. " glVertex2f(".. round(math.sin( math.rad(i) )*-63 + 63) .. ",".. round(math.cos( math.rad(i) )*-63 + 64)..")"
- end
- clockCode = clockCode .. " glEnd()"
- -- hourHand
- hourHand = " glColor3f(1,1,1) glBegin(GL_TRIANGLES)"
- hourHand = hourHand .. " glVertex2f(".. round(math.sin( math.rad((hours % 12) * 30 - 2) )*63 + 63) .. ",".. round(math.cos( math.rad((hours % 12) * 30 - 2) )*-63 + 64) .. ")"
- hourHand = hourHand .. " glVertex2f(".. round(math.sin( math.rad((hours % 12) * 30 + 2) )*63 + 63) .. ",".. round(math.cos( math.rad((hours % 12) * 30 + 2) )*-63 + 64) ..")"
- hourHand = hourHand .. " glVertex2f(63,64)"
- hourHand = hourHand .. " glEnd()"
- -- minuteHand
- minuteHand = " glColor3f(0.8,0,0.1) glBegin(GL_TRIANGLES)"
- minuteHand = minuteHand .. " glVertex2f(".. round(math.sin( math.rad((minutes) * 6 - 1) )*63 + 63) .. ",".. round(math.cos( math.rad((minutes) * 6 - 1) )*-63 + 64) .. ")"
- minuteHand = minuteHand .. " glVertex2f(".. round(math.sin( math.rad((minutes) * 6 + 1) )*63 + 63) .. ",".. round(math.cos( math.rad((minutes) * 6 + 1) )*-63 + 64) ..")"
- minuteHand = minuteHand .. " glVertex2f(63,64)"
- minuteHand = minuteHand .. " glEnd()"
- --EOF creating OPENGL code
- gpu.setRenderCode(gpuSide, [[
- gpuBindOutputBuffer(1)
- gpuClearBuffer()
- ]] .. clockCode .. " " .. hourHand .. " " .. minuteHand)
- sleep(0.001)
- end
- end
- print("Going down..")
Advertisement
Add Comment
Please, Sign In to add comment