Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
waddyado committed Sep 19, 2020
1 parent fde1d73 commit e9cc5a8
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
61 changes: 61 additions & 0 deletions 2D Physics engine/calculate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import math
import time

def eq1():
df = 0
di = input('enter di(m):>')
v = input('enter v(m/s):>')
t = input('enter t(s):>')
di = int(di)
v = int(v)
t = int(t)
vt = v * t
vt = int(vt)
df = di + vt
print(df, ' meters')

def eq2():
vf = 0
a = input('enter a(m/s^2):>')
t = input('enter t(s):>')
vi = input('enter vi(m/s):>')
if a == '9.80':
a = 9.80
t = int(t)
vi = int(vi)
at = a * t
at = int(at)
vf = at + vi
print(vf, 'm/s')

def eq3():
df = 0
di = input('enter di(m):>')
vi = input('enter vi(m/s):>')
t = input('enter t(s):>')
a = input('enter a(m/s^2):>')
di = int(di)
vi = int(vi)
t = int(t)
a = int(a)
at = a * t
vit = vi * t
onehalf = 0.5
onehalfat = onehalf * at
onehalfatsq = onehalfat ** 2
df = di + vit + onehalfatsq
print(df, 'meters')

def eq4():
vf = 0
vi = input('enter vi(m/s):>')
a = input('enter a(m/s^2):>')
deltad = input('enter deltad(m):>')
vi = int(vi)
a = int(a)
deltad = int(deltad)
visq = vi ** 2
twoa = a * 2
twoadeltad = twoa * deltad
vf = math.sqrt(visq + twoadeltad)
print(vf, 'm/s')
24 changes: 24 additions & 0 deletions 2D Physics engine/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import calculate
import time

def main():
print('Physics simulator')
print('type your number equation(1-4) or ')
print('type ball to simulate a ball drop')
inp = input(':>')
if inp == '1':
calculate.eq1()
if inp == '2':
calculate.eq2()
if inp == '3':
calculate.eq3()
if inp == '4':
calculate.eq4()
if inp == 'ball':
import simulate
simulate.main()
else:
time.sleep(1)
main()

main()
65 changes: 65 additions & 0 deletions 2D Physics engine/simulate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

import pygame

pygame.init()

global w, h

w,h = 1024,1024
screen = pygame.display.set_mode((w,h))

def main(a = 9.8, hdamp = 0.1, damp = 0.05):
ball_x = input('enter x:>')
ball_y = input('enter y:>')
ball_x = int(ball_x)
ball_y = int(ball_y)
ball_x_v = input('enter horizontal velocity(m/s):>')
ball_y_v = input('enter vertical velocity(m/s):>')
ball_y = int(ball_y)
ball_x_v = int(ball_x_v)
ball_y_v = int(ball_y_v)
w,h = 1280,1280
screen = pygame.display.set_mode((w,h))

while True:

screen.fill((0,0,0))

ball_y_v += (a / 125)

ball_x += ball_x_v
ball_y += ball_y_v

if ball_x <= 0:

ball_x_v = -ball_x_v*(1-damp)
ball_x = 1

if ball_y <= 0:

ball_y_v = -ball_y_v*(1-damp)

ball_x_v = ball_x_v*(1-hdamp)

ball_y = 1

if ball_x >= w:

ball_x_v = -ball_x_v*(1-damp)

ball_x = w - 1

if ball_y >=h:

ball_y_v = -ball_y_v*(1-damp)

ball_y = h - 1


pygame.draw.circle(screen, (255,255,255), (int(ball_x), int(ball_y)), 5)

pygame.display.update()

if __name__ == '__main__':

main()

0 comments on commit e9cc5a8

Please sign in to comment.