Talk:Coding
Appearance
![]() | This disambiguation page does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||
|
Science maths
import pygame import math
- Initialize Pygame
pygame.init()
- Screen setup
width, height = 800, 600 screen = pygame.display.set_mode((width, height)) clock = pygame.time.Clock()
- Colors
red = (255, 0, 0) black = (0, 0, 0) white = (255, 255, 255)
- Triangle points
triangle_points = [(400, 100), (200, 500), (600, 500)]
- Ball position and angle
ball_radius = 20 angle = 0
- Main loop
running = True while running:
for event in pygame.event.get(): if event.type == pygame.QUIT: running = False
# Clear screen screen.fill(white)
# Draw triangle pygame.draw.polygon(screen, black, triangle_points, 2)
# Calculate ball position ball_x = 400 + 200 * math.cos(angle) ball_y = 300 + 200 * math.sin(angle)
# Draw ball pygame.draw.circle(screen, red, (int(ball_x), int(ball_y)), ball_radius)
# Update angle angle += 0.02
# Update display pygame.display.flip() clock.tick(60)
pygame.quit() 152.58.159.34 (talk) 04:33, 31 January 2025 (UTC)