Platform
Resources
Pricing
Sign in
Get started
Tom Larkworthy
Tech Lead at Taktile. Formerly Firebase, Google
Workspace
Fork
Public
By
Tom Larkworthy
Edited
Nov 3, 2023
1 star
Insert cell
Insert cell
pixi
=
import
(
"https://cdn.skypack.dev/pixi.js@6.2.0"
)
Insert cell
app
=
new
pixi
.
Application
(
{
width
:
800
,
height
:
600
}
)
Insert cell
spaceshipSVG
=
{
const
svgData
=
`<svg width="40" height="60" xmlns="http://www.w3.org/2000/svg"> <polygon points="20,5 40,55 20,45 0,55" fill="lime" /> <circle cx="20" cy="30" r="15" fill="blue" /> </svg>`
;
return
`data:image/svg+xml,${
encodeURIComponent
(
svgData
)
}`
;
}
Insert cell
spaceshipTexture
=
{
return
pixi
.
Texture
.
from
(
spaceshipSVG
)
;
}
Insert cell
spaceship
=
{
const
sprite
=
new
pixi
.
Sprite
(
spaceshipTexture
)
;
sprite
.
x
=
400
;
sprite
.
y
=
300
;
app
.
stage
.
addChild
(
sprite
)
;
return
sprite
;
}
Insert cell
keyState
=
{
const
state
=
{
}
;
document
.
addEventListener
(
"keydown"
,
function
(
event
)
{
state
[
event
.
code
]
=
true
;
}
)
;
document
.
addEventListener
(
"keyup"
,
function
(
event
)
{
state
[
event
.
code
]
=
false
;
}
)
;
return
state
;
}
Insert cell
moveSpaceship
=
{
app
.
ticker
.
add
(
(
)
=>
{
if
(
keyState
[
"ArrowUp"
]
)
spaceship
.
y
-=
5
;
if
(
keyState
[
"ArrowDown"
]
)
spaceship
.
y
+=
5
;
if
(
keyState
[
"ArrowLeft"
]
)
spaceship
.
x
-=
5
;
if
(
keyState
[
"ArrowRight"
]
)
spaceship
.
x
+=
5
;
}
)
;
}
Insert cell
pixiSprite
=
import
(
"https://cdn.skypack.dev/@pixi/sprite"
)
Insert cell
canvasContainer
=
{
const
container
=
document
.
createElement
(
"div"
)
;
app
.
view
.
style
.
border
=
"1px solid black"
;
container
.
appendChild
(
app
.
view
)
;
return
container
;
}
Insert cell
canvasContainer
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
pixi
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
app
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
spaceshipSVG
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
spaceshipTexture
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
spaceship
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
keyState
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
moveSpaceship
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
pixiSprite
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
canvasContainer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML