X



なあ、再帰関数好きな人いる? パート3 [転載禁止]©2ch.net

0001デフォルトの名無しさん
垢版 |
2015/11/28(土) 18:51:38.86ID:Rc2MJzM/
なあ、再帰関数好きな人いる?
0576NAS6 ◆n3AmnVhjwc
垢版 |
2016/01/05(火) 07:31:25.96ID:FnNfbNzM
stk =Array.new()
#同色上書き塗りつぶし
def loop_refill(dest,src,x,y,color,minx,miny,maxx,maxy)
 term = 0
 while !((x < minx) || (maxx < x) ||(y < miny) || (maxy < y))
  dest[y][x] = color
  #上
  if (term < 1) && (src[y-1][x] == color) && (dest[y-1][x] != color)
   term = 0
   stk.push(x)
   stk.push(y)
   stk.push(term)
   y = y - 1
   term = 0
   next
  end
  #左
  if (term < 2) && (src[y][x-1] == color) && (dest[y][x-1] != color)
   term = 1
   stk.push(x)
   stk.push(y)
   stk.push(term)
   x = x - 1
   term = 0
   next
  end
0577NAS6 ◆n3AmnVhjwc
垢版 |
2016/01/05(火) 07:31:53.09ID:FnNfbNzM
  #下
  if (term < 3) && (src[y+1][x] == color) && (dest[y+1][x] != color)
   term = 2
   stk.push(x)
   stk.push(y)
   stk.push(term)
   y = y + 1
   term = 0
   next
  end
  #右
  if (term < 4) && (src[y][x+1] == color) && (dest[y][x+1] != color)
   term = 3
   stk.push(x)
   stk.push(y)
   stk.push(term)
   x = x + 1
   term = 0
   next
  end
  term = stk.pop()
  y = stk.pop()
  x = stk.pop()
 end
end
レスを投稿する


ニューススポーツなんでも実況