|
| 1 | +import './adapter'; |
| 2 | +import type { Application } from 'pixi.js'; |
| 3 | +import * as PIXI from 'pixi.js'; |
| 4 | + |
| 5 | +export async function run(canvas) { |
| 6 | + const app = new PIXI.Application() as Application; |
| 7 | + canvas.width = canvas.clientWidth * window.devicePixelRatio; |
| 8 | + canvas.height = canvas.clientHeight * window.devicePixelRatio; |
| 9 | + |
| 10 | + try { |
| 11 | + await app.init(); |
| 12 | + console.log('done'); |
| 13 | + } catch (e) { |
| 14 | + console.log(e); |
| 15 | + } |
| 16 | + /* |
| 17 | + console.log(app); |
| 18 | +
|
| 19 | + // grab context to present |
| 20 | +// const ctx = canvas.getContext('webgpu'); |
| 21 | +
|
| 22 | + app.ticker.add((delta) => { |
| 23 | + //if (ctx) { |
| 24 | + // ctx.presentSurface(); |
| 25 | + //} |
| 26 | + }); |
| 27 | +
|
| 28 | + const graphics = new PIXI.Graphics(); |
| 29 | +
|
| 30 | + // Rectangle |
| 31 | + graphics.rect(50, 50, 100, 100); |
| 32 | + graphics.fill(0xde3249); |
| 33 | +
|
| 34 | + // Rectangle + line style 1 |
| 35 | + graphics.rect(200, 50, 100, 100); |
| 36 | + graphics.fill(0x650a5a); |
| 37 | + graphics.stroke({ width: 2, color: 0xfeeb77 }); |
| 38 | +
|
| 39 | + // Rectangle + line style 2 |
| 40 | + graphics.rect(350, 50, 100, 100); |
| 41 | + graphics.fill(0xc34288); |
| 42 | + graphics.stroke({ width: 10, color: 0xffbd01 }); |
| 43 | +
|
| 44 | + // Rectangle 2 |
| 45 | + graphics.rect(530, 50, 140, 100); |
| 46 | + graphics.fill(0xaa4f08); |
| 47 | + graphics.stroke({ width: 2, color: 0xffffff }); |
| 48 | +
|
| 49 | + // Circle |
| 50 | + graphics.circle(100, 250, 50); |
| 51 | + graphics.fill(0xde3249, 1); |
| 52 | +
|
| 53 | + // Circle + line style 1 |
| 54 | + graphics.circle(250, 250, 50); |
| 55 | + graphics.fill(0x650a5a, 1); |
| 56 | + graphics.stroke({ width: 2, color: 0xfeeb77 }); |
| 57 | +
|
| 58 | + // Circle + line style 2 |
| 59 | + graphics.circle(400, 250, 50); |
| 60 | + graphics.fill(0xc34288, 1); |
| 61 | + graphics.stroke({ width: 10, color: 0xffbd01 }); |
| 62 | +
|
| 63 | + // Ellipse + line style 2 |
| 64 | + graphics.ellipse(600, 250, 80, 50); |
| 65 | + graphics.fill(0xaa4f08, 1); |
| 66 | + graphics.stroke({ width: 2, color: 0xffffff }); |
| 67 | +
|
| 68 | + // Draw a shape |
| 69 | + graphics.moveTo(50, 350); |
| 70 | + graphics.lineTo(250, 350); |
| 71 | + graphics.lineTo(100, 400); |
| 72 | + graphics.lineTo(50, 350); |
| 73 | + graphics.fill(0xff3300); |
| 74 | + graphics.stroke({ width: 4, color: 0xffd900 }); |
| 75 | +
|
| 76 | + // Draw a rounded rectangle |
| 77 | + graphics.roundRect(50, 440, 100, 100, 16); |
| 78 | + graphics.fill({ |
| 79 | + color: 0x650a5a, |
| 80 | + alpha: 0.25 |
| 81 | + }); |
| 82 | + graphics.stroke({ width: 2, color: 0xff00ff }); |
| 83 | +
|
| 84 | + // Draw star |
| 85 | + graphics.star(360, 370, 5, 50); |
| 86 | + graphics.fill(0x35cc5a); |
| 87 | + graphics.stroke({ width: 2, color: 0xffffff }); |
| 88 | +
|
| 89 | + // Draw star 2 |
| 90 | + graphics.star(280, 510, 7, 50); |
| 91 | + graphics.fill(0xffcc5a); |
| 92 | + graphics.stroke({ width: 2, color: 0xfffffd }); |
| 93 | +
|
| 94 | + // Draw star 3 |
| 95 | + graphics.star(470, 450, 4, 50); |
| 96 | + graphics.fill(0x55335a); |
| 97 | + graphics.stroke({ width: 4, color: 0xffffff }); |
| 98 | +
|
| 99 | + // Draw polygon |
| 100 | + const path = [600, 370, 700, 460, 780, 420, 730, 570, 590, 520]; |
| 101 | +
|
| 102 | + graphics.poly(path); |
| 103 | + graphics.fill(0x3500fa); |
| 104 | +
|
| 105 | + app.stage.addChild(graphics); |
| 106 | + */ |
| 107 | +} |
0 commit comments