Skip to content

Commit

Permalink
tested examples and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
d-roak committed Sep 18, 2024
1 parent 6efcdd3 commit ab4261e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/canvas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function paint_pixel(pixel: HTMLDivElement) {
random_int(256),
random_int(256),
];
canvasCRO.paint(node.networkNode.peerId, [x, y], painting);
canvasCRO.paint([x, y], painting);
const [r, g, b] = canvasCRO.pixel(x, y).color();
pixel.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
}
Expand Down
17 changes: 5 additions & 12 deletions examples/canvas/src/objects/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,18 @@ export class Canvas implements CRO {
}

splash(
nodeId: string,
offset: [number, number],
size: [number, number],
rgb: [number, number, number],
): void {
this._splash(nodeId, offset, size, rgb);
this._splash(offset, size, rgb);
}

paint(
nodeId: string,
offset: [number, number],
rgb: [number, number, number],
): void {
this._paint(nodeId, offset, rgb);
paint(offset: [number, number], rgb: [number, number, number]): void {
this._paint(offset, rgb);
}

private _splash(
nodeId: string,
offset: [number, number],
size: [number, number],
rgb: [number, number, number],
Expand All @@ -51,20 +45,19 @@ export class Canvas implements CRO {

for (let x = offset[0]; x < this.width || x < offset[0] + size[0]; x++) {
for (let y = offset[1]; y < this.height || y < offset[1] + size[1]; y++) {
this.canvas[x][y].paint(nodeId, rgb);
this.canvas[x][y].paint(rgb);
}
}
}

private _paint(
nodeId: string,
offset: [number, number],
rgb: [number, number, number],
): void {
if (offset[0] < 0 || this.canvas.length < offset[0]) return;
if (offset[1] < 0 || this.canvas[offset[0]].length < offset[1]) return;

this.canvas[offset[0]][offset[1]].paint(nodeId, rgb);
this.canvas[offset[0]][offset[1]].paint(rgb);
}

pixel(x: number, y: number): Pixel {
Expand Down
4 changes: 2 additions & 2 deletions examples/chat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const render = () => {
const element_chat = <HTMLDivElement>document.getElementById("chat");
element_chat.innerHTML = "";

if (chat.set.size === 0) {
if (chat.size === 0) {
const div = document.createElement("div");
div.innerHTML = "No messages yet";
div.style.padding = "10px";
element_chat.appendChild(div);
return;
}
for (const message of [...chat.set].sort()) {
for (const message of [...chat].sort()) {
const div = document.createElement("div");
div.innerHTML = message;
div.style.padding = "10px";
Expand Down

0 comments on commit ab4261e

Please sign in to comment.