Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- distacina entre una capa y otra
- distCapas = 2
- -- distancia entre una linea y otra dentro de la misma capa
- distLineas = 2
- -- distancia entre un atomo y otro dentro de la misma linea
- distAtomos = 4
- -- desfase de espacios entre el primer atomo de una fila y el de la siguiente en la misma capa
- -- 0 = si no hay desfase
- desfaseAtomos = 2
- -- desfase en X entre entre un atomo y otro de la fila equivalente en la capa inferior
- desfaseHX = 2
- -- desfase en Y entre entre una fila y otra equivalente en la capa inferior
- desfaseHY = 0
- xMax = 20
- yMax = 20
- hMax = 20
- -- x+ = hacia delante
- x = 1
- -- y+ = hacia la derecha
- y = 1
- -- h+ = hacia arriba
- h = 1
- -- coordenada Y de la primera linea de la capa
- yInit = 1
- turtle.select(1)
- -- Funcion que coloca un atomo bajo la tortuga si es necesario
- function colocarAtomo(xf,yf,hf)
- fila = (yf - yInit)/distLineas
- capa = (hf - 1)/distCapas
- desfase = desfaseAtomos*fila + desfaseHX*capa
- condicion = xf <= xMax and xf >= 1 and (xf - desfase)%distAtomos == 1
- if condicion then
- while (turtle.getItemCount() == 0) and (turtle.getSelectedSlot() < 16) do
- turtle.select(turtle.getSelectedSlot() + 1)
- end
- if (turtle.getItemCount() == 0) and (turtle.getSelectedSlot() == 16) then
- return false
- end
- turtle.placeDown()
- return true
- end
- end
- -- Funcion que calcula si la cooredada Y corresponde a una linea de atomos en esa capa
- function esLinea(xf,yf,hf)
- fila = (yf - 1)/distLineas
- capa = (hf - 1)/distCapas
- desfase = desfaseHY*capa
- return (yf - desfase)%distLineas == 1
- end
- -- Bucle principal
- while h <= hMax do
- -- Comprobar si a esta coordena Y le corresponde una linea de atomos
- if not esLinea(x,y,h) then
- turtle.turnRight()
- while (not esLinea(x,y,h)) and y <= yMax do
- turtle.forward()
- y = y + 1
- end
- yInit = y
- turtle.turnLeft()
- end
- -- Bucle de la capa
- while y <= yMax do
- if x == xMax then
- xDif = -1
- else
- xDif = 1
- end
- -- Bucle de la fila
- while x>0 and x<=xMax do
- print('normal',x,y)
- if colocarAtomo(x,y,h) == false then
- return
- end
- turtle.forward()
- x = x + xDif
- end
- -- Dar la vuelta
- if x > xMax then
- -- al final del cristal girar a la derecha
- turtle.turnRight()
- turtle.forward()
- y = y+1
- while (not esLinea(x,y,h)) and y <= yMax do
- turtle.forward()
- y = y+1
- print('der',x,y)
- end
- turtle.turnRight()
- else
- -- al principio del cristal girar a la izquierda
- turtle.turnLeft()
- turtle.forward()
- y = y+1
- while (not esLinea(x,y,h)) and y <= yMax do
- turtle.forward()
- y = y+1
- print('izq',x,y)
- end
- turtle.turnLeft()
- end
- -- nada mas girar, comprobar si hay que colocar un atomo
- if y <= yMax then
- if colocarAtomo(x,y,h) == false then
- return
- end
- turtle.forward()
- x = x - xDif
- end
- end
- -- Vuelta a casa (1,1,h)
- -- moverse a x=1
- if x > xMax then
- while x>1 do
- turtle.forward()
- x = x - 1
- end
- turtle.turnRight()
- else
- while x<1 do
- turtle.forward()
- x = x + 1
- end
- turtle.turnLeft()
- end
- -- moverse a y=1
- while y>1 do
- turtle.forward()
- y = y - 1
- end
- -- Girar y subir hasta la siguiente altura
- turtle.turnRight()
- turtle.up()
- h = h+1
- while (not (h%distCapas == 1)) and (h<=hMax) do
- turtle.up()
- h = h+1
- end
- end
- print('Stop',x,y,h)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement