-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
203 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as Pixii from 'pixi.js'; | ||
import { Canvas } from '../../../canvas'; | ||
|
||
const NSCAdapter: Pixii.Adapter = { | ||
createCanvas(width?: number, height?: number) { | ||
const canvas = new Canvas(); | ||
canvas.width = width; | ||
canvas.height = height; | ||
return canvas as never; | ||
}, | ||
getCanvasRenderingContext2D() { | ||
return CanvasRenderingContext2D as never; | ||
}, | ||
getWebGLRenderingContext() { | ||
return WebGLRenderingContext as never; | ||
}, | ||
getNavigator() { | ||
return { | ||
userAgent: '', | ||
gpu: global.navigator.gpu, | ||
}; | ||
}, | ||
getBaseUrl() { | ||
return import.meta.url; | ||
}, | ||
getFontFaceSet() { | ||
return null; //document.fonts; | ||
}, | ||
fetch(url: RequestInfo, options?: RequestInit) { | ||
return fetch(url, options); | ||
}, | ||
parseXML(xml: string) { | ||
const parser = new DOMParser(); | ||
return parser.parseFromString(xml, 'text/xml'); | ||
}, | ||
}; | ||
|
||
Pixii.DOMAdapter.set(NSCAdapter); | ||
|
||
Pixii.Assets.setPreferences({ preferWorkers: false }); | ||
|
||
(global as any).PIXI = (global as any).window.PIXI = (global as any).PIXI || Pixii; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import './adapter'; | ||
import type { Application } from 'pixi.js'; | ||
import * as PIXI from 'pixi.js'; | ||
|
||
export async function run(canvas) { | ||
const app = new PIXI.Application() as Application; | ||
canvas.width = canvas.clientWidth * window.devicePixelRatio; | ||
canvas.height = canvas.clientHeight * window.devicePixelRatio; | ||
|
||
try { | ||
await app.init(); | ||
console.log('done'); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
/* | ||
console.log(app); | ||
// grab context to present | ||
// const ctx = canvas.getContext('webgpu'); | ||
app.ticker.add((delta) => { | ||
//if (ctx) { | ||
// ctx.presentSurface(); | ||
//} | ||
}); | ||
const graphics = new PIXI.Graphics(); | ||
// Rectangle | ||
graphics.rect(50, 50, 100, 100); | ||
graphics.fill(0xde3249); | ||
// Rectangle + line style 1 | ||
graphics.rect(200, 50, 100, 100); | ||
graphics.fill(0x650a5a); | ||
graphics.stroke({ width: 2, color: 0xfeeb77 }); | ||
// Rectangle + line style 2 | ||
graphics.rect(350, 50, 100, 100); | ||
graphics.fill(0xc34288); | ||
graphics.stroke({ width: 10, color: 0xffbd01 }); | ||
// Rectangle 2 | ||
graphics.rect(530, 50, 140, 100); | ||
graphics.fill(0xaa4f08); | ||
graphics.stroke({ width: 2, color: 0xffffff }); | ||
// Circle | ||
graphics.circle(100, 250, 50); | ||
graphics.fill(0xde3249, 1); | ||
// Circle + line style 1 | ||
graphics.circle(250, 250, 50); | ||
graphics.fill(0x650a5a, 1); | ||
graphics.stroke({ width: 2, color: 0xfeeb77 }); | ||
// Circle + line style 2 | ||
graphics.circle(400, 250, 50); | ||
graphics.fill(0xc34288, 1); | ||
graphics.stroke({ width: 10, color: 0xffbd01 }); | ||
// Ellipse + line style 2 | ||
graphics.ellipse(600, 250, 80, 50); | ||
graphics.fill(0xaa4f08, 1); | ||
graphics.stroke({ width: 2, color: 0xffffff }); | ||
// Draw a shape | ||
graphics.moveTo(50, 350); | ||
graphics.lineTo(250, 350); | ||
graphics.lineTo(100, 400); | ||
graphics.lineTo(50, 350); | ||
graphics.fill(0xff3300); | ||
graphics.stroke({ width: 4, color: 0xffd900 }); | ||
// Draw a rounded rectangle | ||
graphics.roundRect(50, 440, 100, 100, 16); | ||
graphics.fill({ | ||
color: 0x650a5a, | ||
alpha: 0.25 | ||
}); | ||
graphics.stroke({ width: 2, color: 0xff00ff }); | ||
// Draw star | ||
graphics.star(360, 370, 5, 50); | ||
graphics.fill(0x35cc5a); | ||
graphics.stroke({ width: 2, color: 0xffffff }); | ||
// Draw star 2 | ||
graphics.star(280, 510, 7, 50); | ||
graphics.fill(0xffcc5a); | ||
graphics.stroke({ width: 2, color: 0xfffffd }); | ||
// Draw star 3 | ||
graphics.star(470, 450, 4, 50); | ||
graphics.fill(0x55335a); | ||
graphics.stroke({ width: 4, color: 0xffffff }); | ||
// Draw polygon | ||
const path = [600, 370, 700, 460, 780, 420, 730, 570, 590, 520]; | ||
graphics.poly(path); | ||
graphics.fill(0x3500fa); | ||
app.stage.addChild(graphics); | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters