Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Personal Website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
Personal Website
Commits
54455094
Verified
Commit
54455094
authored
Aug 5, 2024
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Prep for changing velocities
parent
2513e17a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
static/js/background_anim.js
+27
-4
27 additions, 4 deletions
static/js/background_anim.js
with
27 additions
and
4 deletions
static/js/background_anim.js
+
27
−
4
View file @
54455094
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
const
FPS
=
60
;
const
FPS
=
60
;
const
DOTS_NUM_VALUES
=
[
100
,
75
];
const
DOTS_NUM_VALUES
=
[
100
,
75
];
const
VELOCITY_MAX_VALUES
=
[
25
,
15
];
const
INITIAL_VELOCITY_MAX_VALUES
=
[
25
,
15
];
const
VELOCITY_MAX_VALUES
=
[
40
,
30
];
const
RADIUS_MIN_VALUES
=
[
2
,
0.5
];
const
RADIUS_MIN_VALUES
=
[
2
,
0.5
];
const
RADIUS_MAX_VALUES
=
[
6
,
2
];
const
RADIUS_MAX_VALUES
=
[
6
,
2
];
const
LINE_DISTANCE_MAX_VALUES
=
[
120
,
55
];
const
LINE_DISTANCE_MAX_VALUES
=
[
120
,
55
];
...
@@ -18,7 +19,8 @@ const LINE_COLOUR = "#777";
...
@@ -18,7 +19,8 @@ const LINE_COLOUR = "#777";
// Sort-of constants (change with window size)
// Sort-of constants (change with window size)
let
DOTS_NUM
=
100
;
let
DOTS_NUM
=
100
;
let
VELOCITY_MAX
=
25
;
let
INITIAL_VELOCITY_MAX
=
25
;
let
VELOCITY_MAX
=
40
;
let
RADIUS_MIN
=
1
;
let
RADIUS_MIN
=
1
;
let
RADIUS_MAX
=
4
;
let
RADIUS_MAX
=
4
;
...
@@ -33,7 +35,9 @@ class Dot {
...
@@ -33,7 +35,9 @@ class Dot {
this
.
_y
=
y
;
this
.
_y
=
y
;
this
.
_radius
=
radius
;
this
.
_radius
=
radius
;
this
.
_vx
=
vx
;
this
.
_vx
=
vx
;
this
.
_initial_vx
=
vx
;
this
.
_vy
=
vy
;
this
.
_vy
=
vy
;
this
.
_initial_vy
=
vy
;
}
}
get
x
()
{
get
x
()
{
...
@@ -60,12 +64,18 @@ class Dot {
...
@@ -60,12 +64,18 @@ class Dot {
set
vx
(
value
)
{
set
vx
(
value
)
{
this
.
_vx
=
value
;
this
.
_vx
=
value
;
}
}
get
initial_vx
()
{
return
this
.
_initial_vx
}
get
vy
()
{
get
vy
()
{
return
this
.
_vy
;
return
this
.
_vy
;
}
}
set
vy
(
value
)
{
set
vy
(
value
)
{
this
.
_vy
=
value
;
this
.
_vy
=
value
;
}
}
get
initial_vy
()
{
return
this
.
_initial_vy
;
}
}
}
const
randInt
=
(
min
,
max
)
=>
{
const
randInt
=
(
min
,
max
)
=>
{
...
@@ -100,6 +110,7 @@ const setDisplayParameters = () => {
...
@@ -100,6 +110,7 @@ const setDisplayParameters = () => {
// Set properties
// Set properties
DOTS_NUM
=
DOTS_NUM_VALUES
[
index
];
DOTS_NUM
=
DOTS_NUM_VALUES
[
index
];
INITIAL_VELOCITY_MAX
=
INITIAL_VELOCITY_MAX_VALUES
[
index
];
VELOCITY_MAX
=
VELOCITY_MAX_VALUES
[
index
];
VELOCITY_MAX
=
VELOCITY_MAX_VALUES
[
index
];
RADIUS_MIN
=
RADIUS_MIN_VALUES
[
index
];
RADIUS_MIN
=
RADIUS_MIN_VALUES
[
index
];
RADIUS_MAX
=
RADIUS_MAX_VALUES
[
index
];
RADIUS_MAX
=
RADIUS_MAX_VALUES
[
index
];
...
@@ -119,8 +130,8 @@ for (let i = 0; i < DOTS_NUM; i++) {
...
@@ -119,8 +130,8 @@ for (let i = 0; i < DOTS_NUM; i++) {
Math
.
random
()
*
canvas
.
width
,
// position x
Math
.
random
()
*
canvas
.
width
,
// position x
Math
.
random
()
*
canvas
.
height
,
// position y
Math
.
random
()
*
canvas
.
height
,
// position y
randInt
(
RADIUS_MIN
,
RADIUS_MAX
),
// radius
randInt
(
RADIUS_MIN
,
RADIUS_MAX
),
// radius
randInt
(
-
VELOCITY_MAX
,
VELOCITY_MAX
),
// velocity x
randInt
(
-
INITIAL_
VELOCITY_MAX
,
INITIAL_
VELOCITY_MAX
),
// velocity x
randInt
(
-
VELOCITY_MAX
,
VELOCITY_MAX
)
// velocity y
randInt
(
-
INITIAL_
VELOCITY_MAX
,
INITIAL_
VELOCITY_MAX
)
// velocity y
));
));
}
}
...
@@ -196,6 +207,18 @@ const physics = () => {
...
@@ -196,6 +207,18 @@ const physics = () => {
dot
.
x
+=
dot
.
vx
/
FPS
;
dot
.
x
+=
dot
.
vx
/
FPS
;
dot
.
y
+=
dot
.
vy
/
FPS
;
dot
.
y
+=
dot
.
vy
/
FPS
;
// Clamp velocities to maximum
dot
.
vx
=
clamp
(
dot
.
vx
,
-
VELOCITY_MAX
,
VELOCITY_MAX
);
dot
.
vy
=
clamp
(
dot
.
vy
,
-
VELOCITY_MAX
,
VELOCITY_MAX
);
// Stop velocity from going below initial velocity
if
(
dot
.
vx
<
dot
.
initial_vx
)
{
dot
.
vx
=
dot
.
initial_vx
;
}
if
(
dot
.
vy
<
dot
.
initial_vy
)
{
dot
.
vy
=
dot
.
initial_vy
;
}
// Invert velocities if off-screen and not already inverted
// Invert velocities if off-screen and not already inverted
if
((
dot
.
x
<
0
&&
dot
.
vx
<
0
)
||
(
dot
.
x
>
canvas
.
width
&&
dot
.
vx
>
0
))
{
if
((
dot
.
x
<
0
&&
dot
.
vx
<
0
)
||
(
dot
.
x
>
canvas
.
width
&&
dot
.
vx
>
0
))
{
dot
.
vx
=
-
dot
.
vx
;
dot
.
vx
=
-
dot
.
vx
;
...
...
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
sign in
to comment