pointvec/sources/scripts/guide.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-11-09 14:47:06 -05:00
function Guide()
{
2017-11-12 21:25:29 -05:00
this.el = document.createElement("canvas");
2017-11-09 14:47:06 -05:00
this.el.id = "guide";
2017-11-12 21:25:29 -05:00
this.el.width = 600;
this.el.height = 600;
this.el.style.width = "300px";
this.el.style.height = "300px";
2017-11-12 16:47:34 -05:00
this.markers;
2017-11-12 21:25:29 -05:00
2017-11-09 14:47:06 -05:00
this.start = function()
{
2017-11-12 21:25:29 -05:00
this.update();
}
this.clear = function()
{
this.el.getContext('2d').clearRect(0, 0, 600, 600);
2017-11-12 16:47:34 -05:00
}
2017-11-12 21:25:29 -05:00
this.update = function()
2017-11-12 16:47:34 -05:00
{
2017-11-12 21:25:29 -05:00
this.clear();
2017-11-12 16:47:34 -05:00
for (var x = dotgrid.grid_x; x >= 0; x--) {
for (var y = dotgrid.grid_y; y >= 0; y--) {
2017-11-12 21:25:29 -05:00
var pos_x = parseInt(x * dotgrid.grid_width) ;
var pos_y = parseInt(y * dotgrid.grid_height) ;
var is_step = x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0;
var radius = is_step ? 1.5 : 0.5;
dotgrid.guide.draw_marker({x:pos_x * 2,y:pos_y * 2},radius,is_step);
2017-11-09 14:47:06 -05:00
}
}
}
2017-11-12 21:25:29 -05:00
this.draw_marker = function(pos,radius = 1,step)
{
var ctx = this.el.getContext('2d');
ctx.beginPath();
ctx.arc(pos.x, pos.y, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = step ? 'green' : 'red';
ctx.fill();
}
2017-11-09 14:47:06 -05:00
}