Simple Pendulum inspired from the coding channel The Coding Train!
Code in Python:
import pygame
import math
import sys
pygame.init()
width = 640
height = 360
window = pygame.display.set_mode((width, height))
pygame.display.set_caption('Simple Pendulum')
#Constants
BLACK = (0,0,0)
WHITE = (255,255,255)
PI = 3.14159
#Variables
length = 200
origin = [width//2, 0]
Bob = [width//2, length]
angle = PI/4
aVel = 0.0
aAcc = 0.0
while True:
window.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
Bob[0] = int(origin[0] + length*math.sin(angle))
Bob[1] = int(origin[1] + length*math.cos(angle))
pygame.draw.line(window, BLACK, (origin[0], origin[1]), (Bob[0], Bob[1]), 1)
pygame.draw.circle(window, BLACK, (Bob[0], Bob[1]), 20)
aAcc = 0.00001*math.sin(angle)
angle += aVel
aVel -= aAcc
aVel *= 0.99995
pygame.display.update()
Ещё видео!