Skip to content

Commit

Permalink
drawing scale bar in Kinematics
Browse files Browse the repository at this point in the history
  • Loading branch information
rohilvagarwal committed Jun 1, 2023
1 parent 85b9c45 commit 6d8a52a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
31 changes: 19 additions & 12 deletions Kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def draw_static(self, screen):
#ground
pygame.draw.rect(screen, objectsColor, (0, Kinematics.groundHeight, SCREEN_WIDTH, 10))

#draw scale bar (1 pixel is 1m)
pygame.draw.rect(screen, objectsColor, (SCREEN_WIDTH - 25 - 100 - 4, 75 + 20 - 2, 100, 4)) #bar
pygame.draw.rect(screen, objectsColor, (SCREEN_WIDTH - 25 - 100 - 4 - 4, 75 + 20 - 10, 4, 20)) #left edge
pygame.draw.rect(screen, objectsColor, (SCREEN_WIDTH - 25 - 4, 75 + 20 - 10, 4, 20)) #right edge
draw_text_center(screen, SCREEN_WIDTH - 25 - 50 - 4, 75 + 20 + 10, 15, "100m")
draw_text_right(screen, SCREEN_WIDTH - 25, 12, 15, "*Each Pixel is 1m")

#mass
pygame.draw.circle(screen, objectsColor, (self.currentCenterX, self.currentCenterY), Kinematics.massRadius)

Expand All @@ -135,24 +142,24 @@ def draw_static(self, screen):
draw_text_right(screen, SCREEN_WIDTH - 10, 412, 10, "exceed the edge!")

if not self.state == "doneAnimating":
draw_text_right(screen, SCREEN_WIDTH - 130, 100, 20, "Time:")
draw_text_left(screen, SCREEN_WIDTH - 120, 100, 20, str("{:.3f}".format(self.currentTime)) + " s")
draw_text_right(screen, SCREEN_WIDTH - 130, 140, 20, "Time:")
draw_text_left(screen, SCREEN_WIDTH - 120, 140, 20, str("{:.3f}".format(self.currentTime)) + " s")

draw_text_right(screen, SCREEN_WIDTH - 130, 130, 20, "Speed:")
draw_text_left(screen, SCREEN_WIDTH - 120, 130, 20, str(self.playBackSpeed) + "x")
draw_text_right(screen, SCREEN_WIDTH - 130, 170, 20, "Speed:")
draw_text_left(screen, SCREEN_WIDTH - 120, 170, 20, str(self.playBackSpeed) + "x")

draw_text_right(screen, SCREEN_WIDTH - 130, 160, 20, "Max Height:")
draw_text_left(screen, SCREEN_WIDTH - 120, 160, 20, "?")
draw_text_right(screen, SCREEN_WIDTH - 130, 200, 20, "Max Height:")
draw_text_left(screen, SCREEN_WIDTH - 120, 200, 20, "?")

if self.state == "doneAnimating":
draw_text_right(screen, SCREEN_WIDTH - 130, 100, 20, "Time:")
draw_text_left(screen, SCREEN_WIDTH - 120, 100, 20, str("{:.3f}".format(self.calculate_time_till_ground())) + " s")
draw_text_right(screen, SCREEN_WIDTH - 130, 140, 20, "Time:")
draw_text_left(screen, SCREEN_WIDTH - 120, 140, 20, str("{:.3f}".format(self.calculate_time_till_ground())) + " s")

draw_text_right(screen, SCREEN_WIDTH - 130, 130, 20, "Speed:")
draw_text_left(screen, SCREEN_WIDTH - 120, 130, 20, str(self.playBackSpeed) + "x")
draw_text_right(screen, SCREEN_WIDTH - 130, 170, 20, "Speed:")
draw_text_left(screen, SCREEN_WIDTH - 120, 170, 20, str(self.playBackSpeed) + "x")

draw_text_right(screen, SCREEN_WIDTH - 130, 160, 20, "Max Height:")
draw_text_left(screen, SCREEN_WIDTH - 120, 160, 20,
draw_text_right(screen, SCREEN_WIDTH - 130, 200, 20, "Max Height:")
draw_text_left(screen, SCREEN_WIDTH - 120, 200, 20,
str("{:.3f}".format(self.calculate_vertical_position(self.calculate_time_max_height()))) + " m")

if self.arrowWidth < self.calculate_total_horizontal_distance() - Kinematics.massRadius - 20:
Expand Down
6 changes: 3 additions & 3 deletions PhysicsStudy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
kinematicsHeightBar = SliderBar(250, SCREEN_HEIGHT - 50, 200, 20, 0, 500, 250, "Height (m)")
kinematicsVelocityBar = SliderBar(475, SCREEN_HEIGHT - 50, 200, 20, 0, 100, 50, "Initial Velocity (m/s)")
launchButton = Button(centerX=SCREEN_WIDTH - 125, centerY=SCREEN_HEIGHT - 40, width=200, height=50, textSize=30, borderSize=10, text="Launch")
oneXSpeed = Button(centerX=300, centerY=SCREEN_HEIGHT - 110, width=40, height=40, textSize=20, borderSize=10, text="1x")
threeXSpeed = Button(centerX=350, centerY=SCREEN_HEIGHT - 110, width=40, height=40, textSize=20, borderSize=10, text="3x")
fiveXSpeed = Button(centerX=400, centerY=SCREEN_HEIGHT - 110, width=40, height=40, textSize=20, borderSize=10, text="5x")
oneXSpeed = Button(centerX=210, centerY=SCREEN_HEIGHT - 110, width=40, height=40, textSize=20, borderSize=10, text="1x")
threeXSpeed = Button(centerX=260, centerY=SCREEN_HEIGHT - 110, width=40, height=40, textSize=20, borderSize=10, text="3x")
fiveXSpeed = Button(centerX=310, centerY=SCREEN_HEIGHT - 110, width=40, height=40, textSize=20, borderSize=10, text="5x")

#circularMotion
circularMotionObj = CircularMotion(SCREEN_WIDTH / 2 - 250, CircularMotion.groundHeight / 2, 100)
Expand Down

0 comments on commit 6d8a52a

Please sign in to comment.