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
fa39a373
Verified
Commit
fa39a373
authored
11 months ago
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Implement velocity changing
parent
54455094
Branches
Branches containing commit
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
+12
-0
12 additions, 0 deletions
static/js/background_anim.js
with
12 additions
and
0 deletions
static/js/background_anim.js
+
12
−
0
View file @
fa39a373
...
...
@@ -14,6 +14,9 @@ const DOT_FILL_COLOUR = "#666";
const
DOT_OUTLINE_COLOUR
=
"
#444
"
;
const
LINE_COLOUR
=
"
#777
"
;
const
VELOCITY_SLOWDOWN_MULTIPLIER
=
0.998
;
const
VELOCITY_PUSH_MULTIPLIER
=
1.8
;
// ----
// Sort-of constants (change with window size)
...
...
@@ -211,6 +214,10 @@ const physics = () => {
dot
.
vx
=
clamp
(
dot
.
vx
,
-
VELOCITY_MAX
,
VELOCITY_MAX
);
dot
.
vy
=
clamp
(
dot
.
vy
,
-
VELOCITY_MAX
,
VELOCITY_MAX
);
// Slow down velocity
dot
.
vx
*=
VELOCITY_SLOWDOWN_MULTIPLIER
;
dot
.
xy
*=
VELOCITY_SLOWDOWN_MULTIPLIER
;
// Stop velocity from going below initial velocity
if
(
dot
.
vx
<
dot
.
initial_vx
)
{
dot
.
vx
=
dot
.
initial_vx
;
...
...
@@ -222,9 +229,11 @@ const physics = () => {
// Invert velocities if off-screen and not already inverted
if
((
dot
.
x
<
0
&&
dot
.
vx
<
0
)
||
(
dot
.
x
>
canvas
.
width
&&
dot
.
vx
>
0
))
{
dot
.
vx
=
-
dot
.
vx
;
dot
.
vx
*=
VELOCITY_PUSH_MULTIPLIER
;
}
if
((
dot
.
y
<
0
&&
dot
.
vy
<
0
)
||
(
dot
.
y
>
canvas
.
height
&&
dot
.
vy
>
0
))
{
dot
.
vy
=
-
dot
.
vy
;
dot
.
vy
*=
VELOCITY_PUSH_MULTIPLIER
;
}
// Make dots velocities react to mouse movement (deflected by mouse)
...
...
@@ -241,6 +250,9 @@ const physics = () => {
dot
.
vx
=
-
dot
.
vx
;
dot
.
vy
=
-
dot
.
vy
;
dot
.
vx
*=
VELOCITY_PUSH_MULTIPLIER
;
dot
.
vy
*=
VELOCITY_PUSH_MULTIPLIER
;
dot
.
x
=
cx
;
dot
.
y
=
cy
;
}
...
...
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