forked from namankr1/SimPhy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SbyNLM.py
142 lines (132 loc) · 5.98 KB
/
SbyNLM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import pygame
import sys
import inputbox
from Button import Button
from anim1 import *
import errorScreen
from pygame.locals import *
from const_colors import *
import math
def compSbyNLM(DISPLAY_SURF):
print ("INSIDE SbyNLM.py")
btn_s1 = pygame.image.load('Images/buttons/parameters/s1.png')
btn_s2 = pygame.image.load('Images/buttons/parameters/s2.png')
btn_s3 = pygame.image.load('Images/buttons/parameters/s3.png')
btn_s4 = pygame.image.load('Images/buttons/parameters/s4.png')
btn_back = Button('Back')
btn_back.setColor(RED)
btn_back.setHoverColor(LIME)
btn_back.setFontColor(BLUE)
clock = pygame.time.Clock()
background=pygame.image.load('Images/game1/input_values.png')
run = True
while run:
DISPLAY_SURF.blit(background,SCREEN_TOPLEFT)
mouse = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if rect_s1.collidepoint(mouse):
countInputs = 1; # countInputs is related to the y coordinate of the input text boxes
initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial velocity, u",countInputs)
initial_velocity = float (initial_velocity)
countInputs = countInputs + 5;
acceleration = inputbox.ask(DISPLAY_SURF, "Acceleration, a",countInputs)
acceleration = float (acceleration)
countInputs = countInputs + 5;
time = inputbox.ask(DISPLAY_SURF, "Time, t",countInputs)
time = float (time)
if(time < 0):
errorScreen.errorScreen(DISPLAY_SURF,"Negative time entered")
run = False
displacement = initial_velocity*time + acceleration * time*time/2
final_velocity = initial_velocity + acceleration*time
font = pygame.font.Font(None, 36)
text = font.render("The Displacement hence calculated is "+ str(displacement) +"metre", 1, WHITE)
path = "Images/game1/Explanation/Calculate_S/G1/"
anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
run = False
elif rect_s2.collidepoint(mouse):
countInputs = 1; # countInputs is related to the y coordinate of the input text boxes
final_velocity = inputbox.ask(DISPLAY_SURF, "Final velocity, v",countInputs)
final_velocity = float (final_velocity)
countInputs = countInputs + 5;
acceleration = inputbox.ask(DISPLAY_SURF, "Acceleration, a",countInputs)
acceleration = float (acceleration)
countInputs = countInputs + 5;
time = inputbox.ask(DISPLAY_SURF, "Time, t",countInputs)
time = float (time)
if(time < 0):
errorScreen.errorScreen(DISPLAY_SURF,"Negative time entered")
run = False
displacement = final_velocity*time - acceleration * time*time/2
initial_velocity = final_velocity - acceleration*time
font = pygame.font.Font(None, 36)
text = font.render("The Displacement hence calculated is "+ str(displacement) +"metre", 1, WHITE)
path = "Images/game1/Explanation/Calculate_S/G2/"
anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
run = False
elif rect_s3.collidepoint(mouse):
countInputs = 1; # countInputs is related to the y coordinate of the input text boxes
initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial velocity, u",countInputs)
initial_velocity = float (initial_velocity)
countInputs = countInputs + 5;
final_velocity = inputbox.ask(DISPLAY_SURF, "Final velocity, v",countInputs)
final_velocity = float (final_velocity)
countInputs = countInputs + 5;
time = inputbox.ask(DISPLAY_SURF, "Time, t",countInputs)
time = float (time)
if(time < 0):
errorScreen.errorScreen(DISPLAY_SURF,"Negative time entered")
run = False
if(time == 0):
displacement = 0
acceleration = 0
else:
acceleration = (final_velocity - initial_velocity)/time
if(acceleration == 0):
displacement = initial_velocity*time
else :
displacement = (final_velocity*final_velocity - initial_velocity*initial_velocity)/2/acceleration
font = pygame.font.Font(None, 36)
text = font.render("The Displacement hence calculated is "+ str(displacement) +"metre", 1, WHITE)
path = "Images/game1/Explanation/Calculate_S/G3/"
anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
run = False
elif rect_s4.collidepoint(mouse):
countInputs = 1; # countInputs is related to the y coordinate of the input text boxes
initial_velocity = inputbox.ask(DISPLAY_SURF, "Initial velocity, u",countInputs)
initial_velocity = float (initial_velocity)
countInputs = countInputs + 5;
final_velocity = inputbox.ask(DISPLAY_SURF, "Final Velocity, v",countInputs)
final_velocity = float (final_velocity)
countInputs = countInputs + 5;
acceleration = inputbox.ask(DISPLAY_SURF, "Acceleration, a",countInputs)
acceleration = float (acceleration)
if (acceleration == 0):
displacement = 0
time = 0
else:
displacement = (final_velocity*final_velocity - initial_velocity*initial_velocity)/2/acceleration
time = (final_velocity - initial_velocity)/acceleration
if(time < 0):
errorScreen.errorScreen(DISPLAY_SURF,"Inconsistent data entered.(results to Negative time)")
run = False
font = pygame.font.Font(None, 36)
text = font.render("The Displacement hence calculated is "+ str(displacement) +"metre", 1, WHITE)
path = "Images/game1/Explanation/Calculate_S/G4/"
anim1(DISPLAY_SURF,text,final_velocity,initial_velocity,acceleration,time,displacement,path)
run = False
elif btn_back.obj.collidepoint(mouse):
run = False
rect_s1 = DISPLAY_SURF.blit(btn_s1,(125, 103))
rect_s2 = DISPLAY_SURF.blit(btn_s2,(125, 153))
rect_s3 = DISPLAY_SURF.blit(btn_s3,(125, 203))
rect_s4 = DISPLAY_SURF.blit(btn_s4,(125, 253))
btn_back.draw(DISPLAY_SURF,mouse,(550,10,45,20),(560,13))
pygame.display.update()
clock.tick(60)
print ("Exit from SbyNLM")