コード例 #1
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);
        }
コード例 #2
0
ファイル: LSystem3.cs プロジェクト: Tomas0015/TurtleGraphics
        public Turtle Create()
        {
            Config.Add('F', Fwd);
            Config.Add('G', Fwd);
            Config.Add('+', RotPos);
            Config.Add('-', RotNeg);
            Config.Add('[', SavePos);
            Config.Add(']', RestPos);
            Config.Add('M', grn);
            Config.Add('S', brw);
            //1
            //Rules.Add('X',"F");
            //Rules.Add('F', "F+[[X]-X]-F[-FX]+X");
            //2 20°
            //Rules.Add('F', "FF+[+F-F-F]-[-F+F+F]");
            //3 60°
            //Rules.Add('F', "F+F--F+F");
            //4 45°
            //Rules.Add('M', "SF[+MF][-MF]SFMF");
            //Rules.Add('S', "SFSF");
            //5 90
            //Rules.Add('F', "F+F-F-F+F");
            //6 120
            Rules.Add('F', "F-G+F+G-F");
            Rules.Add('G', "GG");
            string start = "F-G-G";

            //F + - [ ]
            //F -> FF+[+F-F-F]-[-F+F+F]
            for (int i = 0; i < 7; i++)
            {
                start = Generate(start);
                Console.WriteLine(i);
            }
            //t.MoveTo(t.X,t.ScreenHeight);
            t.MoveTo(0, t.ScreenHeight - 100);
            t.TurtleSpeed = 20;
            t.SetBrushSize(1);
            //t.Rotate(-90);
            Draw(start);
            return(t);
        }
コード例 #3
0
ファイル: Code.cs プロジェクト: Tomas0015/TurtleGraphicsnew
        public Turtle ToExecute()
        {
            Turtle     t   = new Turtle(true);
            Text       txt = new Text();
            ImagePrint prn = new ImagePrint();

            t.SetBrushSize(1);
            t.AnimatePath = false;
            t.TurtleSpeed = 50;
            t             = prn.Print(t, "image.bmp");
            t.SetColor("brown");
            t = txt.Write(t, "Želva", true, 1);
            t.Rotate(22.5);
            t.SetColor("Black");
            t = txt.Write(t, "píše!", false, 1);
            for (int i = 0; i < 14; i++)
            {
                t.Rotate(22.5);
                t = txt.Write(t, i + string.Empty, (i % 2) == 1, 1, new Font(SystemFonts.DefaultFont.FontFamily, 36, FontStyle.Underline));
            }

            return(t);
        }