-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw-stuff
More file actions
47 lines (45 loc) · 1.36 KB
/
draw-stuff
File metadata and controls
47 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Draw stuff
// Time-stamp: <2019-01-21 20:08:33 Chuck Siska>
// ------------------------------------------------------------
// FUN. Draw filled rect.
function draw_rect( ctx, stroke, fill )
{
stroke = stroke || 'lightgrey';
fill = fill || 'dimgrey';
ctx.save( );
ctx.strokeStyle = stroke;
ctx.fillStyle = fill;
ctx.lineWidth = 5;
ctx.rect(75, 50, canvas.width - 150, canvas.height - 100);
ctx.stroke();
ctx.fill();
ctx.restore( );
}
// ===================================================== draw_grid ====
function draw_grid( rctx, rminor, rmajor, rstroke, rfill )
{
rctx.save( );
rctx.strokeStyle = rstroke;
rctx.fillStyle = rfill;
let width = rctx.canvas.width;
let height = rctx.canvas.height;
for ( var ix = 0; ix < width; ix += rminor )
{
rctx.beginPath( );
rctx.moveTo( ix, 0 );
rctx.lineTo( ix, height );
rctx.lineWidth = ( ix % rmajor == 0 ) ? 0.5 : 0.25;
rctx.stroke( );
if ( ix % rmajor == 0 ) { rctx.fillText( ix, ix, 10 ); }
}
for ( var iy = 0; iy < height; iy += rminor )
{
rctx.beginPath( );
rctx.moveTo( 0, iy );
rctx.lineTo( width, iy );
rctx.lineWidth = ( iy % rmajor == 0 ) ? 0.5 : 0.25;
rctx.stroke( );
if ( iy % rmajor == 0 ) {rctx.fillText( iy, 0, iy + 10 );}
}
rctx.restore( );
}