Guest User

Pygame source code example

a guest
Feb 28th, 2024
242
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | Source Code | 0 0
  1. import pygame
  2. import sys
  3.  
  4. # Initialize Pygame
  5. pygame.init()
  6.  
  7. # Set up display
  8. width, height = 800, 600
  9. screen = pygame.display.set_mode((width, height))
  10. pygame.display.set_caption("Mechanical Arm Thrusting")
  11.  
  12. # Define colors
  13. white = (255, 255, 255)
  14.  
  15. # Define mechanical arm parameters
  16. arm_length = 100
  17. arm_thickness = 20
  18. joint_radius = 10
  19. thrust_distance = 50
  20. thrust_speed = 5
  21.  
  22. # Initial arm angles
  23. base_angle = 0
  24. arm_angle = 45
  25.  
  26. # Main game loop
  27. clock = pygame.time.Clock()
  28.  
  29. while True:
  30.     for event in pygame.event.get():
  31.         if event.type == pygame.QUIT:
  32.             pygame.quit()
  33.             sys.exit()
  34.  
  35.     # Update arm angles
  36.     arm_angle += thrust_speed
  37.     if arm_angle >= 135 or arm_angle <= 45:
  38.         thrust_speed = -thrust_speed
  39.  
  40.     # Calculate arm positions
  41.     base_x, base_y = width // 2, height // 2
  42.     arm_x = base_x + arm_length * pygame.math.Vector2(1, 0).rotate(base_angle)
  43.     arm_y = base_y + arm_length * pygame.math.Vector2(1, 0).rotate(base_angle + arm_angle)
  44.  
  45.     # Draw background
  46.     screen.fill(white)
  47.  
  48.     # Draw base joint
  49.     pygame.draw.circle(screen, white, (int(base_x), int(base_y)), joint_radius)
  50.  
  51.     # Draw arm
  52.     pygame.draw.line(screen, white, (base_x, base_y), (arm_x, arm_y), arm_thickness)
  53.  
  54.     # Update display
  55.     pygame.display.flip()
  56.  
  57.     # Cap the frame rate
  58.     clock.tick(3)
Advertisement
Comments
  • Kjw1
    2 years
    # text 0.10 KB | 0 0
    1. No love line has errors pydroid tells me. Is it lying toe trying to gete to commit suicide or are you?
Add Comment
Please, Sign In to add comment