示例#1
0
def mapper():
    x2, y2, strength2 = get_point(angles, difference, direction, x, y, strength)
    max = -30
    increment = 5
    #strength = s
    if strength2 == 0.0:
        std.setPenColor(std.LIGHT_GRAY)
    elif strength2 >= max:
        std.setPenColor(std.DARK_RED)
    elif strength2 < max and strength2 >= (max - increment):
        std.setPenColor(std.RED)
    elif strength2 < (max - increment) and strength2 >= (max - (2*increment)):
        std.setPenColor(std.MAGENTA)
    elif strength2 < (max - (2*increment)) and strength2 >= (max - (3*increment)):
        std.setPenColor(std.VIOLET)
    elif strength2 < (max - (3*increment)) and strength2 >= (max - (4*increment)):
        std.setPenColor(std.PINK)
    elif strength2 < (max - (4*increment)) and strength2 >= (max - (5*increment)):
        std.setPenColor(std.BOOK_LIGHT_BLUE)
    elif strength2 < (max - (5*increment)) and strength2 >= (max - (6*increment)):
        std.setPenColor(std.BOOK_BLUE)
    elif strength2 < (max - (6*increment)) and strength2 >= (max - (7*increment)):
        std.setPenColor(std.BLUE)
    elif strength2 < (max - (7*increment)) and strength2 >= (max - (8*increment)):
        std.setPenColor(std.DARK_BLUE)
    elif strength2 < (max - (8*increment)):
        std.setPenColor(std.BLACK)
    else:
        print('data not in expected range', strength)
    std.filledCircle(x2[-1], y2[-1], RADIUS)
    std.show(500)
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)
示例#3
0
def draw_heart():
    stddraw.setPenColor(stddraw.RED)
    stddraw.filledCircle(2.5, 7.5, 2.5)
    stddraw.filledCircle(7.5, 7.5, 2.5)
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(0, 0, 10, 7.5)
    stddraw.setPenColor(stddraw.RED)
    stddraw.filledPolygon([5, 10, 0], [0, 7.5, 7.5])
示例#4
0
def draw_tree(n, x, y, size):
    if n <= 1:
        return

    stddraw.line(x, y, x - size / 1.3, y - size)
    stddraw.filledCircle(x - size / 1.3, y - size, 0.008)

    stddraw.line(x, y, x + size / 1.3, y - size)
    stddraw.filledCircle(x + size / 1.3, y - size, 0.008)

    draw_tree(n - 1, x - size / 1.3, y - size, size / 2)
    draw_tree(n - 1, x + size / 1.3, y - size, size / 2)
示例#5
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)
示例#6
0
def mapper():

    print(time.value, direction.value, strength.value)
    x2, y2, strength2 = get_point(angles, time.value, direction.value, x, y,
                                  strength.value)
    max = 90
    increment = 10
    #strength = s
    if strength2 >= max:
        std.setPenColor(std.DARK_RED)
    elif strength2 < max and strength2 >= (max - increment):
        std.setPenColor(std.RED)
    elif strength2 < (max - increment) and strength2 >= (max -
                                                         (2 * increment)):
        std.setPenColor(std.MAGENTA)
    elif strength2 < (max -
                      (2 * increment)) and strength2 >= (max -
                                                         (3 * increment)):
        std.setPenColor(std.VIOLET)
    elif strength2 < (max -
                      (3 * increment)) and strength2 >= (max -
                                                         (4 * increment)):
        std.setPenColor(std.PINK)
    elif strength2 < (max -
                      (4 * increment)) and strength2 >= (max -
                                                         (5 * increment)):
        std.setPenColor(std.BOOK_LIGHT_BLUE)
    elif strength2 < (max -
                      (5 * increment)) and strength2 >= (max -
                                                         (6 * increment)):
        std.setPenColor(std.BOOK_BLUE)
    elif strength2 < (max -
                      (6 * increment)) and strength2 >= (max -
                                                         (7 * increment)):
        std.setPenColor(std.BLUE)
    elif strength2 < (max -
                      (7 * increment)) and strength2 >= (max -
                                                         (8 * increment)):
        std.setPenColor(std.DARK_BLUE)
    elif strength2 < (max - (8 * increment)):
        std.setPenColor(std.BLACK)
    else:
        print('data not in expected range', strength)

    std.filledCircle(x, y, RADIUS)
    std.show(500)
示例#7
0
def curve(n, x0, y0, x1, y1):
    # print 'curve', N, x0, y0, x1, y1
    gap = .01
    err = .0025
    T = 10000
    xm = (x0 + x1) / 2.0
    ym = (y0 + y1) / 2.0
    fxm = estimate.eval(n, xm, T)
    if (x1 - x0 < gap) or (abs(ym - fxm) < err):
        stddraw.line(x0, y0, x1, y1)
        stddraw.show()
        return
    curve(n, x0, y0, xm, fxm)
    stddraw.filledCircle(xm, fxm, .005)
    stddraw.show()

    curve(n, xm, fxm, x1, y1)
示例#8
0
def curve(n, x0, y0, x1, y1):
    # print 'curve', N, x0, y0, x1, y1
    gap = 0.01
    err = 0.0025
    T = 10000
    xm = (x0 + x1) / 2.0
    ym = (y0 + y1) / 2.0
    fxm = estimate.eval(n, xm, T)
    if (x1 - x0 < gap) or (abs(ym - fxm) < err):
        stddraw.line(x0, y0, x1, y1)
        stddraw.show()
        return
    curve(n, x0, y0, xm, fxm)
    stddraw.filledCircle(xm, fxm, 0.005)
    stddraw.show()

    curve(n, xm, fxm, x1, y1)
示例#9
0
def drawScene(goalie_pos, ball_x, ball_y):

    stddraw.clear()
    stddraw.setPenColor(stddraw.BLACK)

    #gridlines
    for i in range(1, GRID_NUM_HEIGHT):
        stddraw.filledRectangle(0, GRID_SIZE * i, WIDTH, 0)

    for i in range(1, GRID_NUM_WIDTH):
        stddraw.filledRectangle(GRID_SIZE * i, 0, 0, HEIGHT)

    #goalie
    stddraw.setPenColor(stddraw.BLUE)
    stddraw.filledRectangle(goalie_pos * GRID_SIZE, 0, GRID_SIZE,
                            GRID_SIZE)  #x,y,size_x,size_y

    #Ball
    stddraw.setPenColor(stddraw.GREEN)
    stddraw.filledCircle(((ball_x * GRID_SIZE) + (GRID_SIZE / 2)),
                         (HEIGHT - ((ball_y * GRID_SIZE) + (GRID_SIZE / 2))),
                         GRID_SIZE / 2)
示例#10
0
def printcheckboard(values): 
    n = 8
    stddraw.setXscale(0, n)
    stddraw.setYscale(0, n)
    z = 0 ##z is the spot in values string
    rows = 'ABCDEFGH'
    cols = '12345678'
        
    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(j + .5, i + .5, .5)
            stddraw.setPenColor(stddraw.YELLOW)
            location = rows[i] + cols[j]
            stddraw.text(j+.15, i+.1, location)
            if((i + j) % 2) == 0:
                if(values[z] == '1'):           ##player 1 #or values[z] == '3'
                    stddraw.setPenColor(stddraw.BLUE)
                    stddraw.filledCircle(j + .5, i + .5, .25)
                elif(values[z] == '2'):         ##player 2
                    stddraw.setPenColor(stddraw.WHITE)
                    stddraw.filledCircle(j + .5, i + .5, .25)
                elif(values[z] == '3'):         ##player 1 king
                    stddraw.setPenColor(stddraw.WHITE)
                    stddraw.filledCircle(j + .5, i + .5, .25)
                    stddraw.setPenColor(stddraw.BLACK)
                    stddraw.text(j+.5, i+.5, "K")
                elif(values[z] == '4'):         ##player 2 king
                    stddraw.setPenColor(stddraw.WHITE)
                    stddraw.filledCircle(j + .5, i + .5, .25)
                    stddraw.setPenColor(stddraw.BLACK)
                    stddraw.text(j+.5, i+.5, "K")
                z+=1
    stddraw.show(500)
示例#11
0
    stddraw.setXscale(0, n)
    stddraw.setYscale(0, n)
else:
    stddraw.setXscale(0, m)
    stddraw.setYscale(0, m)
section = True
No_ = m * n
while True:
    no_run = 0
    stddraw.clear()
    if No_ > 0:
        for i in range(n):
            for j in range(m):
                if no_run < No_:
                    stddraw.setPenColor(stddraw.RED)
                    stddraw.filledCircle(i + .5, j + .5, .5)
                    no_run += 1
        stddraw.show(20)
        print(section)
        if section:
            stdio.write("Luot choi cua A[1-3]: ")
            k = stdio.readInt()
            No_ -= k
            section = False
        else:
            stdio.write("Luot choi cua B[1-3]: ")
            k = stdio.readInt()
            No_ -= k
            section = True
    else:
        if section:
示例#12
0
import sys
import math
sys.path.append('../')
import stddraw
import random
from mathutils import cartesian_coord
import numpy as np

n = int(sys.argv[1])
p = float(sys.argv[2])
minradius = float(sys.argv[3])
maxradius = float(sys.argv[4])

stddraw.setXscale(0, 1)
stddraw.setYscale(0, 1)
for i in range(n):
    if random.random() < p:
        stddraw.setPenColor(stddraw.RED)
    else:
        stddraw.setPenColor(stddraw.BLUE)
    x, y = random.random(), random.random()
    r = random.uniform(minradius, maxradius)
    stddraw.filledCircle(x, y, r)

stddraw.show()
示例#13
0
import stddraw

# Draw a bouncing ball to standard draw.

RADIUS = .05
DT = 20.0

stddraw.setXscale(-1.0, 1.0)
stddraw.setYscale(-1.0, 1.0)

rx = .480
ry = .860
vx = .015
vy = .023

while True:
    # 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.GRAY)
    stddraw.filledCircle(rx, ry, RADIUS)
    stddraw.show(0)
示例#14
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
示例#15
0
import stddraw
import sys
import math

stddraw.setXscale(-1.5, 1.5)
stddraw.setYscale(-1.5, 1.5)
stddraw.setPenColor(stddraw.PINK)

xs = [-1, 0, 1, 0]
ys = [0, -1, 0, 1]
stddraw.filledPolygon(xs, ys)

stddraw.filledCircle(+0.5, 0.5, 1 / math.sqrt(2))
stddraw.filledCircle(-0.5, 0.5, 1 / math.sqrt(2))

stddraw.show()
示例#16
0
def draw_spades():
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.filledPolygon([4, 6, 5], [0, 0, 5])
    stddraw.filledPolygon([0, 10, 5], [5, 5, 10])
    stddraw.filledCircle(2.5, 4, 2.68)
    stddraw.filledCircle(7.5, 4, 2.68)
示例#17
0
def display(playing_field, x, y, lent, totalscore, finalscore, clickcoords,
            clicklocal, attempts, level, background, win):
    stddraw.clear()
    image(background)
    stddraw.setXscale(-lent, (2 * lent * x) - lent)
    stddraw.setYscale(-(2 * lent * y) - 4 * lent, lent)
    stddraw.setPenColor(stddraw.PINK)
    stddraw.filledRectangle(-lent, -(2 * lent * y) - 4 * lent, (2 * lent * x),
                            5 * lent)
    stddraw.setPenColor(stddraw.BOOK_LIGHT_BLUE)
    stddraw.filledRectangle(-lent, -(2 * lent * y) - 3 * lent, (2 * lent * x),
                            lent)
    stddraw.setPenColor(stddraw.BOOK_LIGHT_BLUE)
    stddraw.filledRectangle(-lent, -(2 * lent * y) - 1.5 * lent,
                            (2 * lent * x), lent)
    stddraw.setPenColor(stddraw.GRAY)
    stddraw.filledRectangle(-lent, -(2 * lent * y) - 2.2 * lent,
                            (2 * lent * x), lent)
    if totalscore < finalscore:
        stddraw.setPenColor(stddraw.GREEN)
        stddraw.filledRectangle(-lent, -(2 * lent * y) - 2.2 * lent,
                                ((2 * lent * x) - lent) / 1.7 *
                                (totalscore / finalscore), lent)
    if totalscore >= finalscore:
        stddraw.setPenColor(stddraw.GREEN)
        stddraw.filledRectangle(-lent, -(2 * lent * y) - 2.2 * lent,
                                ((2 * lent * x) - lent), lent)
    stddraw.setPenColor(stddraw.BOOK_LIGHT_BLUE)
    stddraw.filledRectangle(x * lent + lent, -(2 * lent * y) - 3.5 * lent,
                            (lent * x), 3.5 * lent)
    stddraw.setPenRadius(0.010)
    stddraw.setPenColor(stddraw.BOOK_LIGHT_BLUE)
    stddraw.rectangle(-lent, -(2 * lent * y) - 4 * lent, (2 * lent * x),
                      5 * lent)
    stddraw.setFontSize(25)
    stddraw.setPenColor(stddraw.DARK_GREEN)
    stddraw.text((((2 * lent * x) - lent) / 1.3), -((2 * lent * y) + lent),
                 'Points: ' + str(totalscore) + ' / ' + str(finalscore))
    stddraw.setPenColor(stddraw.RED)
    stddraw.setFontSize(20)
    stddraw.text((((2 * lent * x) - lent) / 1.3),
                 -((2 * lent * y) + 2.7 * lent),
                 'Attempts Left: ' + str(attempts))
    stddraw.setPenColor(stddraw.BLUE)
    stddraw.setFontSize(25)
    stddraw.text((((2 * lent * x) - lent) / 20),
                 -((2 * lent * y) - 0.08 * lent), 'Level: ' + str(level))
    for i in range(len(clickcoords) - 1):
        found = False
        reps = -1
        while found == False and not reps >= (x * y - 1):
            reps += 1
            if clicklocal[reps][0] < clickcoords[i] < clicklocal[reps][
                    1] and clicklocal[reps][2] < clickcoords[
                        i + 1] < clicklocal[reps][3]:
                spotx = playing_field[reps][0]
                spoty = playing_field[reps][1]
                stddraw.setPenColor(stddraw.DARK_RED)
                stddraw.setPenRadius(0.05)
                stddraw.filledSquare(spotx, spoty, lent)
                found = True

    for i in range(x * y):
        spotx = playing_field[i][0]
        spoty = playing_field[i][1]

        if playing_field[i][2] == 1:

            stddraw.setPenColor(stddraw.MAGENTA)
            stddraw.setPenRadius(0.05)
            stddraw.filledCircle(spotx, spoty, lent / 1.2)

        if playing_field[i][2] == 2:
            stddraw.setPenColor(stddraw.YELLOW)
            stddraw.setPenRadius(0.05)
            stddraw.filledSquare(spotx, spoty, lent / 1.2)

        if playing_field[i][2] == 3:
            stddraw.setPenColor(stddraw.BLUE)
            stddraw.setPenRadius(0.05)
            stddraw.filledPolygon([(spotx - lent) + 0.2, (spotx - lent) + 0.3,
                                   (spotx - lent) + 0.7, (spotx - lent) + 0.9,
                                   (spotx - lent) + 0.6],
                                  [(spoty - lent) + 0.6, (spoty - lent) + 0.9,
                                   (spoty - lent) + 0.9, (spoty - lent) + 0.6,
                                   (spoty - lent) + 0.1])

        if playing_field[i][2] == 4:
            stddraw.setPenColor(stddraw.GREEN)
            stddraw.setPenRadius(0.05)
            stddraw.filledPolygon([
                (spotx - lent) + 0.1,
                (spotx - lent) + 0.4,
                (spotx - lent) + 0.9,
                (spotx - lent) + 0.4,
            ], [(spoty - lent) + 0.4, (spoty - lent) + 0.1,
                (spoty - lent) + 0.4, (spoty - lent) + 0.9])

        if playing_field[i][2] == 5:
            stddraw.setPenColor(stddraw.BLACK)
            stddraw.setPenRadius(0.05)
            stddraw.filledPolygon([(spotx - lent) + 0.5, (spotx - lent) + 0.1,
                                   (spotx - lent) + 0.9],
                                  [(spoty - lent) + 0.8, (spoty - lent) + 0.1,
                                   (spoty - lent) + 0.1])

        if playing_field[i][2] == 6:
            stddraw.setPenColor(stddraw.CYAN)
            stddraw.setPenRadius(0.05)
            stddraw.filledPolygon([(spotx - lent) + 0.5, (spotx - lent) + 0.1,
                                   (spotx - lent) + 0.9, (spotx - lent) + 0.3,
                                   (spotx - lent) + 0.6],
                                  [(spoty - lent) + 0.9, (spoty - lent) + 0.7,
                                   (spoty - lent) + 0.7, (spoty - lent) + 0.1,
                                   (spoty - lent) + 0.1])

    if attempts == 0 and totalscore < finalscore:
        while stddraw.mousePressed() == False:
            stddraw.setPenColor(stddraw.BLACK)
            stddraw.filledRectangle(-lent, -(lent * y) - 2 * lent,
                                    (2 * lent * x), 3.5 * lent)
            stddraw.setFontSize(40)
            stddraw.setPenColor(stddraw.RED)
            stddraw.text(lent * x - lent, -(lent * y),
                         'YOU LOSE, CLICK TO EXIT')
            stddraw.show(0)
            if stddraw.mousePressed() == True:
                win = True
                return win

    if totalscore >= finalscore:
        while stddraw.mousePressed() == False:
            stddraw.setPenColor(stddraw.BOOK_BLUE)
            stddraw.filledRectangle(-lent, -(lent * y) - 2 * lent,
                                    (2 * lent * x), 3.5 * lent)
            stddraw.setFontSize(40)
            stddraw.setPenColor(stddraw.GREEN)
            stddraw.text(lent * x - lent, -(lent * y),
                         'YOU WIN, CLICK TO PROCEED')
            stddraw.show(0)
            if stddraw.mousePressed() == True:
                win = False
                return win
    stddraw.show(250)
    return win
def drawPiece(x, y, ay):

    stddraw.setPenRadius(0.008)

    if board[y][x] == 0: #diamond
        FILL = Color(250,252,255)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.2, x+0.35, x+0.65, x+0.8]
        ys = [y+ay+0.2, y+ay+0.5, y+ay+0.7, y+ay+0.7, y+ay+0.5]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(220,225,255)
        stddraw.setPenColor(OUTLINE)
        xs = [x+0.5, x+0.2, x+0.35, x+0.65, x+0.8]
        ys = [y+ay+0.2, y+ay+0.5, y+ay+0.7, y+ay+0.7, y+ay+0.5]
        stddraw.polygon(xs, ys)

    if board[y][x] == 1: #emerald
        FILL = Color(180,255,180)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.7, x+0.7, x+0.5, x+0.3, x+0.3]
        ys = [y+ay+0.8, y+ay+0.6, y+ay+0.4, y+ay+0.2, y+ay+0.4, y+ay+0.6]
        stddraw.filledPolygon(xs, ys)

        FILL = Color(210,255,210)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.7, x+0.5, x+0.3]
        ys = [y+ay+0.8, y+ay+0.6, y+ay+0.4, y+ay+0.6]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(100,225,100)
        stddraw.setPenColor(OUTLINE)
        xs = [x+0.5, x+0.7, x+0.7, x+0.5, x+0.3, x+0.3]
        ys = [y+ay+0.8, y+ay+0.6, y+ay+0.4, y+ay+0.2, y+ay+0.4, y+ay+0.6]
        stddraw.polygon(xs, ys)

    if board[y][x] == 2: #ruby
        FILL = Color(245,140,140)
        stddraw.setPenColor(FILL)
        xs = [x+0.65, x+0.75, x+0.75, x+0.65, x+0.35, x+0.25, x+0.25, x+0.35]
        ys = [y+ay+0.8, y+ay+0.7, y+ay+0.3, y+ay+0.2, y+ay+0.2, y+ay+0.3, y+ay+0.7, y+ay+0.8]
        stddraw.filledPolygon(xs, ys)

        FILL2 = Color(255,180,180)
        stddraw.setPenColor(FILL2)
        xs = [x+0.65, x+0.75, x+0.5, x+0.25, x+0.35]
        ys = [y+ay+0.8, y+ay+0.7, y+ay+0.5, y+ay+0.7, y+ay+0.8]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(205,80,80)
        stddraw.setPenColor(OUTLINE)
        xs = [x+0.65, x+0.75, x+0.75, x+0.65, x+0.35, x+0.25, x+0.25, x+0.35]
        ys = [y+ay+0.8, y+ay+0.7, y+ay+0.3, y+ay+0.2, y+ay+0.2, y+ay+0.3, y+ay+0.7, y+ay+0.8]
        stddraw.polygon(xs, ys)

    if board[y][x] == 3: #saphhire
        FILL = Color(60,120,255)
        stddraw.setPenColor(FILL)
        stddraw.filledCircle(x+0.5, y+ay+0.5, 0.3)

        FILL = Color(80,190,255) 
        stddraw.setPenColor(FILL)
        stddraw.filledCircle(x+0.4, y+ay+0.6, 0.1)

        OUTLINE = Color(20,50,255) 
        stddraw.setPenColor(OUTLINE)
        stddraw.circle(x+0.5, y+ay+0.5, 0.3)

    if board[y][x] == 4: #topaz
        FILL = Color(255,255,200)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.2, x+0.3, x+0.7]
        ys = [y+ay+0.2, y+ay+0.5, y+ay+0.7, y+ay+0.7]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(225,225,100)
        stddraw.setPenColor(OUTLINE)
        stddraw.polygon(xs, ys)

    if board[y][x] == 5: #amethyst
        FILL = Color(225,170,225)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.8, x+0.5, x+0.2]
        ys = [y+ay+0.8, y+ay+0.5, y+ay+0.2, y+ay+0.5]
        stddraw.filledPolygon(xs, ys)

        FILL = Color(245,180,245)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.5, x+0.2]
        ys = [y+ay+0.8, y+ay+0.4, y+ay+0.5]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(155,100,155)
        stddraw.setPenColor(OUTLINE)
        xs = [x+0.5, x+0.8, x+0.5, x+0.2]
        ys = [y+ay+0.8, y+ay+0.5, y+ay+0.2, y+ay+0.5]
        stddraw.polygon(xs, ys)

    if board[y][x] == 6: #aquamarine
        FILL = Color(100,250,220)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.8, x+0.7, x+0.3, x+0.2]
        ys = [y+ay+0.8, y+ay+0.4, y+ay+0.2, y+ay+0.2, y+ay+0.4]
        stddraw.filledPolygon(xs, ys)

        FILL = Color(190,255,250)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.7, x+0.6, x+0.4, x+0.3]
        ys = [y+ay+0.7, y+ay+0.45, y+ay+0.3, y+ay+0.3, y+ay+0.45]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(50,200,170) 
        stddraw.setPenColor(OUTLINE)
        xs = [x+0.5, x+0.8, x+0.7, x+0.3, x+0.2]
        ys = [y+ay+0.8, y+ay+0.4, y+ay+0.2, y+ay+0.2, y+ay+0.4]
        stddraw.polygon(xs, ys)

    if board[y][x] == 7: #citrine
        FILL = Color(255,160,70)
        stddraw.setPenColor(FILL)
        xs = [x+0.3, x+0.2, x+0.7, x+0.7]
        ys = [y+ay+0.2, y+ay+0.6, y+ay+0.8, y+ay+0.3]
        stddraw.filledPolygon(xs, ys)

        FILL = Color(255,190,90)
        stddraw.setPenColor(FILL)
        xs = [x+0.5, x+0.2, x+0.7, x+0.7]
        ys = [y+ay+0.5, y+ay+0.6, y+ay+0.8, y+ay+0.6]
        stddraw.filledPolygon(xs, ys)

        OUTLINE = Color(205,100,30) 
        stddraw.setPenColor(OUTLINE)
        xs = [x+0.3, x+0.2, x+0.7, x+0.7]
        ys = [y+ay+0.2, y+ay+0.6, y+ay+0.8, y+ay+0.3]
        stddraw.polygon(xs, ys)
示例#19
0
t = 0
time = '0:00:00'
oldTime = '0:00:00'
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, \
                 0.5 + r1 * math.sin(angle1), \
示例#20
0
# 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, \
                 0.5 + r1 * math.sin(angle1), \
示例#21
0
文件: batphim.py 项目: cstlu/CS100
import pygame
import stddraw
pygame.init()
x = 0
y = 0
stddraw.setPenColor(stddraw.RED)
while True:
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        x -= 0.01
    if keys[pygame.K_RIGHT]:
        x += 0.01
    if keys[pygame.K_UP]:
        y += 0.01
    if keys[pygame.K_DOWN]:
        y -= 0.01
    stddraw.filledCircle(x, y, 0.05)
    stddraw.show(20)
    stddraw.clear()