예제 #1
0
        public Turtle Print(Turtle printer, string input, int spacing = 1)
        {
            printer.ShowTurtle = false;
            int    width  = 64;
            int    height = 64;
            Bitmap image  = (Bitmap)Image.FromFile(input, true);

            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    Color clr = image.GetPixel(j, i);
                    printer.SetColor(clr.R, clr.G, clr.B);
                    printer.Forward(1);
                }
                printer.CaptureScreenshot();
                printer.PenUp();
                printer.Rotate(90, false);
                printer.Forward(spacing);
                printer.Rotate(90, false);
                printer.Forward(image.Width);
                printer.Rotate(-180, false);
                printer.PenDown();
            }
            printer.ShowTurtle = true;
            return(printer);
        }
예제 #2
0
        public Turtle Write(Turtle writer, string input, bool inv = false, double brushSize = 1, Font textFont = null, int width = 64, int height = 64)
        {
            if (input == string.Empty)
            {
                return(writer);
            }
            if (textFont == null)
            {
                textFont = new Font(SystemFonts.DefaultFont.FontFamily, 36, FontStyle.Regular);
            }
            char[]   chars = input.ToCharArray();
            string[] lines = new string[height];
            writer.SetBrushSize(brushSize);
            for (int ctr = 0; ctr < chars.Length; ctr++)
            {
                Bitmap image = CharToImage(chars[ctr], textFont, width, height);

                for (int h = 0; h < image.Height; h++)
                {
                    string line = string.Empty;
                    for (int w = 0; w < image.Width; w++)
                    {
                        Color color = image.GetPixel(w, h);
                        if ((color.A != 0) != inv)
                        {
                            line += '1';
                        }
                        else
                        {
                            line += '0';
                        }
                    }
                    lines[h] += line;
                }
            }
            foreach (string line in lines)
            {
                int    totalProceed = 0;
                int    temp         = 0;
                string lineCopy     = line;
                while (line.Length != totalProceed)
                {
                    writer   = penSet(lineCopy[0], writer);
                    temp     = LastIndexBeforeChange(lineCopy);
                    lineCopy = lineCopy.Substring(temp);
                    writer.Forward(temp);
                    totalProceed += temp;
                    //Console.WriteLine(totalProceed + "/" + line.Length);
                }
                writer.PenUp();
                writer = TurleReturn(writer, line.Length, brushSize);
            }
            return(writer);
        }
예제 #3
0
 static Turtle penSet(char state, Turtle t)
 {
     if (state == '0')
     {
         t.PenUp();
     }
     else
     {
         t.PenDown();
     }
     return(t);
 }