Public
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more