private void grid(ICanvasRenderingContext2D ctx, int w, int h, int size, int unit, string color, string color2) { int x, y, i, j; for (i = 0, x = size; x < w; ++i, x += size) { ctx.beginPath(); ctx.strokeStyle = (i%unit != 0) ? color : color2; ctx.moveTo(x, 0); ctx.lineTo(x, h); ctx.stroke(); ctx.closePath(); } for (j = 0, y = size; y < h; ++j, y += size) { ctx.beginPath(); ctx.strokeStyle = (j%unit != 0) ? color : color2; ctx.moveTo(0, y); ctx.lineTo(w, y); ctx.stroke(); ctx.closePath(); } }
private void drawStar(ICanvasRenderingContext2D ctx, int r) { ctx.save(); ctx.beginPath(); ctx.moveTo(r, 0); for (int i = 0; i < 9; i++) { ctx.rotate(Math.PI/5); if (i%2 == 0) { ctx.lineTo((r/0.525731)*0.200811, 0); } else { ctx.lineTo(r, 0); } } ctx.closePath(); ctx.fill(); ctx.restore(); }
private string TextPositions(ICanvasRenderingContext2D ctx) { int i, j; string text = "Hello world"; var align = new[] {"left", "center", "right"}; var baseline = new[] {"top", "hanging", "middle", "alphabetic", "ideographic", "bottom"}; ctx.fillStyle = "#000"; ctx.strokeStyle = "#f00"; ctx.font = "20px Arial"; ctx.translate(70, 30); for (i = 0; i < align.Length; i++) { for (j = 0; j < baseline.Length; j++) { ctx.save(); ctx.translate(i*170 + 0.5, j*50 + 0.5); ctx.textAlign = align[i]; ctx.textBaseLine = baseline[j]; ctx.fillText(text, 0, 0); ctx.beginPath(); ctx.moveTo(-50, 0); ctx.lineTo(50, 0); ctx.moveTo(0, -10); ctx.lineTo(0, 10); ctx.closePath(); ctx.stroke(); ctx.restore(); } } return @"Originals\Text\TextPositions.png"; }