using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Turtle { public partial class MainForm : Form { public Canvas Canvas { get; private set; } public MainForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { Run(dialog.FileName, Convert.ToInt32(stepCountBox.Value)); } } } private void button2_Click(object sender, EventArgs e) { using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.DefaultExt = "png"; dialog.Filter = "Obrázek PNG|*.png|Obrázek GIF|*.gif|Obrázek BMP|*.bmp|Všechny soubory (*.*)|*.*"; if (dialog.ShowDialog() == DialogResult.OK) { Save(dialog.FileName); } } } private void Run(string path, int stepCount) { Canvas = new Canvas(); Canvas.MaxStepCount = stepCount; using (Parser parser = new Parser(path)) { Token t; while ((t = parser.FetchToken()) != null) { // function call if (t.Type == TokenType.String) { string name = t.Text; while ((t = parser.FetchToken()) != null) { if (t.Type == TokenType.RightBracket) break; if (t.Type == TokenType.Number) { Canvas.Execute(name, t.Value); break; } } } } } pictureBox1.Image = Canvas.Image; } private void Save(string path) { if (Canvas.Image == null) { MessageBox.Show("Musíš vybrat soubor!"); return; } Canvas.Image.Save(path); } } }