Beispiel #1
0
def drawShapes(number,x,y):
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.setPenRadius(0.01)
    if number == 0:
        stddraw.square(x,y,0.4)
        stddraw.setPenColor(stddraw.YELLOW)
        stddraw.filledSquare(x,y,0.4)
    if number == 1:
        stddraw.setPenColor(stddraw.RED)
        stddraw.filledCircle(x,y,0.4)
        stddraw.setPenColor(stddraw.BLACK)
        stddraw.setPenRadius(0.004)
        stddraw.circle(x,y,0.4)
    if number == 2:
        xs = [x-0.4,x+0.4,x]
        ys = [y-0.4,y-0.4,y+0.4]
        stddraw.polygon(xs,ys)
        stddraw.setPenColor(stddraw.ORANGE)
        stddraw.filledPolygon(xs,ys)
    if number == 3:
        xs = [x-0.4,x,x+0.4,x]
        ys = [y,y+0.4,y,y-0.4]
        stddraw.polygon(xs,ys)
        stddraw.setPenColor(stddraw.GREEN)
        stddraw.filledPolygon(xs,ys)
    if number == 4:
        xs = [x-0.4,x-0.2,x+0.2,x+0.4,x]
        ys = [y,y+0.4,y+0.4,y,y-0.4]
        stddraw.polygon(xs,ys)
        stddraw.setPenColor(stddraw.MAGENTA)
        stddraw.filledPolygon(xs,ys)
    if number == 5:
        xs = [x-0.4,x-0.2,x+0.4,x+0.2]
        ys = [y-0.4,y+0.4,y+0.4,y-0.4]
        stddraw.polygon(xs,ys)
        stddraw.setPenColor(stddraw.BLUE)
        stddraw.filledPolygon(xs,ys)
Beispiel #2
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)
Beispiel #3
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()
Beispiel #4
0
def draw_diamond():
    stddraw.setPenColor(stddraw.RED)
    stddraw.filledPolygon([5, 10, 5, 0], [0, 5, 10, 5])
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)
Beispiel #6
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
Beispiel #7
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()
Beispiel #8
0
def filledTriangle(x, y, length):
    xf = [x, x - length / 2, x + length / 2]
    yf = [y, y + height(length), y + height(length)]
    stddraw.filledPolygon(xf, yf)