def draw(self):
     #stddraw.rectangle(x,y,w,h),x,y为左下角坐标
     x = self._x - self._width / 2
     y = self._y - self._height / 2
     # stddraw.setXscale(self._x-self._width/2-1,self._x+self._width/2+1)
     # stddraw.setYscale(self._y-self._height/2-1,self._y+self._height/2+1)
     stddraw.rectangle(x, y, self._width, self._height)
Exemple #2
0
def drawScene(black_hole_x, black_hole_y, ball_x, ball_y, goal_x, goal_y,
              neg_x, neg_y):
    '''
    handles the drawing of the ball, black box, goal box, and negative box
    '''
    stddraw.clear()
    stddraw.setPenColor(stddraw.BLACK)

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

    #black rectangle
    stddraw.filledRectangle(black_hole_x * GRID_SIZE, black_hole_y * GRID_SIZE,
                            GRID_SIZE, GRID_SIZE)

    #Ball
    stddraw.setPenColor(stddraw.GREEN)
    stddraw.filledCircle(((ball_x * GRID_SIZE) + (GRID_SIZE / 2)),
                         ((ball_y * GRID_SIZE) + (GRID_SIZE / 2)),
                         GRID_SIZE / 2)

    #Goal
    stddraw.setPenColor(stddraw.GREEN)
    stddraw.rectangle(goal_x * GRID_SIZE, goal_y * GRID_SIZE, GRID_SIZE,
                      GRID_SIZE)

    #Negative box
    stddraw.setPenColor(stddraw.RED)
    stddraw.rectangle(neg_x * GRID_SIZE, neg_y * GRID_SIZE, GRID_SIZE,
                      GRID_SIZE)
Exemple #3
0
 def draw_score(self, score):
     stddraw.setPenColor(self.boundary_color)  # using boundary_color
     # set the pen radius
     stddraw.setPenRadius(self.box_thickness)
     # coordinates of the bottom left corner of the game grid
     pos_x, pos_y = self.grid_width - 0.5, -0.5
     stddraw.rectangle(pos_x, pos_y, 3.5, self.grid_height)
     stddraw.setPenColor(Color(167, 160, 151))
     stddraw.filledRectangle(pos_x + 0.03, pos_y + 0.09, 3.4,
                             self.grid_height - 0.2)
     # set the text
     text_color = Color(0, 0, 0)
     stddraw.setFontFamily("Arial")
     stddraw.setFontSize(30)
     stddraw.setPenColor(text_color)
     text_to_display = "SCORE"
     text_to_display2 = "NEXT"
     stddraw.text(12 + 1.2, 5, text_to_display2)
     stddraw.text(self.grid_width + 1.2, 15, text_to_display)
     stddraw.text(self.grid_width + 1.2, 14, str(score))
     # get the tetromino's type to create next tetromino to show in the next section
     tet_type = self.current_tetromino.get_type()
     if tet_type == 'I':
         width = 4
         height = 11
     elif tet_type == 'O':
         width = 2
         height = 12
     else:
         width = 3
         height = 11
     next_tetromino = Tetromino(tet_type, height, width)
     next_tetromino.draw_next_tet(self.current_tetromino)
     stddraw.setPenRadius()  # reset the pen radius to its default value
def white_key(x, y, is_pressed):
    stddraw.setPenColor(stddraw.BLACK)
    stddraw.rectangle(x, y, 48, 300)
    if is_pressed:
        stddraw.setPenColor(stddraw.RED)
    else:
        stddraw.setPenColor(stddraw.WHITE)
    stddraw.filledRectangle(x, y, 48, 300)
Exemple #5
0
 def draw_boundaries(self):
    # draw a bounding box around the game grid as a rectangle
    stddraw.setPenColor(self.boundary_color)  # using boundary_color
    # set the pen radius as box_thickness (half of this thickness is visible 
    # for the bounding box as its lines lie on the boundaries of the canvas)
    stddraw.setPenRadius(self.box_thickness)
    # coordinates of the bottom left corner of the game grid
    pos_x, pos_y = -0.5, -0.5
    stddraw.rectangle(pos_x, pos_y, self.grid_width, self.grid_height)
    stddraw.setPenRadius()  # reset the pen radius to its default value
Exemple #6
0
   def display(self,pause):
      # clear the background canvas to empty_cell_color
      stddraw.clear(self.empty_cell_color)
      # SCORE
      stddraw.setFontSize(28)
      stddraw.setPenColor(stddraw.WHITE)
      stddraw.boldText(self.grid_width + 2, self.grid_height - 1, "SCORE")
      stddraw.rectangle(self.grid_width, self.grid_height - 3.5, 4, 2)
      stddraw.boldText(self.grid_width + 2, self.grid_height - 2.5, str(self.total_score))

      # Controls
      stddraw.setFontSize(18)
      stddraw.setPenColor(stddraw.DARK_GRAY)
      stddraw.boldText(self.grid_width + 2, self.grid_height - 6, "Controls")

      stddraw.setFontSize(12)
      stddraw.boldText(self.grid_width + 2, self.grid_height - 7, "← Left Key the tetromino left by on")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 7.5, "→ Right Key the tetro right by on")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 8, "P to Pause")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 8.5, "E/Q to Rotate")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 9, "Current Speed: {:.2f}".format((1/self.delta_time)*1000))
      stddraw.boldText(self.grid_width + 2, self.grid_height - 9.5, "W to Faster Down")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 10, "S to Slower Down")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 10.5, "R to Restart ")
      stddraw.boldText(self.grid_width + 2, self.grid_height - 11,"Space to drop tetromino")


      stddraw.setFontSize(24)
      stddraw.setPenColor(stddraw.WHITE)
      stddraw.text(self.grid_width+2, self.grid_height-12 , "next")
      stddraw.rectangle(self.grid_width,self.grid_height-18,4,5)
      # draw the game grid
      self.next_tetromino.draw_dummy()
      self.draw_grid()
      # draw the current (active) tetromino
      if self.current_tetromino != None:
         self.current_tetromino.draw()
      # draw a box around the game grid 
      self.draw_boundaries()

      if(pause):
         stddraw.setPenColor(stddraw.BLACK)
         stddraw.setFontSize(32)
         stddraw.text(self.grid_width/2,self.grid_height/2,"Game is Paused")
      # show the resulting drawing with a pause duration = 250 ms
      stddraw.show(self.delta_time)
def clicked_handler(posx, posy, first_taffy):
    row = (int(posx / taffy_spacing_horizontal))  #row of selected taffy
    column = (int(
        ((posy - 1) * -1) / taffy_spacing_vertical))  #column of selected taffy

    if first_taffy:
        #draw rectangular selection for taffy 1
        stddraw.rectangle(
            (row * taffy_spacing_horizontal) + selected_rectangle_offset,
            (1 - (column * taffy_spacing_vertical)) - taffy_spacing_vertical,
            taffy_spacing_horizontal, taffy_spacing_vertical)

    #return the taffy type selected, and location
    taffy = richardnorman_p2_taffy.Taffy()
    taffy.row = row
    taffy.column = column
    taffy.taffy_type = board_array[column][row]
    return taffy
def draw_hanging_man(guesses_remaining):
    #draw floor
    stddraw.line(0.2, 0.4, 0.8, 0.4)
    stddraw.rectangle(0.3, 0.4, 0.4, 0.04)
    if guesses_remaining <= 7:
        #head
        stddraw.circle(0.5, 0.8, 0.07)
        if guesses_remaining <= 6:
            #torso
            stddraw.line(0.5, 0.73, 0.5, 0.55)
            if guesses_remaining <= 5:
                #left arm
                stddraw.line(0.5, 0.73, 0.425, 0.655)
                if guesses_remaining <= 4:
                    #right arm
                    stddraw.line(0.5, 0.73, 0.575, 0.655)
                    if guesses_remaining <= 3:
                        #left leg
                        stddraw.line(0.5, 0.55, 0.425, 0.465)
                        if guesses_remaining <= 2:
                            #right leg
                            stddraw.line(0.5, 0.55, 0.575, 0.465)
                            if guesses_remaining <= 1:
                                #gallows
                                stddraw.line(0.7, 0.404, 0.7, 0.9)
                                stddraw.line(0.7, 0.9, 0.5, 0.9)
                                stddraw.line(0.5, 0.9, 0.5, 0.87)
                                if guesses_remaining == 0:
                                    #face
                                    #left eye
                                    stddraw.line(0.465, 0.82, 0.485, 0.8)
                                    stddraw.line(0.485, 0.82, 0.465, 0.8)

                                    #right eye
                                    stddraw.line(0.515, 0.82, 0.535, 0.8)
                                    stddraw.line(0.535, 0.82, 0.515, 0.8)
                                    #mouth
                                    stddraw.line(0.475, 0.775, 0.525, 0.775)
            while str(pixel) != WEIGHT:
                pixel = pic.get(col,row)
                col += 1
            te[row] = [row,col]
        col += 10
    row += 10
    col = 0

temp1 = 0
temp2 = 0
for i in range(h):
    if temp1 < tb[i][0]:
        temp1 = tb[i][0]
        temp2 = te[i][0]
print(temp1)
print(temp2)

'''
temp2 = w
for i in range(h):
    if te[i][0] != 0:
        if temp2 > te[i][0]:
            temp2 = te[i][0]
print(temp2)
'''
#stddraw.picture(pic)
stddraw.rectangle(temp1,0,temp2-temp1+1,h)
stddraw.rectangle(1,1,10,10)
stddraw.show()

 def draw(self):
     #stddraw.rectangle(x,y,w,h),x,y为左下角坐标
     x = self._x-self._width/2
     y = self._y-self._height/2
     stddraw.rectangle(x,y,self._width,self._height)
     stddraw.show()
"""
This program is so simple that I don't need the usual DISCLAIMER...

Example of using the Color and Picture data types from the booksite library.
"""

from color import Color
from picture import Picture
import stddraw

turquoise = Color(64, 224, 208)
stddraw.setPenColor(turquoise)
stddraw.setPenRadius(0.025)
stddraw.rectangle(.1, .1, .8, .8)

my_picture = Picture('karel.png')
stddraw.picture(my_picture, 0.5, 0.6)

stddraw.setPenColor(stddraw.BLACK)
stddraw.setFontSize(64)
stddraw.text(0.5, 0.25, 'I live!')
stddraw.show()
help(stddraw)

Exemple #12
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
Exemple #13
0
def drawbox(x, y):
    stddraw.rectangle(x, y, 0.1, 0.1)
Exemple #14
0
def tileSelectedClear(x, y):
    stddraw.setPenColor(stddraw.WHITE)
    stddraw.rectangle(x + 0.03, y + 0.02, (1 / 1.5) - 0.05, 0.90)
Exemple #15
0
def tileSelected(x, y):
    stddraw.setPenColor(stddraw.MAGENTA)
    stddraw.rectangle(x + 0.03, y + 0.02, (1 / 1.5) - 0.05, 0.90)