Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://www.youtube.com/watch?v=kdyehkBjLJg
- monitor = peripheral.wrap("right")
- -- VARIABLE --
- -- limites de la gráfica
- xMin = -2*math.pi
- xMax = 2*math.pi
- yMax = 1.5
- yMin = -1.5
- -- coloreamos el fondo
- monitor.setBackgroundColor(colors.black)
- -- aumentamos la resolucion
- monitor.setTextScale(0.5)
- -- borramos todo
- monitor.clear()
- -- obtenemos las dimensiones del monitor
- sxMax, syMax = monitor.getSize()
- -- guardamos la configuracion del ordenador
- computer = term.current()
- -- pasamos a trabajar en el monitor
- term.redirect( monitor )
- -- pintamos los ejes
- -- eje x
- y0 = (1-syMax)*(0-yMax)/(yMax-yMin) + 1
- y0 = math.floor(y0+0.5)
- if y0 >= 1 and y0 <= syMax then
- paintutils.drawLine(1, y0, sxMax, y0, colors.gray)
- end
- -- eje y
- x0 = (sxMax-1)*(0-xMin)/(xMax-xMin) + 1
- x0 = math.floor(x0+0.5)
- if x0 >= 1 and x0 <= sxMax then
- paintutils.drawLine(x0, 1, x0, syMax, colors.gray)
- end
- -- pintamos todas las gráficas
- for j = 1, 3 do
- yScreenm1 = 1/0
- -- pintamos puntos para todos los valores de x
- for k = 1, sxMax do
- -- guardamos la actual posicion de x en la pantalla
- xScreen = k
- -- calculamos el valor de x en la funcion
- x = (xMax-xMin)*(xScreen-1)/(sxMax-1) + xMin
- -- VARIABLE --
- if j == 1 then
- -- calculamos el valor de y para la x actual
- y = math.sin(x)
- color = colors.orange
- elseif j == 2 then
- y = math.sin(x - math.pi*2/3)
- color = colors.green
- elseif j == 3 then
- y = math.sin(x + math.pi*2/3)
- color = colors.blue
- end
- -- calculamos la posicion en y del punto actual
- yScreen = (1-syMax)*(y-yMax)/(yMax-yMin) + 1
- -- ajustamos la posicion de y para que sea un entero
- yScreen = math.floor(yScreen+0.5)
- -- si el punto esta en la pantalla, lo pintamos
- if math.abs(yScreen)~=math.huge and yScreen >= 1 and yScreen <= syMax then
- paintutils.drawPixel(xScreen, yScreen, color)
- end
- -- a continuacion llenamos los huecos para que no queden piexeles sueltos
- -- pintamos en la columna anterior todos los pixeles hasta uno antes del nuevo
- -- comprobamos que ningun valor sea infinito y que no pase de inf a -inf
- if math.abs(yScreenm1)~=math.huge and math.abs(yScreen)~=math.hugeand and
- not ((yScreenm1 < 1 and yScreen > syMax) or (yScreenm1 > syMax and yScreen < 1)) then
- -- si la grafica es creciente
- if yScreen > yScreenm1 + 1 then
- for m = yScreenm1 + 1, yScreen - 1 do
- paintutils.drawPixel(xScreen - 1, m, color)
- end
- -- si la grafica es decreciente
- elseif yScreen < yScreenm1 - 1 then
- for m = yScreen + 1, yScreenm1 - 1 do
- paintutils.drawPixel(xScreen - 1, m, color)
- end
- end
- end
- yScreenm1 = yScreen
- end
- end
- -- regresamos al ordenador
- term.redirect( computer )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement