Advertisement
Guest User

CC Turtle Square Wall

a guest
Aug 24th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. angle = math.asin(3.0 / 5.0);
  2. sin = math.sin(angle);
  3. cos = math.cos(angle);
  4.  
  5. local function rotateBack(vec)
  6.     local vx = vec.x * (cos - sin);
  7.     local vy = vec.y * (cos + sin);
  8.     return vector.new(vx, vy);
  9. end
  10.  
  11. local function getJitterDirY(position, inv1, inv2)
  12.     local p = rotateBack(position);
  13.     if p.y > inv2.y then
  14.         return 1;
  15.     elseif p.y < 0 then
  16.         return -1;
  17.     else
  18.         return 0;
  19.     end
  20. end
  21.  
  22. args = {...};
  23. width = tonumber(args[1]);
  24.  
  25. -- Initial position is (0,0)
  26. position = vector.new(0, 0, 0);
  27. inverted1 = rotateBack(vector.new(4, -3, 0)).mul(width);
  28. inverted2 = rotateBack(vector.new(3, 4, 0)).mul(width);
  29. lastX = inverted1.add(inverted2).x;
  30.  
  31. for xi = 0, lastX do
  32.     local downDone = false;
  33.     local upDone = false;
  34.    
  35.     while getJitterDirY(position, inverted1, inverted2) <= 0 do
  36.         turtle.place();
  37.         turtle.up();
  38.         position.y += 1;
  39.     end
  40.     while getJitterY(position, inverted1, inverted2) >= 0 do
  41.         if not turtle.detect() then
  42.             turtle.place();
  43.         end
  44.         turtle.down();
  45.         position.y -= 1;
  46.     end
  47.     turtle.turnRight();
  48.     turtle.forward();
  49.     turtle.turnLeft();
  50.     position.x += 1;
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement