Nov-17-2020, 05:12 PM
SCREEN_WIDTH = 1500 SCREEN_HEIGHT = 750 background = pygame.image.load(r'C:\Users\ga-sa\Downloads\honeycomb.png') background = pygame.transform.scale(BACKGROUND, (SCREEN_WIDTH, SCREEN_HEIGHT)) img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") img2 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsXOR.png") img3 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsNOT.png") img4 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsAND.png") images = [img1, img2, img3, img4] current_image = -1 img_rects = [images[i].get_rect(topleft=(20 + 40 * i, 20)) for i in range(len(images))] img_angles = [0 for _ in range(len(images))] LeftButton = 0 while 1: for e in pygame.event.get(): if e.type == QUIT: pygame.quit() exit(0) if e.type == pygame.MOUSEBUTTONDOWN: mouse_rect = pygame.Rect(e.pos, (1, 1)) current_image = mouse_rect.collidelist(img_rects) if e.type == MOUSEMOTION: if e.buttons[LeftButton]: rel = e.rel if 0 <= current_image < len(images): img_rects[current_image].x += rel[0] img_rects[current_image].y += rel[1] keys = pygame.key.get_pressed() if keys[pygame.K_RIGHT]: img_angles[current_image] -= 1 if keys[pygame.K_LEFT]: img_angles[current_image] += 1 screen.blit(background, (0,0)) for i in range(len(images)): rotated_image = pygame.transform.rotate(images[i], img_angles[i]) rotated_rect = rotated_image.get_rect(center=img_rects[i].center) screen.blit(rotated_image, rotated_rect) pygame.display.flip() the second code that i like to put in the first: def main() pygame.init() pygame.display.set_caption("Mouse Draw") surface = pygame.display.set_mode((800, 600)) clock = pygame.time.Clock() rect = surface.get_rect() fps = 60 line_surface = pygame.Surface(rect.size, pygame.SRCALPHA) line_surface.fill((0, 0, 0, 0)) mouse_position = None display_line = None running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEMOTION: if mouse_position: display_line = mouse_position, event.pos elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: if mouse_position: pygame.draw.line(line_surface, pygame.Color("red"), mouse_position, event.pos) mouse_position = None display_line = None else: mouse_position = event.pos surface.fill(pygame.Color('black')) surface.blit(line_surface, (0, 0)) if display_line: pygame.draw.line(surface, pygame.Color('lawngreen'), *display_line) pygame.display.update() clock.tick(fps) main ()