Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bardicarchive
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Raphael Storm Larsen
bardicarchive
Commits
ee6cd14a
Commit
ee6cd14a
authored
2 years ago
by
Sara Stentvedt Luggenes
Browse files
Options
Downloads
Patches
Plain Diff
fix: better math
parent
b1107580
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
frontend/script.js
+54
-43
54 additions, 43 deletions
frontend/script.js
with
54 additions
and
43 deletions
frontend/script.js
+
54
−
43
View file @
ee6cd14a
let
statsParagraph
=
document
.
getElementById
(
'
stats
'
);
let
statsParagraph
=
document
.
getElementById
(
'
stats
'
);
let
clickParagraph
=
document
.
getElementById
(
'
clickangle
'
);
let
clickParagraph
=
document
.
getElementById
(
'
clickangle
'
);
let
rotation
=
0
;
let
targetAngle
=
0
;
let
isSpinning
=
false
;
let
wheelCanvas
;
function
setup
()
{
wheelCanvas
=
createCanvas
(
800
,
800
);
wheelCanvas
.
parent
(
'
container
'
);
wheelCanvas
.
mousePressed
(
spinWheel
);
angleMode
(
RADIANS
);
}
function
draw
()
{
background
(
255
);
translate
(
width
/
2
,
height
/
2
);
//translate targetangle to rotation value
//check if rotation = targetrotation
//if: stop spin
//else: continue spin
rotate
(
rotation
);
if
(
round
(
rotation
%
TWO_PI
,
2
)
==
round
(
targetAngle
,
2
)){
stopSpinning
();
}
else
{
rotation
+=
isSpinning
?
0.01
:
0
;
stats
.
innerHTML
=
"
rotation:
"
+
int
(
rotation
)
+
"
rotation%:
"
+
(
rotation
%
TWO_PI
);
}
drawWheel
();
}
function
drawWheel
()
{
const
colors
=
[
const
colors
=
[
"
#FFF56D
"
,
// Curious
"
#FFF56D
"
,
// Curious
"
#FFEE00
"
,
// Adventurous
"
#FFEE00
"
,
// Adventurous
...
@@ -81,6 +43,45 @@ function drawWheel() {
...
@@ -81,6 +43,45 @@ function drawWheel() {
"
Silly
"
"
Silly
"
];
];
let
rotation
=
0
;
let
targetAngle
=
0
;
let
isSpinning
=
false
;
let
wheelCanvas
;
function
setup
()
{
wheelCanvas
=
createCanvas
(
800
,
800
);
wheelCanvas
.
parent
(
'
container
'
);
wheelCanvas
.
mousePressed
(
spinWheel
);
angleMode
(
RADIANS
);
}
function
draw
()
{
background
(
255
);
translate
(
width
/
2
,
height
/
2
);
//translate targetangle to rotation value
//check if rotation = targetrotation
//if: stop spin
//else: continue spin
rotate
(
rotation
);
if
(
round
(
rotation
%
TWO_PI
,
2
)
==
round
(
targetAngle
,
2
)){
stopSpinning
();
}
else
{
rotation
+=
isSpinning
?
0.01
:
0
;
stats
.
innerHTML
=
"
rotation:
"
+
int
(
rotation
)
+
"
rotation%:
"
+
(
rotation
%
TWO_PI
);
}
drawWheel
();
}
function
drawWheel
()
{
const
numSegments
=
colors
.
length
;
const
numSegments
=
colors
.
length
;
const
angleIncrement
=
TWO_PI
/
numSegments
;
const
angleIncrement
=
TWO_PI
/
numSegments
;
...
@@ -120,7 +121,17 @@ function spinWheel(event) {
...
@@ -120,7 +121,17 @@ function spinWheel(event) {
targetAngle
=
PI
+
(
PI
-
clickAngle
)
targetAngle
=
PI
+
(
PI
-
clickAngle
)
}
}
targetAngle
=
targetAngle
+
(
rotation
%
TWO_PI
);
//apply offset for previous rotations
//targetAngle = (targetAngle % TWO_PI) + (rotation % TWO_PI); //apply offset for previous rotations
let
sectorIncrement
=
TWO_PI
/
colors
.
length
;
for
(
let
i
=
0
;
i
<
colors
.
length
;
i
++
){
if
(
targetAngle
>=
sectorIncrement
*
i
&&
targetAngle
<
sectorIncrement
*
(
i
+
1
)){
//angle is within sector
console
.
log
(
"
target:
"
+
targetAngle
+
"
lower value:
"
+
sectorIncrement
*
i
+
"
higher value:
"
+
sectorIncrement
*
(
i
+
1
));
targetAngle
=
(
sectorIncrement
*
i
)
+
sectorIncrement
/
2
;
}
}
clickParagraph
.
innerHTML
=
"
targetangle:
"
+
targetAngle
;
clickParagraph
.
innerHTML
=
"
targetangle:
"
+
targetAngle
;
...
...
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