-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
67 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
export function TestImage2OnCanvas2D({entity}) { | ||
export function TestImage2OnCanvas2D() { | ||
const [r, g, b] = [Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255)]; | ||
const fillStyle0 = `rgb(${r} ${g} ${b})`; | ||
const fillStyle1 = `rgb(${255 - r} ${255 - g} ${255 - b})`; | ||
|
||
let ctx = null; | ||
let canvas; | ||
let ctx; | ||
|
||
entity.on('onRenderFrame', ({canvas}) => { | ||
ctx ??= canvas.getContext('2d'); | ||
return { | ||
onRenderFrame(params) { | ||
canvas ??= params.canvas; | ||
ctx ??= canvas.getContext('2d'); | ||
|
||
const [w, h] = [canvas.width, canvas.height]; | ||
const halfH = Math.floor(h / 2); | ||
const halfW = Math.floor(w / 2); | ||
const [w, h] = [canvas.width, canvas.height]; | ||
const halfH = Math.floor(h / 2); | ||
const halfW = Math.floor(w / 2); | ||
|
||
ctx.clearRect(0, 0, w, h); | ||
ctx.clearRect(0, 0, w, h); | ||
|
||
ctx.fillStyle = fillStyle0; | ||
ctx.fillRect(0, 0, halfW, halfH); | ||
ctx.fillStyle = fillStyle0; | ||
ctx.fillRect(0, 0, halfW, halfH); | ||
|
||
ctx.fillStyle = fillStyle1; | ||
ctx.fillRect(0, halfH, halfW, h - halfH); | ||
}); | ||
ctx.fillStyle = fillStyle1; | ||
ctx.fillRect(0, halfH, halfW, h - halfH); | ||
}, | ||
|
||
onDestroy() { | ||
if (canvas && ctx) { | ||
ctx.fillStyle = 'red'; | ||
const halfW = Math.floor(canvas.width / 2); | ||
ctx.fillRect(0, 0, halfW, canvas.height); | ||
} | ||
}, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,26 +1,36 @@ | ||
export function TestImageOnCanvas2D({entity, useContext}) { | ||
export function TestImageOnCanvas2D({entity, useContext, onDestroy}) { | ||
const [r, g, b] = [Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255)]; | ||
const fillStyle0 = `rgb(${r} ${g} ${b})`; | ||
const fillStyle1 = `rgb(${255 - r} ${255 - g} ${255 - b})`; | ||
|
||
let ctx = null; | ||
|
||
let consoleCount = 0; | ||
|
||
useContext('canvasSize')((size) => { | ||
console.debug(`[TestImageOnCanvas2D] ${entity.uuid} canvas size changed to`, size); | ||
if (consoleCount++ < 3) { | ||
console.debug(`[TestImageOnCanvas2D] ${entity.uuid} canvas size changed to`, size); | ||
} | ||
}); | ||
|
||
entity.on('onRenderFrame', ({canvas}) => { | ||
ctx ??= canvas.getContext('2d'); | ||
console.log(`[TestImageOnCanvas2D] ${entity.uuid} Ready.`); | ||
|
||
onDestroy(() => { | ||
console.log(`[TestImageOnCanvas2D] ${entity.uuid} Thank you for the fish.`); | ||
}); | ||
|
||
const [w, h] = [canvas.width, canvas.height]; | ||
const halfH = Math.floor(h / 2); | ||
return { | ||
onRenderFrame({canvas}) { | ||
ctx ??= canvas.getContext('2d'); | ||
|
||
ctx.fillStyle = fillStyle0; | ||
ctx.fillRect(0, 0, w, halfH); | ||
const [w, h] = [canvas.width, canvas.height]; | ||
const halfH = Math.floor(h / 2); | ||
|
||
ctx.fillStyle = fillStyle1; | ||
ctx.fillRect(0, halfH, w, h - halfH); | ||
}); | ||
ctx.fillStyle = fillStyle0; | ||
ctx.fillRect(0, 0, w, halfH); | ||
|
||
console.debug(`[TestImageOnCanvas2D] ${entity.uuid} ready`); | ||
ctx.fillStyle = fillStyle1; | ||
ctx.fillRect(0, halfH, w, h - halfH); | ||
}, | ||
}; | ||
} |
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