// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace Spludlow.Drawing { public class Dartboard { public static void Demo(string pageSize) { Spludlow.Printing.PrintDoc printDoc = new Printing.PrintDoc(pageSize, "Dartboard Demo"); float radius = (printDoc.Width - 10) / 2; Draw(printDoc, printDoc.Width / 2, printDoc.Height / 2, radius); Spludlow.Printing.Printer.Print(printDoc); Spludlow.Log.Finish("Dartboard Demo Finished size:" + pageSize + ", radius:" + radius); } /// /// Draw a Dartboard. For actual size Radius = 225 /// public static void Draw(Spludlow.Printing.PrintDoc doc, float x, float y, float radius) { bool extraNumbers = false; float fontHeadSize = radius / 2.0F; string fontHead = "Arial, " + fontHeadSize + ", Bold"; string fontDouble = "Arial, 28.0, Bold"; string fontTebble = "Arial, 16.0, Bold"; float scale = radius / 225; float outerRadius = 225 * scale; float outerWireRadius = 220 * scale; float outerDoubleRadius = 170 * scale; float innerDoubleRadius = 160 * scale; float outerTrebbleRadius = 105 * scale; float innerTrebbleRadius = 95 * scale; float outerBullRadius = 17.5F * scale; float innerBullRadius = 7.5F * scale; float wireWidth = scale; Color wireColour = Color.Silver; int[] numbers = new int[] { 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5, }; doc.Cirlce(x, y, outerRadius, 0, Color.Empty, Color.Black); doc.Cirlce(x, y, outerWireRadius, wireWidth, wireColour, Color.Empty); outerWireRadius *= 0.9F; float step = 360.0F / 20.0F; float offset = -(step / 2) - 180; bool odd = true; for (int sector = 0; sector < 20; ++sector) { float startAngle = offset + (float)sector * step; float endAngle = startAngle + step; Color small = Color.Red; if (odd == false) small = Color.Green; Color large = Color.Black; if (odd == false) large = Color.Wheat; doc.ArcSector(x, y, outerDoubleRadius, outerDoubleRadius, innerDoubleRadius, innerDoubleRadius, startAngle, endAngle, 0, wireColour, small); doc.ArcSector(x, y, innerDoubleRadius, innerDoubleRadius, outerTrebbleRadius, outerTrebbleRadius, startAngle, endAngle, 0, wireColour, large); doc.ArcSector(x, y, outerTrebbleRadius, outerTrebbleRadius, innerTrebbleRadius, innerTrebbleRadius, startAngle, endAngle, 0, wireColour, small); doc.ArcSector(x, y, innerTrebbleRadius, innerTrebbleRadius, outerBullRadius, outerBullRadius, startAngle, endAngle, 0, wireColour, large); startAngle += (step / 2); PointF textPoint = Spludlow.Drawing.Maths.ArcPoint(x, y, outerWireRadius, outerWireRadius, startAngle); float textAngle = startAngle + 180; doc.Text(numbers[sector].ToString(), fontHead, textPoint.X, textPoint.Y, wireColour, textAngle, System.Drawing.StringAlignment.Center); if (extraNumbers == true) { string doubleText = numbers[sector] * 2 + "-" + numbers[sector] * 2 * 2 + "-" + numbers[sector] * 2 * 3; float textRadius = outerDoubleRadius - 5.0F; textPoint = Spludlow.Drawing.Maths.ArcPoint(x, y, textRadius, textRadius, startAngle); doc.Text(doubleText, fontDouble, textPoint.X, textPoint.Y, Color.White, startAngle + 180, System.Drawing.StringAlignment.Center); doubleText = numbers[sector] * 3 + "-" + numbers[sector] * 3 * 2 + "-" + numbers[sector] * 3 * 3; textRadius = outerTrebbleRadius - 5.0F; textPoint = Spludlow.Drawing.Maths.ArcPoint(x, y, textRadius, textRadius, startAngle); doc.Text(doubleText, fontTebble, textPoint.X, textPoint.Y, Color.White, startAngle + 180, System.Drawing.StringAlignment.Center); } odd = !odd; } doc.Cirlce(x, y, outerDoubleRadius, wireWidth, wireColour, Color.Empty); doc.Cirlce(x, y, innerDoubleRadius, wireWidth, wireColour, Color.Empty); doc.Cirlce(x, y, outerTrebbleRadius, wireWidth, wireColour, Color.Empty); doc.Cirlce(x, y, innerTrebbleRadius, wireWidth, wireColour, Color.Empty); doc.Cirlce(x, y, outerBullRadius, wireWidth, wireColour, Color.Green); doc.Cirlce(x, y, innerBullRadius, wireWidth, wireColour, Color.Red); for (int sector = 0; sector < 20; ++sector) { float startAngle = offset + (float)sector * step; float endAngle = startAngle + step; PointF startWire = Spludlow.Drawing.Maths.ArcPoint(x, y, outerBullRadius, outerBullRadius, startAngle); PointF endWire = Spludlow.Drawing.Maths.ArcPoint(x, y, outerDoubleRadius * 1.05F, outerDoubleRadius * 1.05F, startAngle); doc.Line(startWire.X, startWire.Y, endWire.X, endWire.Y, wireWidth, wireColour); } } } }