Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tfya87-simulation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacob Slunga
tfya87-simulation
Commits
9008dde5
Commit
9008dde5
authored
8 months ago
by
Jacob Slunga
Browse files
Options
Downloads
Patches
Plain Diff
done
parent
0350461e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+29
-5
29 additions, 5 deletions
main.py
with
29 additions
and
5 deletions
main.py
+
29
−
5
View file @
9008dde5
...
...
@@ -10,7 +10,7 @@ background_img = pygame.image.load("galaxy.jpg").convert()
sun_img_original
=
pygame
.
image
.
load
(
"
sun.png
"
).
convert_alpha
()
sun_img_original
=
pygame
.
transform
.
scale
(
sun_img_original
,
(
50
,
50
)
)
# Initial sun size
)
earth_img
=
pygame
.
image
.
load
(
"
earth.png
"
).
convert_alpha
()
earth_img
=
pygame
.
transform
.
scale
(
earth_img
,
(
20
,
20
))
mars_img
=
pygame
.
image
.
load
(
"
mars.jpeg
"
).
convert_alpha
()
...
...
@@ -25,13 +25,18 @@ font = pygame.font.SysFont(None, 24)
initial_sun_mass
=
1.989e30
*
mass_scale
sun_mass
=
initial_sun_mass
scale_factor
=
0.
05
# Reduced scale factor for more control
max_size
=
200
# Limit maximum sun sprite size
scale_factor
=
0.
3
max_size
=
200
def
update_sun_sprite
():
ratio
=
sun_mass
/
initial_sun_mass
sun_size
=
min
(
int
(
50
+
scale_factor
*
ratio
*
50
),
max_size
)
sun_size
=
min
(
int
(
50
+
scale_factor
*
ratio
*
50
),
max_size
)
print
(
f
"
Sun size (pixels):
{
sun_size
}
, Ratio:
{
ratio
:
.
2
f
}
"
)
return
pygame
.
transform
.
scale
(
sun_img_original
,
(
sun_size
,
sun_size
)),
ratio
...
...
@@ -41,11 +46,18 @@ sun_img, sun_ratio = update_sun_sprite()
class
Planet
:
def
__init__
(
self
,
image
,
pos
,
mass
,
velocity
=
(
0
,
0
)):
self
.
image
=
image
self
.
initial_pos
=
pygame
.
Vector2
(
pos
)
self
.
initial_velocity
=
pygame
.
Vector2
(
velocity
)
self
.
pos
=
pygame
.
Vector2
(
pos
)
self
.
mass
=
mass
self
.
velocity
=
pygame
.
Vector2
(
velocity
)
self
.
path
=
[]
def
reset
(
self
):
self
.
pos
=
self
.
initial_pos
self
.
velocity
=
self
.
initial_velocity
self
.
path
=
[]
def
gravitational_force
(
self
,
sun_pos
,
sun_mass
):
distance
=
self
.
pos
.
distance_to
(
sun_pos
)
direction
=
(
sun_pos
-
self
.
pos
).
normalize
()
...
...
@@ -122,9 +134,19 @@ mars = Planet(
increase_sun_mass
=
Button
(
10
,
730
,
150
,
30
,
"
Increase Sun Mass
"
)
decrease_sun_mass
=
Button
(
10
,
770
,
150
,
30
,
"
Decrease Sun Mass
"
)
reset_button
=
Button
(
10
,
810
,
150
,
30
,
"
Reset Simulation
"
)
dt
=
3600
def
reset_simulation
():
global
sun_mass
,
sun_img
,
sun_ratio
sun_mass
=
initial_sun_mass
sun_img
,
sun_ratio
=
update_sun_sprite
()
earth
.
reset
()
mars
.
reset
()
running
=
True
while
running
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -144,6 +166,8 @@ while running:
elif
decrease_sun_mass
.
is_clicked
(
event
):
sun_mass
*=
0.9
sun_img
,
sun_ratio
=
update_sun_sprite
()
elif
reset_button
.
is_clicked
(
event
):
reset_simulation
()
screen
.
blit
(
background_img
,
(
0
,
0
))
scaled_sun_img
=
pygame
.
transform
.
scale
(
...
...
@@ -168,8 +192,8 @@ while running:
increase_sun_mass
.
draw
(
screen
)
decrease_sun_mass
.
draw
(
screen
)
reset_button
.
draw
(
screen
)
# Display Sun's mass ratio
ratio_text
=
font
.
render
(
f
"
Sun Size Ratio:
{
sun_ratio
:
.
2
f
}
"
,
True
,
(
255
,
255
,
255
))
screen
.
blit
(
ratio_text
,
(
10
,
10
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment