SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function round(num, idp) |
| 1 | + | function HSVtoRGB(hue, sat, val) |
| 2 | - | local mult = 10^(idp or 0) |
| 2 | + | |
| 3 | - | return math.floor(num * mult + 0.5) / mult |
| 3 | + | local h = round(hue / 60) |
| 4 | - | end |
| 4 | + | local f = hue / 60 - h |
| 5 | - | |
| 5 | + | local p = val * (1 - sat) |
| 6 | - | |
| 6 | + | local q = val * (1 - sat * f) |
| 7 | - | print(" Analog Clock ") |
| 7 | + | local t = val * (1- sat * (1 - f)) |
| 8 | - | sleep(3.0) |
| 8 | + | local r, g, b = 0 |
| 9 | - | |
| 9 | + | |
| 10 | - | gpuCount = 0 |
| 10 | + | |
| 11 | - | gpus = {} |
| 11 | + | if h == 1 then |
| 12 | - | gpuSide = "" |
| 12 | + | r = q |
| 13 | - | |
| 13 | + | g = 1 |
| 14 | - | --detecting gpus |
| 14 | + | b = p |
| 15 | - | |
| 15 | + | elseif h == 2 then |
| 16 | - | sides = {"back","front","left","right","top"} |
| 16 | + | r = p |
| 17 | - | for i = 1, 5, 1 do |
| 17 | + | g = 1 |
| 18 | - | if peripheral.isPresent(sides[i]) then |
| 18 | + | b = t |
| 19 | - | if peripheral.getType(sides[i]) == "gpu" then |
| 19 | + | elseif h == 3 then |
| 20 | - | gpuCount = gpuCount + 1 --increasing gpu count |
| 20 | + | r = p |
| 21 | - | table.insert(gpus, (#gpus + 1), sides[i]) --adding gpu to list |
| 21 | + | g = q |
| 22 | - | end |
| 22 | + | b = 1 |
| 23 | - | end |
| 23 | + | elseif h == 4 then |
| 24 | - | end |
| 24 | + | r = t |
| 25 | - | |
| 25 | + | g = p |
| 26 | - | --tell User |
| 26 | + | b = 1 |
| 27 | - | exit = false |
| 27 | + | elseif h == 5 then |
| 28 | - | |
| 28 | + | r = 1 |
| 29 | - | if gpuCount == 0 then |
| 29 | + | g = p |
| 30 | - | print("No gpu found!") |
| 30 | + | b = q |
| 31 | - | exit = true |
| 31 | + | else |
| 32 | - | elseif (gpuCount > 1) then |
| 32 | + | r = 1 |
| 33 | - | print("More than 1 gpu found!") |
| 33 | + | g = t |
| 34 | - | print() |
| 34 | + | b = p |
| 35 | - | local reading = true |
| 35 | + | end |
| 36 | - | while reading do |
| 36 | + | |
| 37 | - | print("Please choose:") |
| 37 | + | return r, g, b |
| 38 | - | for i = 1, #gpus, 1 do |
| 38 | + | end |
| 39 | - | print("GPU at side: " .. gpus[i]) |
| 39 | + | |
| 40 | - | end |
| 40 | + | function round(num, idp) |
| 41 | - | print() |
| 41 | + | local mult = 10^(idp or 0) |
| 42 | - | gpuSide = read() |
| 42 | + | return math.floor(num * mult + 0.5) / mult |
| 43 | - | |
| 43 | + | end |
| 44 | - | for i = 1, #gpus, 1 do |
| 44 | + | |
| 45 | - | |
| 45 | + | |
| 46 | - | if gpuSide == gpus[i] then |
| 46 | + | print(" Analog Clock ")
|
| 47 | - | reading = false |
| 47 | + | sleep(3.0) |
| 48 | - | end |
| 48 | + | |
| 49 | - | end |
| 49 | + | gpuCount = 0 |
| 50 | - | |
| 50 | + | gpus = {}
|
| 51 | - | if reading == true then |
| 51 | + | gpuSide = "" |
| 52 | - | print("Invaild input!! Please repeat") |
| 52 | + | |
| 53 | - | sleep(1.5) |
| 53 | + | --detecting gpus |
| 54 | - | end |
| 54 | + | |
| 55 | - | end |
| 55 | + | sides = {"back","front","left","right","top"}
|
| 56 | - | |
| 56 | + | for i = 1, 5, 1 do |
| 57 | - | elseif gpuCount == 1 then |
| 57 | + | if peripheral.isPresent(sides[i]) then |
| 58 | - | gpuSide = gpus[1] |
| 58 | + | if peripheral.getType(sides[i]) == "gpu" then |
| 59 | - | end |
| 59 | + | gpuCount = gpuCount + 1 --increasing gpu count |
| 60 | - | |
| 60 | + | table.insert(gpus, (#gpus + 1), sides[i]) --adding gpu to list |
| 61 | - | if not exit then |
| 61 | + | end |
| 62 | - | print("GPU at side " .. gpuSide .. " selected") |
| 62 | + | end |
| 63 | - | |
| 63 | + | end |
| 64 | - | print("Hold [Ctrl] + [T] to terminate!") |
| 64 | + | |
| 65 | - | sleep(2) |
| 65 | + | --tell User |
| 66 | - | print("Starting Clock") |
| 66 | + | exit = false |
| 67 | - | |
| 67 | + | |
| 68 | - | while true do |
| 68 | + | if gpuCount == 0 then |
| 69 | - | time = os.time() |
| 69 | + | print("No gpu found!")
|
| 70 | - | |
| 70 | + | exit = true |
| 71 | - | hours = math.floor(time) |
| 71 | + | elseif (gpuCount > 1) then |
| 72 | - | minutes = math.floor((time-hours)*60) |
| 72 | + | print("More than 1 gpu found!")
|
| 73 | - | |
| 73 | + | print() |
| 74 | - | |
| 74 | + | local reading = true |
| 75 | - | --clocCode |
| 75 | + | while reading do |
| 76 | - | clockCode = "glColor3f(0,0.3,1) glBegin(GL_POINTS)" |
| 76 | + | print("Please choose:")
|
| 77 | - | |
| 77 | + | for i = 1, #gpus, 1 do |
| 78 | - | for i = 0,360,1 do |
| 78 | + | print("GPU at side: " .. gpus[i])
|
| 79 | - | clockCode = clockCode .. " glVertex2f(".. round(math.sin( math.rad(i) )*-63 + 63) .. ",".. round(math.cos( math.rad(i) )*-63 + 64)..")" |
| 79 | + | end |
| 80 | - | end |
| 80 | + | print() |
| 81 | - | clockCode = clockCode .. " glEnd()" |
| 81 | + | gpuSide = read() |
| 82 | - | |
| 82 | + | |
| 83 | - | -- hourHand |
| 83 | + | for i = 1, #gpus, 1 do |
| 84 | - | |
| 84 | + | |
| 85 | - | hourHand = " glColor3f(1,1,1) glBegin(GL_TRIANGLES)" |
| 85 | + | if gpuSide == gpus[i] then |
| 86 | - | |
| 86 | + | reading = false |
| 87 | - | 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) .. ")" |
| 87 | + | end |
| 88 | - | 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) ..")" |
| 88 | + | end |
| 89 | - | hourHand = hourHand .. " glVertex2f(63,64)" |
| 89 | + | |
| 90 | - | |
| 90 | + | if reading == true then |
| 91 | - | hourHand = hourHand .. " glEnd()" |
| 91 | + | print("Invaild input!! Please repeat")
|
| 92 | - | |
| 92 | + | sleep(1.5) |
| 93 | - | -- minuteHand |
| 93 | + | end |
| 94 | - | |
| 94 | + | end |
| 95 | - | minuteHand = " glColor3f(0.8,0,0.1) glBegin(GL_TRIANGLES)" |
| 95 | + | |
| 96 | - | |
| 96 | + | elseif gpuCount == 1 then |
| 97 | - | minuteHand = minuteHand .. " glVertex2f(".. round(math.sin( math.rad((minutes) * 6 - 1) )*63 + 63) .. ",".. round(math.cos( math.rad((minutes) * 6 - 1) )*-63 + 64) .. ")" |
| 97 | + | gpuSide = gpus[1] |
| 98 | - | minuteHand = minuteHand .. " glVertex2f(".. round(math.sin( math.rad((minutes) * 6 + 1) )*63 + 63) .. ",".. round(math.cos( math.rad((minutes) * 6 + 1) )*-63 + 64) ..")" |
| 98 | + | end |
| 99 | - | minuteHand = minuteHand .. " glVertex2f(63,64)" |
| 99 | + | |
| 100 | - | |
| 100 | + | if not exit then |
| 101 | - | minuteHand = minuteHand .. " glEnd()" |
| 101 | + | print("GPU at side " .. gpuSide .. " selected")
|
| 102 | - | |
| 102 | + | print("Do you want the outer ring to crossfade colors? <y/n>")
|
| 103 | - | |
| 103 | + | local fade = read() |
| 104 | - | --EOF creating OPENGL code |
| 104 | + | |
| 105 | - | |
| 105 | + | print("Hold [Ctrl] + [T] to terminate!")
|
| 106 | - | gpu.setRenderCode(gpuSide, [[ |
| 106 | + | sleep(2) |
| 107 | - | |
| 107 | + | print("Starting Clock")
|
| 108 | - | gpuBindOutputBuffer(1) |
| 108 | + | |
| 109 | - | gpuClearBuffer() |
| 109 | + | color = 0 |
| 110 | - | |
| 110 | + | |
| 111 | - | ]] .. clockCode .. " " .. hourHand .. " " .. minuteHand) |
| 111 | + | while true do |
| 112 | - | |
| 112 | + | time = os.time() |
| 113 | - | sleep(0.001) |
| 113 | + | |
| 114 | - | end |
| 114 | + | hours = math.floor(time) |
| 115 | - | |
| 115 | + | minutes = math.floor((time-hours)*60) |
| 116 | - | end |
| 116 | + | |
| 117 | - | |
| 117 | + | if fade == "y" or fade == "Y" then |
| 118 | my_r, my_g, my_b = HSVtoRGB(color, 1, 1) | |
| 119 | clockCode = "glColor3f(" .. my_r .. "," .. my_g .."," .. my_b .. ") glBegin(GL_POINTS)"
| |
| 120 | color = color + 1 | |
| 121 | if color > 360 then color = 0 end | |
| 122 | else | |
| 123 | clockCode = "glColor3f(0,0.3,1) glBegin(GL_POINTS)" | |
| 124 | end | |
| 125 | ||
| 126 | for i = 0,360,1 do | |
| 127 | clockCode = clockCode .. " glVertex2f(".. round(math.sin( math.rad(i) )*-63.5 + 63) .. ",".. round(math.cos( math.rad(i) )*-63.5 + 64)..")"
| |
| 128 | end | |
| 129 | clockCode = clockCode .. " glEnd()" | |
| 130 | ||
| 131 | -- hourHand | |
| 132 | ||
| 133 | hourHand = " glColor3f(1,1,1) glBegin(GL_TRIANGLES)" | |
| 134 | ||
| 135 | 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) .. ")"
| |
| 136 | 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) ..")"
| |
| 137 | hourHand = hourHand .. " glVertex2f(63,64)" | |
| 138 | ||
| 139 | ||
| 140 | hourHand = hourHand .. " glEnd()" | |
| 141 | ||
| 142 | -- minuteHand | |
| 143 | ||
| 144 | minuteHand = " glColor3f(0.8,0,0.1) glBegin(GL_TRIANGLES)" | |
| 145 | ||
| 146 | 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) .. ")"
| |
| 147 | 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) ..")"
| |
| 148 | minuteHand = minuteHand .. " glVertex2f(63,64)" | |
| 149 | ||
| 150 | minuteHand = minuteHand .. " glEnd()" | |
| 151 | ||
| 152 | ||
| 153 | --EOF creating OPENGL code | |
| 154 | ||
| 155 | gpu.setRenderCode(gpuSide, [[ | |
| 156 | ||
| 157 | gpuBindOutputBuffer(1) | |
| 158 | gpuClearBuffer() | |
| 159 | ||
| 160 | ]] .. clockCode .. " " .. hourHand .. " " .. minuteHand) | |
| 161 | ||
| 162 | ||
| 163 | ||
| 164 | sleep(0.007) | |
| 165 | end | |
| 166 | ||
| 167 | end | |
| 168 | ||
| 169 | print("Going down..") |