Skip to content

Commit

Permalink
Implementar função desenhar_linha
Browse files Browse the repository at this point in the history
  • Loading branch information
dngadelha committed Jan 6, 2025
1 parent e791ce5 commit 2cdbe0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/runtime/src/graphics/PortugolGraphicsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,25 @@ class PortugolGraphicsContext {
}
});
}
drawLine(x1, y1, x2, y2) {
this.drawCall(() => {
if (this.canvasContext) {
this.applyWorkParams(false, {
x: Math.min(x1, x2),
y: Math.min(y1, y2),
width: Math.abs(x2 - x1),
height: Math.abs(y2 - y1),
});
this.canvasContext.beginPath();
this.canvasContext.moveTo(x1, y1);
this.canvasContext.lineTo(x2, y2);
this.canvasContext.closePath();
this.canvasContext.stroke();
}
});
}
}
//endregion
`;
11 changes: 11 additions & 0 deletions packages/runtime/src/libs/Graficos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ export default /* javascript */ `{
self.graphics.drawText(x.getValue(), y.getValue(), texto.getValue());
},
desenhar_linha(x1, y1, x2, y2) {
self.runtime.expectType("desenhar_linha", "x1", x1, "inteiro", "real");
self.runtime.expectType("desenhar_linha", "y1", y1, "inteiro", "real");
self.runtime.expectType("desenhar_linha", "x2", x2, "inteiro", "real");
self.runtime.expectType("desenhar_linha", "y2", y2, "inteiro", "real");
self.runtime.assertGraphicsContext();
self.graphics.drawLine(x1.getValue(), y1.getValue(), x2.getValue(), y2.getValue());
},
altura_imagem(endereco) {
self.runtime.expectType("altura_imagem", "endereco", endereco, "inteiro");
self.runtime.unimplementedMethod("altura_imagem", "Graficos");
Expand Down

0 comments on commit 2cdbe0d

Please sign in to comment.