Advertisement
LDDestroier

Punnet Square Maker (CC)

May 16th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3.  
  4.     pat = read() --paternal --localize
  5.     mat = read() --maternal --localize
  6.  
  7. pat = pat:sub(1,#pat-(#pat%2))
  8. mat = mat:sub(1,#mat-(#mat%2))
  9.  
  10. split = function(txt,splitPt) --such a useful function
  11.     local output = {}
  12.     local buffer = ""
  13.     for a = 1, #txt do
  14.         if (txt:sub(a,a) == "\n") or (#buffer >= splitPt) then
  15.             output[#output+1] = buffer
  16.             buffer = ""
  17.         end
  18.         buffer = (buffer..txt:sub(a,a)):gsub("\n","")
  19.         if a == #txt then
  20.             output[#output+1] = buffer
  21.         end
  22.     end
  23.     return output
  24. end
  25.  
  26. everyOther = function(txt,step) --localize
  27.     local output = ""
  28.     for a = 1, #txt, step or 2 do
  29.         output = output..txt:sub(a,a)
  30.     end
  31.     return output
  32. end
  33.  
  34. foilArrange = function(str,step)
  35.     step = step or 2
  36.     local output = {}
  37.     local genes = split(str,2)
  38.     for g = 1, #genes do
  39.         for a = 1, #genes[g] do
  40.             for b = 1, #genes[g] do
  41.                 if a ~= b then
  42.                     output[#output+1] = genes[g]:sub(a,a)..genes[g]:sub(b,b)
  43.                 end
  44.             end
  45.         end
  46.     end
  47.     return output
  48. end
  49.  
  50. spliceStr = function(txt1,txt2) --localize
  51.     assert(#txt1 == #txt2, "strings must be same length, you dullard")
  52.     local output = ""
  53.     for a = 1, #txt1 do
  54.         output = output..txt1:sub(a,a)..txt2:sub(a,a)
  55.     end
  56.     return output
  57. end
  58.  
  59.     pGenes = foilArrange(pat) --localize
  60.     mGenes = foilArrange(mat) --localize
  61.  
  62.     grid = {} --localize
  63.  
  64. for p = 1, #pat do
  65.     grid[p] = {}
  66.     for m = 1, #mat do
  67.         grid[p][m] = spliceStr(pGenes[p],mGenes[m])
  68.     end
  69. end
  70.  
  71. writeBlocks = function(len,col) --localize
  72.     local pCol = term.getBackgroundColor()
  73.     term.setBackgroundColor(col or colors.white)
  74.     term.write((" "):rep(len or 1))
  75.     term.setBackgroundColor(pCol)
  76. end
  77.  
  78. renderGrid = function(g,sx,sy)
  79.     sx, sy = sx or 2, sy or 2
  80.     term.setCursorPos(sx,sy)
  81.     writeBlocks(1+((#g[1])^2)+#g[1])
  82.     for y = 1, #g do
  83.         term.setCursorPos(sx,sy+(y*2)-1)
  84.         writeBlocks(1)
  85.         for x = 1, #g[y] do
  86.             term.write(grid[y][x])
  87.             writeBlocks(1)
  88.         end
  89.         term.setCursorPos(sx,sy+(y*2))
  90.         writeBlocks(1+((#g[1])^2))
  91.     end
  92. end
  93.  
  94. local cx,cy = term.getCursorPos()
  95.  
  96. renderGrid(grid,2,cy+2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement