basic parser to renderer pipeline
This commit is contained in:
parent
ab353dc594
commit
a502abf051
|
@ -1,9 +1,10 @@
|
||||||
point(0.2378, -34.389) -> A
|
point(200, 300) -> A
|
||||||
point(2.5, 0) -> B
|
point(400, 300) -> B
|
||||||
[point(-1, 3) -> C]
|
[point(300, 128) -> C]
|
||||||
|
|
||||||
line(A, B) -> AB
|
line(A, B) -> AB
|
||||||
line(B, C)
|
line(B, C)
|
||||||
line(C, A)
|
line(C, A)
|
||||||
|
|
||||||
circle(A, len(AB))
|
circle(A, len(AB))
|
||||||
|
circle(B, len(AB))
|
|
@ -41,14 +41,9 @@ class Geometry extends HTMLElement
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let instr of parser.instructions)
|
|
||||||
{
|
|
||||||
console.log(instr.eval());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.attachShadow({mode: "open"});
|
this.attachShadow({mode: "open"});
|
||||||
let canvas = document.createElement("canvas");
|
let canvas = document.createElement("canvas");
|
||||||
canvas.width = 500;
|
canvas.width = 700;
|
||||||
canvas.height = 500;
|
canvas.height = 500;
|
||||||
let context = canvas.getContext("2d");
|
let context = canvas.getContext("2d");
|
||||||
|
|
||||||
|
@ -59,18 +54,27 @@ class Geometry extends HTMLElement
|
||||||
|
|
||||||
|
|
||||||
this.shapes = []
|
this.shapes = []
|
||||||
this.shapes.push(new Circle(this.context, new Vector2D(150, 150), 100))
|
for(let instruction of parser.instructions)
|
||||||
this.shapes.push(new Line(this.context, new Vector2D(), new Vector2D(300, 300)))
|
{
|
||||||
|
let value = instruction.eval();
|
||||||
|
switch(instruction.getType())
|
||||||
|
{
|
||||||
|
case InstructionType.Line:
|
||||||
|
{
|
||||||
|
console.log("New line " + value)
|
||||||
|
this.shapes.push(new Line(this.context, new Vector2D(value[0].x, value[0].y), new Vector2D(value[1].x, value[1].y)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case InstructionType.Circle:
|
||||||
|
{
|
||||||
|
console.log("New circle " + value)
|
||||||
|
this.shapes.push(new Circle(this.context, new Vector2D(value[0].x, value[0].y), value[1]));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.shapes.push(new Polygon(this.context,
|
|
||||||
[
|
|
||||||
new Vector2D(150, 150),
|
|
||||||
new Vector2D(150, 250),
|
|
||||||
new Vector2D(250, 250),
|
|
||||||
new Vector2D(250, 150),
|
|
||||||
new Vector2D(300, 300),
|
|
||||||
new Vector2D(250, 350),
|
|
||||||
]))
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ class CircleInstruction extends Instruction
|
||||||
{
|
{
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
super(InstructionType.Line, 2);
|
super(InstructionType.Circle, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
eval()
|
eval()
|
||||||
|
|
Loading…
Reference in a new issue