using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace win_kytka { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private Stack zasobnik = new Stack(); private Bitmap bm; private struct Zelva { public float x,y; public float direction; public float krok; public float uchylka; public Zelva(float x, float y, float direction, float uchylka, float krok){ this.x = x; this.y = y; this.direction = direction; this.uchylka = uchylka; this.krok = krok; } } ; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(664, 654); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Zelva ahoj = new Zelva(this.ClientSize.Width/2,this.ClientSize.Height,(float)(Math.PI/2),2/9.0f,2); Zelva nazdar = new Zelva(this.ClientSize.Width/2f,this.ClientSize.Height,(float)(Math.PI/2f),2/8.0f,0.1f); //kreslic(e.Graphics, ref ahoj,7,"X"); kreslic(e.Graphics, ref nazdar,12,"X"); /*bm = new Bitmap(1000,1000); kreslic(Graphics.FromImage(bm), ref nazdar, 12, "X"); bm.Save("ahoj.bmp");*/ } private void kreslic(Graphics g, ref Zelva zelva, int zanoreni, string retezec){ float foo; float bar; if(zanoreni == 0) return; for(int i = 0; i < retezec.Length; i++) { switch(retezec[i]) { case 'F': foo = (float)(zelva.x + zelva.krok * Math.Cos(zelva.direction)); bar = (float)(zelva.y - zelva.krok * Math.Sin(zelva.direction)); g.DrawLine(Pens.Black,zelva.x,zelva.y,foo, bar); zelva.x = foo; zelva.y = bar; kreslic(g,ref zelva,zanoreni-1,"FF"); break; case 'X': kreslic(g,ref zelva,zanoreni-1,"F[[+X]+XF]FX[[-X]-XF]+X"); break; case '[': zasobnik.Push(zelva); break; case ']': zelva = (Zelva)zasobnik.Pop(); break; case '+': zelva.direction += zelva.uchylka; break; case '-': zelva.direction -= zelva.uchylka; break; } } } } }