-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |