예제 #1
0
def drawCanvas():
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.setPenRadius(0.5)
    stddraw.line(-3.33, -10.0, -3.33, 10.0)
    stddraw.line(3.33, -10.0, 3.33, 10.0)
    stddraw.line(-10.0, -3.33, 10.0, -3.33)
    stddraw.line(-10.0, 3.33, 10.0, 3.33)
예제 #2
0
def select_second(game_array_select):
    global turns
    global moves
    row1 = first_position[0]
    column1 = first_position[1]
    if turns == 2:
        turns = 1
        x = stddraw.mouseX()
        y = stddraw.mouseY()
        for i in range(9):
            for j in range(7):
                if x > j and x < j + 1 and y > i and y < i + 1:
                    if i == row1 and j == column1:
                        stddraw.setPenColor(stddraw.WHITE)
                        stddraw.square(first_position[1] + 0.5,
                                       first_position[0] + 0.5, 0.5)
                        juweimodule.draw_new_things(game_board, score)
                    else:
                        if i == row1 and j != column1:
                            if j - 1 == column1 or j + 1 == column1:
                                swap = game_board[i][j]
                                game_board[i][j] = game_board[row1][column1]
                                game_board[row1][column1] = swap
                                scan_for_same()
                                if display() == 1:
                                    moves -= 1
                                    juweimodule.draw_new_things(
                                        game_board, score)
                                else:
                                    swap = game_board[i][j]
                                    game_board[i][j] = game_board[row1][
                                        column1]
                                    game_board[row1][column1] = swap
                                    reminding_not_matching()

                            else:
                                reminding_faulse_move()

                        elif j == first_position[1] and i != first_position[0]:
                            if i - 1 == row1 or i + 1 == row1:
                                swap = game_board[i][j]
                                game_board[i][j] = game_board[row1][column1]
                                game_board[row1][column1] = swap
                                scan_for_same()
                                if display() == 1:
                                    moves -= 1
                                    juweimodule.draw_new_things(
                                        game_board, score)
                                else:
                                    swap = game_board[i][j]
                                    game_board[i][j] = game_board[row1][
                                        column1]
                                    game_board[row1][column1] = swap
                                    reminding_not_matching()
                            else:
                                reminding_faulse_move()
                        else:
                            reminding_faulse_move()

    return game_array_select
예제 #3
0
def win():
    stddraw.clear()
    stddraw.setPenColor(stddraw.GREEN)
    stddraw.setFontSize(36)
    stddraw.text(4.5, -4.5, "Congrats! You win!")
    stddraw.show(1000)
    sys.exit()
예제 #4
0
def drawSelect(point, score, time): #[x, y], score
    x = point[0]
    y = point[1]
    stddraw.clear()
            
    LIGHT_BLUE = Color(190,240,255)
    stddraw.setPenColor(LIGHT_BLUE)
    stddraw.filledSquare(x-1+0.5, y+0.5, 0.5) #the 4 adjacent squares to the one you clicked
    stddraw.filledSquare(x+1+0.5, y+0.5, 0.5)
    stddraw.filledSquare(x+0.5, y-1+0.5, 0.5)
    stddraw.filledSquare(x+0.5, y+1+0.5, 0.5)

    drawTop(score, time)
    drawBoard()

    stddraw.setPenColor(stddraw.BLACK)
    stddraw.setPenRadius(0.04)
    
    stddraw.line(x, y, x+0.25, y) #the 4 corners around the selected square
    stddraw.line(x, y, x, y+0.25) #bottom left

    stddraw.line(x+0.75, y, x+1, y) #bottom right
    stddraw.line(x+1, y, x+1, y+0.25)

    stddraw.line(x, y+0.75, x, y+1) #top left
    stddraw.line(x, y+1, x+0.25, y+1)

    stddraw.line(x+0.75, y+1, x+1, y+1) #top right
    stddraw.line(x+1, y+0.75, x+1, y+1)
예제 #5
0
    def move(self, dir, apple):
        """ Changes the direction of the snake.

        Keyword parameters:
        dir   -- That key that will change the direction of the snake (a string).
        apple -- The apple that the snake is trying to eat.
        """
        x, y = self.body[0]
        if dir == 'a':
            self.body.insert(0, (x - 1, y))
        elif dir == 'w':
            self.body.insert(0, (x, y + 1))
        elif dir == 'd':
            self.body.insert(0, (x + 1, y))
        elif dir == 's':
            self.body.insert(0, (x, y - 1))

        front = self.body[0]
        stddraw.setPenColor(stddraw.PURPLE)
        stddraw.filledSquare(front[0], front[1], 0.5)

        if front != apple.location:
            back = self.body.pop()
            stddraw.setPenColor(stddraw.BLACK)
            stddraw.filledSquare(back[0], back[1], 0.5)
        else:
            apple.new_location(self)
            config.PTS += 1
예제 #6
0
def score(score):
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.setFontSize(26)
    stddraw.filledRectangle(7.2, -2.5, 2, 1)
    stddraw.setPenColor(stddraw.RED)
    stddraw.text(8.25, -1.75, "SCORE:")
    stddraw.text(8.25, -2.25, str(score) + "/1000")
예제 #7
0
def draw(pole):

    POLE_WIDTH = 0.01
    POLE_COLOR = stddraw.RED
    DISC_COLOR = stddraw.BLUE

    n = len(pole) - 1

    # Draw 3 poles.
    stddraw.clear()
    stddraw.setPenColor(POLE_COLOR)
    stddraw.setPenRadius(POLE_WIDTH)
    for i in range(3):
        stddraw.line(i, 0, i, n)

    # Draw n discs.
    discs = stdarray.create1D(3, 0)   # discs[p] = # discs on pole p
    for i in range(n, 0, -1):
        stddraw.setPenColor(DISC_COLOR)
        stddraw.setPenRadius(0.035)   # magic constant
        size = 0.5 * i / n
        p = pole[i]
        stddraw.line(p-size/2, discs[p], p + size/2, discs[p])
        discs[p] += 1

    stddraw.show(500.0)
예제 #8
0
def draw_clubs():
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledPolygon([4, 6, 5], [0, 0, 5])
    stddraw.filledCircle(5, 7.5, 2.5)
    stddraw.filledCircle(7.5, 4, 2.5)
    stddraw.filledCircle(2.5, 4, 2.5)
    stddraw.filledCircle(5, 5, 2.5)
예제 #9
0
def showScore(score, x=0):
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(-350, 450, 700, 100)
    score = "Score: " + str(score)
    stddraw.setFontSize(60)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.text(-210 + x, 500, score)
예제 #10
0
def main():
    #n = int(sys.argv[1])
    #p = float(sys.argv[2])
    #trials = int(sys.argv[3])
    n = 50
    trials = 1
    moveStep = 999
    for i in range(trials):
        #isAlive = lifeio.random(n, p)

        #滑翔机
        isAlive = [[False] * 2*n for i in range(2*n)]
        isAlive[10][20] = True
        isAlive[11][21] = True
        isAlive[12][19] = True
        isAlive[12][20] = True
        isAlive[12][21] = True
        #isAlive[10][21] = True
        '''
        #高斯帕滑翔机枪
        isAlive = GosperGliderGun.gun
        '''
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        lifeio.draw(isAlive, True)
        stddraw.show(1000)
        for j in range(moveStep):
            stddraw.clear()
            alive = move(isAlive)
            isAlive = alive
        
    stddraw.show()
def draw_graph(points, color):
    stddraw.setPenColor(color)
    prev = None
    for point in points:
        if prev is not None:
            stddraw.line(*prev, *point)
        prev = point
def wrong_guesses(i):
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(-1, -1, 2, 0.2)
    stddraw.setPenColor(stddraw.RED)
    stddraw.setFontSize(40)
    stddraw.text(-0.2,-0.9,i)
    stddraw.show(0)
예제 #13
0
def instructions():
    stddraw.clear()
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.setFontSize(30)
    stddraw.text(3.5,7,"To Win This Game All You Have To Do")
    stddraw.text(3.5,6,"Is Get Your Score Over 100 in under 25 Moves.")
    stddraw.text(3.5,5,"That's It!. Good Luck!")
예제 #14
0
def draw_a_circle(game_array):
    for j in range(9):
        for k in range(7):
            if game_array[j][k] == 4:
                stddraw.circle(k + 0.5, j + 0.5, 0.3)
                stddraw.setPenColor(stddraw.RED)
                stddraw.filledCircle(k + 0.5 , j + 0.5 , 0.3)
예제 #15
0
def drawPDiamond(x, y, colour=stddraw.MAGENTA):
    x1 = [x - 40, x, x + 40, x]
    y1 = [y, y + 40, y, y - 40]
    erase(x, y)
    stddraw.setPenColor(colour)
    stddraw.filledPolygon(x1, y1)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.polygon(x1, y1)
def draw_turn(turn_number):
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(0, 0.96, 80, 20)
    stddraw.setPenColor(stddraw.BLACK)
    if turn_number % 2 != 0:
        stddraw.text((1 / 3) / 2, 0.98, "Player 1's Turn")
    else:
        stddraw.text((1 / 3) / 2, 0.98, "Player 2's Turn")
