10 examples of 'pygame draw rect' in Python

Every line of 'pygame draw rect' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
123def draw_alpha_rect(self, rect, color, alpha):
124 x, y = self.map_point((rect[0], rect[1]))
125 w, h = int(self.scale*rect[2]), int(self.scale*rect[3])
126 s = pygame.Surface((w, h), pygame.SRCALPHA) # per-pixel alpha
127 s.fill(color + (alpha,))
128 # print(y, self.h)
129 self.surface.blit(s, (x, y-h))
52def draw(self):
53 self.screen.fill((0, 100, 0))
54 pygame.draw.rect(self.screen, (135, 206, 235), pygame.Rect(0, 0, self.width, 100))
55 for i in range(2):
56 if self.dead[i]:
57 img = CrackGame.DEAD_IMAGE
58 elif not self.jumps[i]:
59 img = CrackGame.IMAGES[self.current_frame]
60 else:
61 img = CrackGame.JUMP_IMAGE
62
63 pygame.draw.rect(self.screen, (200, 200, 200), pygame.Rect(0, self.sidewalk_y + i*2*self.sidewalk_height, self.width, self.sidewalk_height))
64 pygame.draw.rect(self.screen, (150, 150, 150), pygame.Rect(0, self.sidewalk_y+self.sidewalk_height + i*2*self.sidewalk_height, self.width, self.sidewalk_height/5))
65 p = 0
66 for crack in self.cracks:
67 pygame.draw.aaline(self.screen, (0, 0, 0), (p + crack - 10, self.sidewalk_y+self.sidewalk_height + i*2*self.sidewalk_height), (p + crack + 10, self.sidewalk_y + i*2*self.sidewalk_height))
68 pygame.draw.aaline(self.screen, (0, 0, 0), (p + crack - 10, self.sidewalk_y+self.sidewalk_height + i*2*self.sidewalk_height), (p + crack - 10, self.sidewalk_y+self.sidewalk_height + i*2*self.sidewalk_height + self.sidewalk_height/5))
69 p += crack
70 if not self.jumping[i]:
71 if (self.positions[i][0] < self.width) and (self.positions[i][0] - img.get_rect().width/4 < p < self.positions[i][0] + img.get_rect().width/4):
72 self.dead[i] = True
73
74 if not self.dead[i]:
75 width = img.get_rect().width - ((self.sidewalk_y+self.sidewalk_height/2 + 2*i*self.sidewalk_height - self.positions[i][1]) / 8)
76 pygame.draw.ellipse(self.screen, (180, 180, 180), pygame.Rect(self.positions[i][0] - img.get_rect().width/2, self.sidewalk_y + i*2*self.sidewalk_height + 60, width, 20))
77 self.screen.blit(img, pygame.Rect(self.positions[i][0] - img.get_rect().width/2, self.positions[i][1] - 0.75*img.get_rect().height, img.get_rect().width, img.get_rect().height))
38def draw(self):
39 x = self.loc.x * CELLSIZE
40 y = self.loc.y * CELLSIZE
41 apple_rect = pygame.Rect(x, y, CELLSIZE, CELLSIZE)
42 pygame.draw.rect(screen, RED, apple_rect)
60def draw(self, surface):
61 if self._apple_image is not None:
62 surface.blit(self._apple_image, (self.x, self.y))
63 else:
64 pygame.draw.rect(surface, self.color,
65 (self.x, self.y, self.size, self.size), 0)
30def draw(self, screen, color):
31 l = self.block
32 for (x, y) in self.list:
33 draw.rect(screen, color, (x, y, l, l), 1)
34 draw.rect(screen, color, (x+3, y+3, l-6, l-6))
35 return screen
194def paint(self,screen):
195 pygame.draw.rect(screen,self.color,self.rect,0)
491def draw(self, view):
492
493 view.rectangle((self.x, self.y, self.width, self.height), self.color)
48def draw_rect(self, rect, color):
49 r, g, b = color
50 r /= float(0xff)
51 g /= float(0xff)
52 b /= float(0xff)
53 x, y, width, height = rect
54 # the y direction is flipped but this fixes it :)
55 y = self.height - y - height
56
57 glColor3f(r, g, b)
58 glBegin(GL_QUADS)
59 glVertex2f(x, y)
60 glVertex2f(x + width, y)
61 glVertex2f(x + width, y + height)
62 glVertex2f(x, y + height)
63 glEnd()
38def draw(self, win):
39 pygame.draw.rect(win, (0,0,0), (self.x - self.BORDER_THICKNESS/2, self.y-self.BORDER_THICKNESS/2, self.WIDTH + self.BORDER_THICKNESS, self.HEIGHT + self.BORDER_THICKNESS), self.BORDER_THICKNESS)
40 for y, _ in enumerate(self.board):
41 for x, col in enumerate(self.board[y]):
42 pygame.draw.rect(win, col, (self.x + x*8, self.y + y*8, 8, 8), 0)
154def draw(self):
155 #draw background image
156 self.draw_background()
157
158 #draw game field crap here
159
160 #decide if we should draw grid.
161 if self.options['draw_grid']:
162 self.draw_grid()
163
164 #Only stuff being drawn right now.
165 #Message board with x button
166 self.tboard.draw()
167
168 if self.button.is_visible():
169 self.button.draw()
170
171 if self.togglebtn.is_visible():
172 self.togglebtn.draw()

Related snippets