Ejemplo n.º 1
0
def main():
    n = int(sys.argv[1])
    time = float(sys.argv[2])

    table = Table(n)
    while True:
        table.time_evolve(time)
        table.draw()
        stddraw.show(20)
        stddraw.clear()
Ejemplo n.º 2
0
def main():
    universe = Universe(sys.argv[1])
    dt = float(sys.argv[2])
    count = 0
    while True:
        universe.increaseTime(dt)
        stddraw.clear()
        universe.draw()
        stddraw.show(10)
        print(count)
        count += 1
Ejemplo n.º 3
0
def main():
    duration = int(input('what is the duration?(min):'))
    status = input('start to work?(Y/N)')

    while status == 'Y':
        stddraw.clear()
        stddraw.setXscale(0, 10)
        stddraw.setYscale(0, 10)
        time.sleep(duration * 60)
        stddraw.text(5, 5, 'go to do sport')
        stddraw.show()
        status = input('continue to work?(Y/N')
        if status == 'N':
            break
Ejemplo n.º 4
0
def move(location, dict, n, a, buffer, c):

    print('enter move program')
    stddraw.clear()

    print(dict)
    if (n == 1):

        print(a, "->", c)
        dict[c].insert(0, dict[a][0])

        del (dict[a][0])
        draw_move(dict, a, c, location)
        print(dict)

        return
    move(location, dict, n - 1, a, c, buffer)
    move(location, dict, 1, a, buffer, c)
    move(location, dict, n - 1, buffer, a, c)
Ejemplo n.º 5
0
def lifegame(life):
    '''
    recursive return the adjacent part block

    :param x:
    :param y:
    :return:
    '''
    stddraw.clear()
    draw(life)
    stddraw.show(500)
    for line in life:
        print(line)

    life2 = stdarray.create2D(10, 10, 0)
    for x in range(10):
        for y in range(10):
            print('x is {0},y is {1}'.format(x, y))

            a = 0
            for i in range(x - 1, x + 2):
                # print('i is {0}'.format(i))
                for j in range(y - 1, y + 2):
                    # print('j is {0}'.format(j))
                    if i < 0 or i > 9 or j < 0 or j > 9:
                        pass
                    else:

                        a += life[i][j]
                        print(
                            'i is {0},j is {1},life[{0}][{1}] is {3},a is{2}'.
                            format(i, j, a, life[i][j]))

            if a == 0:
                print(x, y, 'no alive in 9')
                pass
            else:

                life2[x][y] = isalive(life, x, y)

    lifegame(life2)
Ejemplo n.º 6
0
    result = stdarray.create1D(len(index), 0)
    for i in range(n):
        sum = dice_1[stdrandom.uniformInt(0, 5)] + dice_2[stdrandom.uniformInt(
            0, 5)]
        result[sum] += 1

    return result


def run(n):

    dice_1 = [1, 3, 4, 5, 6, 8]
    dice_2 = [1, 2, 2, 3, 3, 4]
    dice_s = [1, 2, 3, 4, 5, 6]

    result1 = dice(dice_1, dice_2, n)
    result2 = dice(dice_s, dice_s, n)

    print(result1, result2)

    stddraw.setYscale(0, 1.1 * max(max(result1), max(result2)))
    stdstats.plotLines(result1)
    stdstats.plotBars(result2)
    stddraw.show(50)


stddraw.setCanvasSize(1000, 400)
for n in range(50, 200):
    stddraw.clear()
    run(n)
Ejemplo n.º 7
0
        v1x = v2x
        v2x = a
        changepoint.append((r1x, r1y, r2x, r2y))
        # stddraw.line(r1x,r1y,r2x,r2y)
        # stddraw.show()
        a = v1y
        v1y = v2y
        v2y = a
        # break
    if abs(r1x + v1x) + RADIUS > 1.0: v1x = -v1x
    if abs(r1y + v1y) + RADIUS > 1.0: v1y = -v1y
    if abs(r2x + v2x) + RADIUS > 1.0: v2x = -v2x
    if abs(r2y + v2y) + RADIUS > 1.0: v2y = -v2y
    r1x = r1x + v1x
    r1y = r1y + v1y
    r2x = r2x + v2x
    r2y = r2y + v2y

    position1.append((r1x, r1y))

    stddraw.clear(stddraw.LIGHT_GRAY)

    stddraw.setPenColor(stddraw.GRAY)
    for x, y in position1[-50:]:
        print(x, y)
        stddraw.circle(x, y, RADIUS)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledCircle(r1x, r1y, RADIUS)
    stddraw.filledCircle(r2x, r2y, RADIUS)
    stddraw.show(DT)
Ejemplo n.º 8
0
def draw_clock(H=0, M=0, S=0):
    stddraw.setXscale(-1.5, 1.5)
    stddraw.setYscale(-1.5, 1.5)

    R = 1.1
    Hour_L = 0.4
    Min_L = 0.55
    Sec_L = 0.7
    Hour_count = 0

    Hour_X = stdarray.create1D(12, 0)
    Hour_Y = stdarray.create1D(12, 0)

    for i in range(1, 13):
        Hour_X[i - 1] = 1 * math.cos(-(i / 12 * 2 * math.pi - 1 / 2 * math.pi))
        Hour_Y[i - 1] = 1 * math.sin(-(i / 12 * 2 * math.pi - 1 / 2 * math.pi))

    stddraw.setFontSize(25)

    if H > 11:
        print('H is {0}'.format(H))
        H = H % 12
        Hour_count = 1

    while True:
        while H < 13:

            angle_H = H * 2 * math.pi / 12 - 1 / 2 * math.pi
            print('H is {0}'.format(H))
            if H == 12:
                H = 0
                Hour_count += 1

            H += 1

            if Hour_count % 2 == 0:
                text = 'morining'
            else:
                text = 'afternoon'

            while M < 61:

                angle_M = M * 2 * math.pi / 60 - 1 / 2 * math.pi
                print('m is {0}'.format(M))

                if M == 60:
                    print('m is 60')
                    M = 0
                    break
                else:
                    M += 1
                while S < 61:
                    angle_s = S * 2 * math.pi / 60 - 1 / 2 * math.pi
                    print('s is {0}'.format(S))

                    if S == 60:
                        S = 0
                        print('s is 60')
                        break
                    else:
                        S += 1

                    stddraw.clear()
                    stddraw.circle(0, 0, R)
                    for i in range(1, 13):
                        stddraw.text(Hour_X[i - 1], Hour_Y[i - 1], str(i))
                    stddraw.text(0, 0.85, text)

                    stddraw.setPenRadius(0.02)
                    stddraw.line(0, 0, Hour_L * math.cos(-angle_H),
                                 Hour_L * math.sin(-angle_H))
                    stddraw.setPenRadius(0.01)
                    stddraw.line(0, 0, Min_L * math.cos(-angle_M),
                                 Min_L * math.sin(-angle_M))
                    stddraw.setPenRadius(0.005)

                    stddraw.line(0, 0, Sec_L * math.cos(-angle_s),
                                 Sec_L * math.sin(-angle_s))
                    stddraw.show(1000)