Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- public class FractalTreeForm : Form
- {
- private Bitmap canvas;
- public FractalTreeForm()
- {
- this.Width = 800;
- this.Height = 600;
- canvas = new Bitmap(this.Width, this.Height);
- this.Paint += new PaintEventHandler(DrawTree);
- }
- private void DrawTree(object sender, PaintEventArgs e)
- {
- using (Graphics g = Graphics.FromImage(canvas))
- {
- g.Clear(Color.White);
- DrawBranch(g, this.Width / 2, this.Height - 50, -90, 100, 10);
- }
- e.Graphics.DrawImage(canvas, 0, 0);
- }
- private void DrawBranch(Graphics g, float x, float y, float angle, float length, int depth)
- {
- if (depth == 0) return;
- float x2 = x + (float)(length * Math.Cos(angle * Math.PI / 180));
- float y2 = y + (float)(length * Math.Sin(angle * Math.PI / 180));
- g.DrawLine(Pens.Black, x, y, x2, y2);
- DrawBranch(g, x2, y2, angle - 30, length * 0.7f, depth - 1);
- DrawBranch(g, x2, y2, angle + 30, length * 0.7f, depth - 1);
- }
- [STAThread]
- static void Main()
- {
- Application.Run(new FractalTreeForm());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement