Jump to content

Talk:Coding

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 152.58.159.34 (talk) at 04:33, 31 January 2025 (Science maths: new section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Science maths

import pygame import math

  1. Initialize Pygame

pygame.init()

  1. Screen setup

width, height = 800, 600 screen = pygame.display.set_mode((width, height)) clock = pygame.time.Clock()

  1. Colors

red = (255, 0, 0) black = (0, 0, 0) white = (255, 255, 255)

  1. Triangle points

triangle_points = [(400, 100), (200, 500), (600, 500)]

  1. Ball position and angle

ball_radius = 20 angle = 0

  1. 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)[reply]