예제 #1
0
def PofRelativelyPrime(n):
	l = [[False] * n for i in range(n)]
	for i in range(n):
		for j in range(n):
			if PofInt.relativelyPrime(i,j):
				l[i][j] = True
	percolationio.draw(l,True)
예제 #2
0
def Pofx(n):
	l = [[False] * n for i in range(n)]
	for i in range(n):
		for j in range(n):
			if odd(comb(i,j)):
				l[i][j] = True
	percolationio.draw(l,True)
예제 #3
0
def main():
    n = int(sys.argv[1])
    p = float(sys.argv[2])
    trials = int(sys.argv[3])
    for i in range(trials):
        isOpen = percolationio.random(n, p)
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        percolationio.draw(isOpen, False)
        stddraw.setPenColor(stddraw.BLUE)
        full = percolation.flow(isOpen)
        percolationio.draw(full, True)
        stddraw.show(1000.0)
    stddraw.show()
예제 #4
0
 def leftRight(isOpen,isFull,i,j):
     t = j
     #向左一直找空的
     while 1 <= t and isOpen[i][t-1]:
         isFull[i][t-1] = True
         t -= 1
         percolationio.draw(isFull, True)
         stddraw.show(50.0)
     t = j
     #向右一直找空的
     while t < n-1 and isOpen[i][t+1]:
         isFull[i][t+1] = True
         t += 1
         percolationio.draw(isFull, True)
         stddraw.show(50.0)
     return isFull
예제 #5
0
def main():
    # n = int(sys.argv[1])
    # p = float(sys.argv[2])
    # trials = int(sys.argv[3])
    n = 20
    p = .5
    trials = 5
    for i in range(trials):
        isOpen = percolationio.random(n, p)
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        stddraw.setPenRadius(0.005)
        percolationio.draw(isOpen, True)
        stddraw.setPenColor(stddraw.BLUE)
        stddraw.setPenRadius(0.05)
        full = percolation.flow(isOpen)
        percolationio.draw(full, True)
        stddraw.show(1000.0)
    #print('over')
    stddraw.show()
예제 #6
0
def flow(isOpen):
    n = len(isOpen)
    isFull = stdarray.create2D(n, n, False)
    stddraw.setPenColor(stddraw.BLUE)
    for j in range(n):
        isFull[0][j] = isOpen[0][j]
        percolationio.draw(isFull, True)
        stddraw.show(50.0)
    for i in range(1, n):
        for j in range(n):
            if isOpen[i][j] and isFull[i-1][j]:
                isFull[i][j] = True
                percolationio.draw(isFull, True)
                stddraw.show(50.0)
        # for j in range(n):
        #     if isOpen[i][j]:
        #         if 1 <= j and j < n-1:
        #             if isFull[i][j-1] or isFull[i][j+1]:
        #                 isFull[i][j] = True
        #                 percolationio.draw(isFull, True)
        #                 stddraw.show(50.0)
        isFull = horizontal(isOpen,isFull,i)
    return isFull
def _flow(isOpen, isFull, i, j):
    n = len(isFull)
    if (i < 0) or (i >= n):
        print(i, j)
        return
    if (j < 0) or (j >= n):
        print(i, j)
        return
    if not isOpen[i][j]:
        print(i, j)
        return
    if isFull[i][j]:
        print(i, j)
        return
    isFull[i][j] = True
    stddraw.setPenColor(stddraw.BLUE)
    percolationio.draw(isFull, True)
    stddraw.show(100)
    global depth
    depth += 1
    _flow(isOpen, isFull, i + 1, j)  # Down.
    _flow(isOpen, isFull, i, j + 1)  # Right.
    _flow(isOpen, isFull, i, j - 1)  # Left.
    _flow(isOpen, isFull, i - 1, j)  # Up.
예제 #8
0
def Pofhadamard(n):
	l = hadamard.had(n)
	percolationio.draw(l,True)