Algorithm project "Code"

profileMalikbinn
draw-stuff.js

// 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( ); }