public static void CreateIceCreamConeModel() { const double b = .1; const double h = 2; const double coneAngle = 15; const double w = .05; const double t = .1; const int bRev = 36; const int rev = 36; const int cuts = 4; var pivot = p(-h * tan(coneAngle), h); var curve = Enumerable.Range(0, bRev).Select(i => i * (90 - coneAngle) / (bRev - 1)).Select(angle => new { Point = p(-b * sin(angle), -b * cos(angle) + b / sin(coneAngle)), Normal = Normal.Average }) .Concat(Enumerable.Range(0, cuts).Select(i => i / (cuts - 1.0)).Select(pr => new { Point = p(-b * sin(90 - coneAngle), -b * cos(90 - coneAngle) + b / sin(coneAngle)) * (1 - pr) + pivot * pr, Normal = Normal.Mine })); //.Concat(new { Point = p(-b * sin(90 - coneAngle), -b * cos(90 - coneAngle) + b / sin(coneAngle)), Normal = Normal.Mine }) //.Concat(new { Point = pivot, Normal = Normal.Mine }); var surface = Enumerable.Range(0, rev + 1) .Select(i => 360.0 * i / rev) .Select(angle => curve.Select(p => pt(p.Point.X * cos(angle), p.Point.Y, p.Point.X * sin(angle)).WithMeshInfo(Normal.Average, Normal.Average, p.Normal, p.Normal).WithTexture(angle / 360.0, p.Point.Y / (h + t))).ToArray()); var rimCurve = new[] { pivot + p(-w / 2, 0), pivot + p(0, 0), pivot + p(0, t), pivot + p(-w / 2, t), pivot + p(-w, t / 2) }; var rim = Enumerable.Range(0, rev) .Select(i => 360.0 * i / rev) .Select(angle => rimCurve.Select(p => pt(p.X * cos(angle), p.Y, p.X * sin(angle)).WithMeshInfo(Normal.Average, Normal.Average, Normal.Mine, Normal.Mine)).ToArray()) .ToArray(); File.WriteAllText(@"D:\c\KTANE\IceCream\Assets\Models\IceCreamCone.obj", GenerateObjFile( CreateMesh(false, false, surface.ToArray()) .Concat(CreateMesh(false, false, surface.Reverse().ToArray())) .Concat(CreateMesh(true, true, rim)), "IceCreamCone")); Color color(string hex) => Color.FromArgb(Convert.ToInt32(hex.Substring(0, 2), 16), Convert.ToInt32(hex.Substring(2, 2), 16), Convert.ToInt32(hex.Substring(4, 2), 16)); const int bw = 500; const int bh = 400; GraphicsUtil.DrawBitmap(bw, bh, g => { g.Clear(color("EAB87F")); using (var pen = new Pen(color("A48662"), 5f)) using (var tr = new GraphicsTransformer(g).Translate(2.5, 0)) for (int i = -bh; i <= bw + bh; i += 50) { g.DrawLine(pen, i, 0, i + bh, bh); g.DrawLine(pen, i + bh, 0, i, bh); } using (var pen = new Pen(color("FFD197"), 5f)) for (int i = -bh; i <= bw + bh; i += 50) { g.DrawLine(pen, i, 0, i + bh, bh); g.DrawLine(pen, i + bh, 0, i, bh); } }).Save(@"D:\c\KTANE\IceCream\Assets\Textures\Waffle.png"); }
public static void MakeTextures() { var bmp = new Bitmap(@"D:\c\KTANE\Lasers\Data\Metal2.jpg"); for (int hatchIx = 1; hatchIx <= 9; hatchIx++) { foreach (var left in new[] { true, false }) { GraphicsUtil.DrawBitmap(250, 500, g => { g.DrawImage(bmp, -200 * ((hatchIx - 1) % 3), -200 * ((hatchIx - 1) / 3)); using (var tr = new GraphicsTransformer(g).Translate(left ? 0 : -250, 0)) { g.FillRectangle(Brushes.Black, 200, 0, 100, 500); for (int i = 0; i < 5; i++) { g.FillPolygon(new SolidBrush(GraphicsUtil.FromHsv(60, .9, .7)), new[] { new Point(200, 0), new Point(300, -100), new Point(300, 0), new Point(200, 100) }.Select(p => { p.Offset(0, 200 * i + 30); return(p); }).ToArray()); } } using (var tr2 = new GraphicsTransformer(g).Scale(.9, 1).Translate(left ? 255 : 5, 0)) g.DrawString(hatchIx.ToString(), new Font("Federal Escort Laser", 420f, FontStyle.Regular), new SolidBrush(GraphicsUtil.FromHsv(230, .1, .9)), 0, 250, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); }).Save($@"D:\c\KTANE\Lasers\Assets\Textures\Hatch-{hatchIx}-{(left ? "left" : "right")}.png"); } } }
public static void CreateIcons() { var chars = File.ReadAllText(@"D:\c\KTANE\SymbolCycle\Data\Symbols.txt"); const int w = 256; const int h = 256; var i = 0; var j = 0; while (i < chars.Length) { Console.WriteLine($"{i}/{chars.Length}"); var ch = char.ConvertFromUtf32(char.ConvertToUtf32(chars, i)); i += ch.Length; GraphicsUtil.DrawBitmap(w, h, g => { g.Clear(Color.Transparent); var gp = new GraphicsPath(); gp.AddString(ch, new FontFamily("🏸🏹🏺🕋🕌🕍🕎🕺🏏🏐🏑🏒🏓".Contains(ch) ? "Segoe UI Symbol" : "Symbola"), 0, 100, new PointF(0, 0), new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); var pts = gp.PathPoints; float minX = pts[0].X, maxX = pts[0].X, minY = pts[0].Y, maxY = pts[0].Y; foreach (var pt in pts) { minX = Math.Min(minX, pt.X); maxX = Math.Max(maxX, pt.X); minY = Math.Min(minY, pt.Y); maxY = Math.Max(maxY, pt.Y); } var rect = GraphicsUtil.FitIntoMaintainAspectRatio(new Size((int)(maxX - minX), (int)(maxY - minY)), new Rectangle(1, 1, w - 2, h - 2)); using (var tr = new GraphicsTransformer(g).Translate(-minX, -minY).Scale(rect.Width / (maxX - minX), rect.Height / (maxY - minY)).Translate(rect.Left, rect.Top)) g.FillPath(Brushes.White, gp); }).Save($@"D:\c\KTANE\SymbolCycle\Assets\Symbols\Icon{j}.png"); j++; } }
private static void DoGallows() { IEnumerable <PointD> decode(string str) => DecodeSvgPath.DecodePieces(str).SelectMany(ps => (ps.Points ?? new PointD[0])); var data = decode(@"M 40,822.375 40,872.375 70,872.375 70,852.375 87.5,852.375 140,922.375 140,1002.375 100,1002.375 100,1032.375 210,1032.375 210,1002.375 170,1002.375 170,822.375 z M 125,852.375 140,852.375 140,872.375 z") .Concat(decode(@"M 45,827.375 45,867.375 65,867.375 65,847.375 90,847.375 145,920.71875 145,1007.375 105,1007.375 105,1027.375 205,1027.375 205,1007.375 165,1007.375 165,827.375 z M 115,847.375 145,847.375 145,887.375 z")) .Select(p => new PointD(p.X, p.Y - 802.36218)) .ToArray(); GraphicsUtil.DrawBitmap(500, 500, g => { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.Clear(Color.White); using (var tr = new GraphicsTransformer(g).Scale(2, 2)) { for (int i = 0; i < data.Length; i++) { if (!new[] { 31, 15, 12, 28 }.Contains(i)) { g.DrawLine(new Pen(Color.CornflowerBlue, .5f), data[i].ToPointF(), data[(i + 1) % data.Length].ToPointF()); } } for (int i = 0; i < data.Length; i++) { g.DrawString(((char)(i < 10 ? '0' + i : 'A' + i - 10)).ToString(), new Font("Niagara Solid", 10f, FontStyle.Bold), Brushes.Black, (float)data[i].X, (float)data[i].Y, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); } } }).Save(@"D:\temp\temp.png"); void mkFile(string file, string objName, string code) { File.WriteAllText(file, GenerateObjFile(code.Split(',').Select(str => str.Select(ch => ch <= '9' ? ch - '0' : ch - 'A' + 10).Select(ix => pt(data[ix].X, ix >= 16 ? 5 : 0, data[ix].Y)).Reverse().ToArray()), objName, AutoNormal.Flat)); } mkFile(@"D:\c\KTANE\Mafia\Assets\Models\GallowsFront.obj", "GallowsFront", @"GSUJ,GJIH,KTVL,USRM,NQPO"); mkFile(@"D:\c\KTANE\Mafia\Assets\Models\GallowsBevel.obj", "GallowsBevel", @"0CSG,CBRS,BAQR,QA9P,OP98,7NO8,76MN,5LM6,4KL5,JK43,J32I,HI21,0GH1,TUED,EUVF,DFVT"); }
private static void makeTempPng(IEnumerable <PointD> polygon) { const double po = .02; const float pw = .02f; GraphicsUtil.DrawBitmap(1000, 1000, g => { g.Clear(Color.Transparent); using (var tr = new GraphicsTransformer(g).Scale(75, 75).Translate(500, 500)) { void drawPoint(PointD p, Brush brush) { g.DrawLine(new Pen(brush, pw), (p + new PointD(-po, -po)).ToPointF(), (p + new PointD(po, po)).ToPointF()); g.DrawLine(new Pen(brush, pw), (p + new PointD(po, -po)).ToPointF(), (p + new PointD(-po, po)).ToPointF()); } foreach (var point in polygon) { drawPoint(point, Brushes.Black); } } }).Save(@"D:\temp\temp.png"); }
public Bitmap DrawBitmap(HexagonySettings settings, Font defaultValueFont, Font defaultAnnotationFont) { var getX = Ut.Lambda((Direction dir, PointAxial coords) => 4 * coords.Q + 2 * coords.R + (dir is East ? 1 : 0)); var getY = Ut.Lambda((Direction dir, PointAxial coords) => 2 * coords.R + (dir is NorthEast ? 0 : dir is East ? 1 : 2)); int minX = getX(_dir, _mp), maxX = minX; int minY = getY(_dir, _mp), maxY = minY; foreach (var kvp1 in _edges) { foreach (var kvp2 in kvp1.Value) { var x = getX(kvp1.Key, kvp2.Key); var y = getY(kvp1.Key, kvp2.Key); minX = Math.Min(minX, x); minY = Math.Min(minY, y); maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); } } foreach (var kvp1 in _annotations) { foreach (var kvp2 in kvp1.Value) { var x = getX(kvp1.Key, kvp2.Key); var y = getY(kvp1.Key, kvp2.Key); minX = Math.Min(minX, x); minY = Math.Min(minY, y); maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); } } minX -= 3; minY -= 3; maxX += 3; maxY += 3; const int xFactor = 20, yFactor = 34; return(GraphicsUtil.DrawBitmap((maxX - minX) * xFactor, (maxY - minY) * yFactor, g => { g.Clear(settings.MemoryBackgroundColor); using (var unusedEdgePen = new Pen(settings.MemoryGridZeroColor)) using (var usedEdgePen = new Pen(settings.MemoryGridNonZeroColor, 2f)) using (var pointerBrush = new SolidBrush(settings.MemoryPointerColor)) using (var valueBrush = new SolidBrush(settings.MemoryValueFont.NullOr(f => f.Color) ?? Color.CornflowerBlue)) using (var annotationBrush = new SolidBrush(settings.MemoryAnnotationFont.NullOr(f => f.Color) ?? Color.ForestGreen)) using (var valueFont = settings.MemoryValueFont.NullOr(f => f.Font)) using (var annotationFont = settings.MemoryAnnotationFont.NullOr(f => f.Font)) { var sfValue = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near }; var sfAnnotation = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far }; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { if (!((y % 2 == 0 && x % 2 == 0) || ((y % 4 + 4) % 4 == 1 && (x % 4 + 4) % 4 == 1) || ((y % 4 + 4) % 4 == 3 && (x % 4 + 4) % 4 == 3))) { continue; } var dir = Direction.East; var mp = new PointAxial(0, 0); if (y % 2 != 0) { dir = Direction.East; mp = new PointAxial((x - y) / 4, (y - 1) / 2); } else if ((x - y) % 4 == 0) { dir = Direction.NorthEast; mp = new PointAxial((x - y) / 4, y / 2); } else { dir = Direction.SouthEast; mp = new PointAxial((x - y + 2) / 4, (y - 2) / 2); } var xx = (x - minX) * xFactor; var yy = (y - minY) * yFactor; var hasValue = _edges.ContainsKeys(dir, mp); using (var tr = new GraphicsTransformer(g).Rotate((dir is NorthEast ? -60 : dir is SouthEast ? 60 : 0) + (_cw ? 180 : 0)).Translate(xx, yy)) { g.DrawLine(hasValue ? usedEdgePen : unusedEdgePen, 0, yFactor * -.68f, 0, yFactor * .68f); if (dir == _dir && mp == _mp) { g.FillPolygon(pointerBrush, new[] { new PointF(0, yFactor * -.68f), new PointF(3, yFactor * .68f), new PointF(-3, yFactor * .68f) }); } } using (var tr = new GraphicsTransformer(g).Rotate((dir is NorthEast ? 30 : dir is SouthEast ? -30 : -90)).Translate(xx, yy)) { if (hasValue) { var str = _edges[dir][mp].ToString(); // Show printable ISO-8859-1 characters if (_edges[dir][mp] >= 0x20 && _edges[dir][mp] <= 0xff && _edges[dir][mp] != 0x7f) { try { str += " '" + char.ConvertFromUtf32((int)_edges[dir][mp]) + "'"; } catch { } } g.DrawString(str, valueFont ?? defaultValueFont, valueBrush, 0, 0, sfValue); } var annotation = _annotations.Get(dir, mp, null); if (!string.IsNullOrWhiteSpace(annotation)) { g.DrawString(annotation, annotationFont ?? defaultAnnotationFont, annotationBrush, 0, 2, sfAnnotation); } } } } } })); }
public static void RenderFriendshipSymbols() { var ponyColors = ClassifyJson.DeserializeFile <Dictionary <string, string> >(_poniesJson); var filesButNoPonyColor = new DirectoryInfo(_poniesDir).EnumerateFiles("*.png").Where(f => !ponyColors.ContainsKey(Path.GetFileNameWithoutExtension(f.Name))).ToArray(); if (filesButNoPonyColor.Length > 0) { Console.WriteLine("Files but no pony color:"); foreach (var file in filesButNoPonyColor) { Console.WriteLine(Path.GetFileNameWithoutExtension(file.Name)); } Console.WriteLine(); } //ClassifyJson.SerializeToFile(ponyColors, _poniesJson); ponyColors.Where(kvp => File.Exists(Path.Combine(_poniesDir, $"{kvp.Key}.png"))).ParallelForEach(4, kvp => { var pony = kvp.Key; var newFilename = $"{kvp.Key}.png"; lock (ponyColors) Console.WriteLine("Starting " + newFilename); var color = Color.FromArgb(Convert.ToInt32(kvp.Value.Substring(0, 2), 16), Convert.ToInt32(kvp.Value.Substring(2, 2), 16), Convert.ToInt32(kvp.Value.Substring(4, 2), 16)); var newCutieMark = GraphicsUtil.MakeSemitransparentImage(200, 200, g => { g.SetHighQuality(); }, g => { g.Clear(color); using (var bmp = new Bitmap(Path.Combine(_poniesDir, $"{pony}.png"))) { var width = bmp.Width; var height = bmp.Height; var pts = new List <PointD>(); unsafe { var bits = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); for (int y = 0; y < height; y++) { byte *readFrom = (byte *)bits.Scan0 + y * bits.Stride; for (int x = 0; x < width; x++) { if (readFrom[4 * x + 3] != 0) { pts.Add(new PointD(x, y)); } } } bmp.UnlockBits(bits); } var circum = CircleD.GetCircumscribedCircle(pts); using (var tr = new GraphicsTransformer(g).Translate(-circum.Center.X, -circum.Center.Y).Scale(90 / circum.Radius, 90 / circum.Radius).Translate(100, 100)) { g.DrawImage(bmp, 0, 0); //g.DrawEllipse(Pens.Black, circum.ToRectangle().ToRectangleF()); } } }, g => { g.Clear(Color.Transparent); g.FillEllipse(Brushes.Black, 1, 1, 197, 197); }); //* var tmp = $@"D:\c\KTANE\Public\HTML\img\Friendship\tmp_{newFilename}"; var final = $@"D:\c\KTANE\Public\HTML\img\Friendship\{newFilename}"; newCutieMark.Save(tmp, ImageFormat.Png); CommandRunner.Run("pngcr", tmp, final).OutputNothing().Go(); File.Delete(tmp); /*/ * var final = $@"D:\c\KTANE\Friendship\Manual\img\Friendship\{newFilename}"; * newCutieMark.Save(final, ImageFormat.Png); * /**/ lock (ponyColors) Console.WriteLine("Saved " + newFilename); }); }