Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function HSVtoRGB(hue, sat, val)
- local h = round(hue / 60)
- local f = hue / 60 - h
- local p = val * (1 - sat)
- local q = val * (1 - sat * f)
- local t = val * (1- sat * (1 - f))
- local r, g, b = 0
- if h == 1 then
- r = q
- g = 1
- b = p
- elseif h == 2 then
- r = p
- g = 1
- b = t
- elseif h == 3 then
- r = p
- g = q
- b = 1
- elseif h == 4 then
- r = t
- g = p
- b = 1
- elseif h == 5 then
- r = 1
- g = p
- b = q
- else
- r = 1
- g = t
- b = p
- end
- return r, g, b
- end
- 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
- local 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("")
- print("Do you want the outer ring to crossfade colors? <y/n>")
- local fade = read()
- if fade == "y" or fade == "Y" then
- print("")
- print("")
- repeat
- print("")
- print("How many seconds should it take until the crossfading restart?")
- fadeTime = tonumber(read())
- if type(fadeTime) ~= "number" or fadeTime <= 0 then print ("Illeagal Input (min = 1)") end
- until type(fadeTime) == "number" and fadeTime > 0
- end
- print("")
- print("")
- print("")
- print("Please enter the frequency of frame updates.")
- print(" smale value (2-10) => more MC FPS, maybe less accurate Time")
- print("")
- print(" high value (>10) => less MC FPS, high accurate Time")
- print("A alue of > 25 is a waste of CPU usage")
- print("")
- print("Recommended: 6.5")
- repeat
- frq = tonumber(read())
- illegalInput = type(frq) ~= "number" or frq < 1 or frq > 35
- if illegalInput then print("Illegal Input (min=1; max=100)") end
- until not illegalInput
- print("")
- print("")
- print("")
- print("")
- print("")
- print("Hold [Ctrl] + [T] to terminate!")
- sleep(2)
- print("Starting Clock")
- color = 0
- my_r = 0
- my_g = 0.3
- my_b = 1
- lasttick = 0
- --Generate Circle
- clockCode = " glBegin(GL_POINTS)"
- for i = 0,360,1 do
- clockCode = clockCode .. " glVertex2f(".. round(math.cos( math.rad(i) )*63.5 + 63) .. ",".. round(math.sin( math.rad(i) )*63.5 + 64)..")"
- end
- clockCode = clockCode .. " glEnd()"
- --EOF Generate Circle
- while true do
- time = os.time()
- hours = math.floor(time)
- minutes = math.floor((time-hours)*60)
- if fade == "y" or fade == "Y" then
- my_r, my_g, my_b = HSVtoRGB(color, 1, 1)
- color = color + (( os.clock() - lasttick) / fadeTime * 360)
- lasttick = os.clock()
- if color > 359 then color = 0 end
- end
- clockColor = "glColor3f(" .. my_r .. "," .. my_g .."," .. my_b .. ")"
- -- hourHand
- hourHand = " glColor3f(1,1,1) glBegin(GL_TRIANGLES)"
- hourHand = hourHand .. " glVertex2f(".. round(math.sin( math.rad((hours % 12) * 30 - 2) )*63.5 + 63) .. ",".. round(math.cos( math.rad((hours % 12) * 30 - 2) )*-63.5 + 64) .. ")"
- hourHand = hourHand .. " glVertex2f(".. round(math.sin( math.rad((hours % 12) * 30 + 2) )*63.5 + 63) .. ",".. round(math.cos( math.rad((hours % 12) * 30 + 2) )*-63.5 + 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.5 + 63) .. ",".. round(math.cos( math.rad((minutes) * 6 - 1) )*-63.5 + 64) .. ")"
- minuteHand = minuteHand .. " glVertex2f(".. round(math.sin( math.rad((minutes) * 6 + 1) )*63.5 + 63) .. ",".. round(math.cos( math.rad((minutes) * 6 + 1) )*-63.5 + 64) ..")"
- minuteHand = minuteHand .. " glVertex2f(63,64)"
- minuteHand = minuteHand .. " glEnd()"
- --EOF creating OPENGL code
- gpu.setRenderCode(gpuSide, [[
- gpuBindOutputBuffer(1)
- gpuClearBuffer()
- ]] .. clockColor .. clockCode .. " " .. hourHand .. " " .. minuteHand)
- sleep(1 / frq)
- end
- end
- print("Going down..")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement