Skip to content

Commit

Permalink
Update Canvas.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Oct 28, 2024
1 parent 15ee302 commit f1fafb4
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions featured/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
getInfo() {
return {
id: 'MistiumCanvas',
name: "Mist's Canvases",
name: "Canvas",
color1: '#4A893D',
blocks: [
{
Expand Down Expand Up @@ -48,7 +48,30 @@
COLOUR: {
type: Scratch.ArgumentType.COLOR,
defaultValue: '#000000'
}
},
}
},
{
opcode: 'createInvisCanvas',
blockType: Scratch.BlockType.COMMAND,
text: 'create invisible canvas [CANVAS_ID] width: [WIDTH] height: [HEIGHT] background colour: [COLOUR]',
arguments: {
CANVAS_ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'canvas1'
},
WIDTH: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 100
},
HEIGHT: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 100
},
COLOUR: {
type: Scratch.ArgumentType.COLOR,
defaultValue: '#000000'
},
}
},
{
Expand Down Expand Up @@ -499,6 +522,32 @@
this.canvases[CANVAS_ID] = canvas;
}

createInvisCanvas({ CANVAS_ID, WIDTH, HEIGHT, COLOUR }) {
CANVAS_ID = cast.toString(CANVAS_ID);
X = cast.toNumber(X);
Y = cast.toNumber(Y);
WIDTH = cast.toNumber(WIDTH);
HEIGHT = cast.toNumber(HEIGHT);
COLOUR = cast.toString(COLOUR);

if (this.canvases[CANVAS_ID]) {
this.canvases[CANVAS_ID].remove();
delete this.canvases[CANVAS_ID];
}
const canvas = document.createElement('canvas');
canvas.id = CANVAS_ID;
canvas.style.position = 'absolute';
canvas.style.display = 'none'
canvas.x = 0;
canvas.y = 0;
canvas.style.left = '0px';
canvas.style.top = '0px';
canvas.style.backgroundColor = COLOUR;
canvas.width = WIDTH;
canvas.height = HEIGHT;
this.canvases[CANVAS_ID] = canvas;
}

deleteCanvas({ CANVAS_ID }) {
CANVAS_ID = cast.toString(CANVAS_ID);
const canvas = this.canvases[CANVAS_ID];
Expand Down

0 comments on commit f1fafb4

Please sign in to comment.