Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
chip-ahoyto
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
chip-ahoyto
Commits
fc61472e
Verified
Commit
fc61472e
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: support for image drawing on clear canvas
parent
9650bad8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#769
passed
2 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/web/index.ts
+26
-29
26 additions, 29 deletions
examples/web/index.ts
with
26 additions
and
29 deletions
examples/web/index.ts
+
26
−
29
View file @
fc61472e
...
...
@@ -178,7 +178,7 @@ const main = async () => {
// system and the machine state (to be able to recover)
// also sets the default color on screen to indicate the issue
if
(
isPanic
)
{
clearCanvas
(
undefined
,
{
await
clearCanvas
(
undefined
,
{
// @ts-ignore: ts(2580)
image
:
require
(
"
./res/storm.png
"
),
imageScale
:
0.4
...
...
@@ -682,7 +682,7 @@ const updateCanvas = (pixels: Uint8Array) => {
state
.
canvasScaledCtx
.
drawImage
(
state
.
canvas
,
0
,
0
);
};
const
clearCanvas
=
(
const
clearCanvas
=
async
(
color
=
PIXEL_UNSET_COLOR
,
{
image
=
null
as
string
,
imageScale
=
1
}
=
{}
)
=>
{
...
...
@@ -697,33 +697,30 @@ const clearCanvas = (
// in case an image was requested then uses that to load
// an image at the center of the screen
if
(
image
)
{
const
img
=
new
Image
();
img
.
onload
=
()
=>
{
const
[
imgWidth
,
imgHeight
]
=
[
img
.
width
*
imageScale
,
img
.
height
*
imageScale
];
const
[
x0
,
y0
]
=
[
state
.
canvasScaled
.
width
/
2
-
imgWidth
/
2
,
state
.
canvasScaled
.
height
/
2
-
imgHeight
/
2
];
state
.
canvasScaledCtx
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
);
try
{
state
.
canvasScaledCtx
.
drawImage
(
img
,
x0
,
y0
,
imgWidth
,
imgHeight
);
}
finally
{
state
.
canvasScaledCtx
.
scale
(
state
.
canvasScaled
.
width
/
state
.
canvas
.
width
,
state
.
canvasScaled
.
height
/
state
.
canvas
.
height
);
}
};
img
.
src
=
image
;
const
img
=
await
new
Promise
<
HTMLImageElement
>
((
resolve
)
=>
{
const
img
=
new
Image
();
img
.
onload
=
()
=>
{
resolve
(
img
);
};
img
.
src
=
image
;
});
const
[
imgWidth
,
imgHeight
]
=
[
img
.
width
*
imageScale
,
img
.
height
*
imageScale
];
const
[
x0
,
y0
]
=
[
state
.
canvasScaled
.
width
/
2
-
imgWidth
/
2
,
state
.
canvasScaled
.
height
/
2
-
imgHeight
/
2
];
state
.
canvasScaledCtx
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
);
try
{
state
.
canvasScaledCtx
.
drawImage
(
img
,
x0
,
y0
,
imgWidth
,
imgHeight
);
}
finally
{
state
.
canvasScaledCtx
.
scale
(
state
.
canvasScaled
.
width
/
state
.
canvas
.
width
,
state
.
canvasScaled
.
height
/
state
.
canvas
.
height
);
}
}
};
...
...
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