예제 #17
0
def _draw_points(array, pointcolor):
    """
    @param array: Array with points
    @param pointcolor: Color of points
    Draws given points in a color (TO BE USED FOR draw_data_random() FUNCTION)
    """
    stddraw.setPenColor(pointcolor)
    for point in array:
        stddraw.point(point[0], point[1])
예제 #18
0
def drawGParallelogram(x, y):
    a = 14 * math.sqrt(3)
    x1 = [x - 42, x - 14, x + 42, x + 14]
    y1 = [y - a, y + a, y + a, y - a]
    erase(x, y)
    stddraw.setPenColor(stddraw.GREEN)
    stddraw.filledPolygon(x1, y1)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.polygon(x1, y1)
예제 #19
0
def drawLossCondition():
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(0.03, 4, 4.65, 2.97)
    stddraw.setFontSize(50)
    stddraw.setPenColor(stddraw.RED)
    stddraw.text(2.25, 5.75, 'YOU LOSE!')
    stddraw.setFontSize(25)
    stddraw.text(2.25, 4.75, 'Click to exit')
    stddraw.show(0)
예제 #20
0
def Wguess(guessed):
    stddraw.setFontSize(22)
    stddraw.setPenColor(stddraw.GRAY)
    stddraw.text(3, 5, "Wrong Guesses:")
    stddraw.setFontSize(30)
    stddraw.setPenColor(stddraw.PINK)
    for i in range(len(guessed)):
        stddraw.text(i, 4, ''.join(guessed[i]))
    stddraw.show(500)
예제 #21
0
def draw_a_square(game_array):
    for j in range(9):
        for k in range(7):
            if game_array[j][k] == 2:
                x_axie = [k + 0.2, k + 0.2, k + 0.8, k + 0.8]
                y_axie = [j + 0.8, j + 0.2, j + 0.2, j + 0.8]
                stddraw.polygon(x_axie, y_axie)
                stddraw.setPenColor(stddraw.YELLOW)
                stddraw.filledPolygon(x_axie,y_axie)
예제 #22
0
def goal():
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.setFontSize(26)
    stddraw.filledRectangle(7.2, -3.75, 2, 1.3)
    stddraw.setPenColor(stddraw.ORANGE)
    stddraw.text(8.25, -3, "GOAL:")
    stddraw.setFontSize(16)
    stddraw.text(8, -3.5, "Score 1000 points")
    stddraw.text(8, -3.75, "within 1 minute!")
예제 #23
0
def draw_a_parallelogram(game_array):
    for j in range(9):
        for k in range(7):
            if game_array[j][k] == 0:
                x_axie = [k + 0.4, k + 0.2, k + 0.6, k + 0.8]
                y_axie = [j + 0.8, j + 0.4, j + 0.4, j + 0.8]
                stddraw.polygon(x_axie, y_axie)
                stddraw.setPenColor(stddraw.BLUE)
                stddraw.filledPolygon(x_axie,y_axie)
예제 #24
0
def drawOTriangle(x, y):
    a = 20 * math.sqrt(3)
    x1 = [x - 40, x, x + 40]
    y1 = [y - a, y + a, y - a]
    erase(x, y)
    stddraw.setPenColor(stddraw.ORANGE)
    stddraw.filledPolygon(x1, y1)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.polygon(x1, y1)
예제 #25
0
def drawWinCondition():
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(0.03, 4, 4.65, 2.97)
    stddraw.setFontSize(50)
    stddraw.setPenColor(stddraw.MAGENTA)
    stddraw.text(2.25, 5.75, 'YOU WIN!')
    stddraw.setFontSize(25)
    stddraw.text(2.25, 4.75, 'Click to exit')
    stddraw.show(0)
예제 #26
0
def drawBHexagon(x, y):
    a = 20 * math.sqrt(3)
    x1 = [x - 40, x - 20, x + 20, x + 40, x + 20, x - 20]
    y1 = [y, y + a, y + a, y, y - a, y - a]
    erase(x, y)
    stddraw.setPenColor(stddraw.BLUE)
    stddraw.filledPolygon(x1, y1)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.polygon(x1, y1)
예제 #27
0
def draw_a_regular_triangle(game_array):
    for j in range(9):
        for k in range(7):
            if game_array[j][k] == 5:
                x_axie = [k + 0.2, k + 0.8, k + 0.5]
                y_axie = [j + 0.3, j + 0.3, j + 0.7]
                stddraw.polygon(x_axie, y_axie)
                stddraw.setPenColor(stddraw.ORANGE)
                stddraw.filledPolygon(x_axie,y_axie)
예제 #28
0
def draw_a_inclined(game_array):
    for j in range(9):
        for k in range(7):
            if game_array[j][k] == 3:
                x_axie = [k + 0.2 , k + 0.5, k + 1 - 0.2, k + 0.5]
                y_axie = [j + 0.5, j + 0.2, j + 0.5, j + 1 - 0.2]
                stddraw.polygon(x_axie, y_axie)
                stddraw.setPenColor(stddraw.GREEN)
                stddraw.filledPolygon(x_axie,y_axie)
def draw_results(guesses_remaining, word_to_guess):
    if guesses_remaining == 0:
        stddraw.setPenColor(stddraw.DARK_RED)
        stddraw.text(0.5, 0.3, "You lost! Try playing again.")
    else:
        stddraw.setPenColor(stddraw.DARK_GREEN)
        stddraw.text(0.5, 0.3, "Congrats! You won the game!")
    stddraw.text(0.5, 0.225, "The word was: " + word_to_guess)
    stddraw.show()
예제 #30
0
def draw_blanks():
    new_array = array
    for i in range(len(new_array)):
        for j in range(len(new_array[i])):
            y = -i + 1 - 1.5
            x = j + 1 - .5
            if new_array[i][j] == 0:
                stddraw.setPenColor(stddraw.WHITE)
                stddraw.filledSquare(x, y, 0.5)
예제 #31
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()
예제 #32
0
def main(argv):
    r1 = int(argv[1])
    g1 = int(argv[2])
    b1 = int(argv[3])

    c1 = color.Color(r1, g1, b1)

    r2 = int(argv[4])
    g2 = int(argv[5])
    b2 = int(argv[6])

    c2 = color.Color(r2, g2, b2)
    stddraw.createWindow()
    stddraw.setPenColor(c1)
    stddraw.filledSquare(.25, .5, .2)

    stddraw.setPenColor(c2)
    stddraw.filledSquare(.25, .5, .1)

    stddraw.setPenColor(c2)
    stddraw.filledSquare(.75, .5, .2)

    stddraw.setPenColor(c1)
    stddraw.filledSquare(.75, .5, .1)
    stddraw.show()
    stddraw.wait()
예제 #33
0
def main(argv):
    n = int(argv[1])
    p = float(argv[2])
    t = int(argv[3])
    stddraw.createWindow()
    for i in range(t):
        open = percolation.random(n, p)
        stddraw.clear()
        stddraw.setPenColor(stddraw.BLACK)
        percolation.show(open, False)
        stddraw.setPenColor(stddraw.BLUE)
        full = percolation.flow(open)
        percolation.show(full, True)
        stddraw.sleep(1000)
        stddraw.show()
    stddraw.wait()
예제 #34
0
def main():
    stddraw.createWindow()
    stddraw.setXscale(0, 15)
    stddraw.setYscale(0, 15)
    for i in range(16):
        for j in range (16):
            #val = i + 16*j
            val = 8*i + 8*j
            #c1 = color.Color(0, 0, 255-val)
            c1 = color.Color(255-val, 255-val, 255)            
            c2 = color.Color(val, val, val)
            stddraw.setPenColor(c1)
            stddraw.filledSquare(i, j, 0.5)
            stddraw.setPenColor(c2)
            stddraw.filledSquare(i, j, 0.25)
            stddraw.show()
    stddraw.wait()
예제 #35
0
def draw(pole):

    n = len(pole) - 1

    # Draw 3 poles.
    stddraw.clear()
    stddraw.setPenColor(POLE_COLOR)
    stddraw.setPenRadius(POLE_WIDTH)
    for i in range(3):
        stddraw.line(i, 0, i, n)

    # Draw n discs.
    discs = stdarray.create1D(3, 0)   # discs[p] = # discs on pole p
    for i in range(n, 0, -1):
        stddraw.setPenColor(DISC_COLOR)
        stddraw.setPenRadius(0.035)   # magic constant
        size = 0.5 * i / n
        p = pole[i]
        stddraw.line(p-size/2, discs[p], p + size/2, discs[p])
        discs[p] += 1

    stddraw.sleep(500)
    stddraw.show()
예제 #36
0
# (r2, g2, b2).

r1 = int(sys.argv[1])
g1 = int(sys.argv[2])
b1 = int(sys.argv[3])
c1 = color.Color(r1, g1, b1)

r2 = int(sys.argv[4])
g2 = int(sys.argv[5])
b2 = int(sys.argv[6])
c2 = color.Color(r2, g2, b2)

stddraw.setCanvasSize(512, 256)
stddraw.setYscale(.25, .75)

stddraw.setPenColor(c1)
stddraw.filledSquare(.25, .5, .2)

stddraw.setPenColor(c2)
stddraw.filledSquare(.25, .5, .1)

stddraw.setPenColor(c2)
stddraw.filledSquare(.75, .5, .2)

stddraw.setPenColor(c1)
stddraw.filledSquare(.75, .5, .1)

stddraw.show()

#-----------------------------------------------------------------------
예제 #37
0
def drawSquare(x, y, size):
    stddraw.setPenColor(stddraw.LIGHT_GRAY)
    stddraw.filledSquare(x, y, size / 2)
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.square(x, y, size / 2)
예제 #38
0
#-----------------------------------------------------------------------
# rose.py
#-----------------------------------------------------------------------

import stddraw
import sys
import math

# Accept integer command-line argument n. Draw an n petal rose (if n
# is odd) and a 2n petal rose (if n is even).

n = int(sys.argv[1])
stddraw.createWindow()
stddraw.setXscale(-1, +1);
stddraw.setYscale(-1, +1);
stddraw.setPenColor(stddraw.PINK);

x0 = 0.0
y0 = 0.0

t = 0.0
while t <= 360.0:
    theta = math.radians(t)
    r = math.sin(n * theta)
    x1 = r * math.cos(theta)
    y1 = r * math.sin(theta)
    stddraw.line(x0, y0, x1, y1)
    x0 = x1
    y0 = y1
    t += 0.1
stddraw.show()
예제 #39
0
# Draw an animation of the second, minute, and hour hands of an
# analog clock.
stddraw.createWindow()
t = 0
while True:

    # Remainder operator with floats so all hands move every second.
    seconds = t % 60
    minutes = (t / 60.0) % 60
    hours   = (t / 3600.0) % 12

    stddraw.clear()
    stddraw.setPenRadius()

    # Draw clock face.
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledCircle(0.5, 0.5, 0.45)

    # Draw hour markers.
    stddraw.setPenColor(stddraw.BLUE)
    for i in range(12):
        theta = math.radians(i * 30)
        stddraw.filledCircle(0.5 + 0.4 * math.cos(theta), \
                             0.5 + 0.4 * math.sin(theta), .025)

    # Draw second hand.
    stddraw.setPenRadius(.01)
    stddraw.setPenColor(stddraw.YELLOW)
    angle1 = math.radians(6 * seconds)
    r1 = 0.4
    stddraw.line(0.5, 0.5, \
예제 #40
0
vy = 0.023

radius = 0.05
dt = 20
start = time.time()

t = 0
while t < 10000:
    # Update ball position and draw it there.
    if abs(rx + vx) + radius > 1.0:
        vx = -vx
    if abs(ry + vy) + radius > 1.0:
        vy = -vy
    rx = rx + vx
    ry = ry + vy

    # stddraw.clear()

    stddraw.setPenColor(stddraw.GRAY)
    stddraw.filledSquare(0, 0, 1.0)

    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledCircle(rx, ry, radius)

    # stddraw.sleep(dt)
    stddraw.show()
    t += 1
finish = time.time()

print finish - start
예제 #41
0
#-----------------------------------------------------------------------
# checkerboard.py
#-----------------------------------------------------------------------

import stddraw
import sys

# Accept integer command-line argument n. Draw an n-by-n checkerboard.

n = int(sys.argv[1])
stddraw.createWindow()

stddraw.setXscale(0, n)
stddraw.setYscale(0, n)

for i in range(n):
    for j in range(n):
        if ((i + j) % 2) != 0:
            stddraw.setPenColor(stddraw.BLACK)
        else:
            stddraw.setPenColor(stddraw.RED)
        stddraw.filledSquare(i + .5, j + .5, .5)
        stddraw.show()

stddraw.wait()
예제 #42
0
#-----------------------------------------------------------------------
# shapestext.py
#-----------------------------------------------------------------------

import stddraw

# Draw some shapes and some text.
stddraw.createWindow()
stddraw.square(.2, .8, .1)

stddraw.filledSquare(.8, .8, .2)

stddraw.circle(.8, .2, .2)

xd = [.1, .2, .3, .2]
yd = [.2, .3, .2, .1]
stddraw.filledPolygon(xd, yd)

stddraw.setFontFamily('Times')
stddraw.setFontSize(40)
stddraw.text(.2, .5, 'black')

stddraw.setPenColor(stddraw.WHITE)
stddraw.setFontFamily('Courier')
stddraw.setFontSize(30)
stddraw.text(.8, .8, 'white')

stddraw.show()
stddraw.wait()