Today I’d like to share another old project of mine.
I’ve been looking through my old YouTube uploads and trying to see which scripts I can still track down.
Most scripts I wrote as a beginner programmer I’ve shared at some point on my Facebook (A practice I stopped about 8 years ago). If I look through my old messages I will have a lot of better code from a more recent time but focused on YouTube content I can recover the corresponding code for.

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Bitmap DrawArea;
        public Form1()
        {
            InitializeComponent();
        }

        public Random R = new Random();

        public void drawleaf(int[] pos, double dir,Graphics g)
        {
            Pen mypen = new Pen(Brushes.Green);
            int x; int y;
            x = pos[0] + Convert.ToInt32(Math.Round(Math.Cos(dir+(R.Next(1,3600)%90-45)/180.00*Math.PI) * 6));
            y = pos[1] + Convert.ToInt32(Math.Round(Math.Sin(dir + (R.Next(1, 3600) % 90-45) / 180.00 * Math.PI) * 6));
            int[] posn = new int[2];
            posn[0] = x;
            posn[1] = y;
            int ite;
            for (ite = 0; ite < 2; ite++)
            {
                g.DrawLine(mypen, pos[0], pos[1] + ite, x, y + ite);
            }
        }

        public void troactal(int i, int[] pos,double dir,Graphics g, Pen mypen)
        {
            int x; int y;
            x = pos[0] + Convert.ToInt16(Math.Round(Math.Cos(dir)*i*10));
            y = pos[1] + Convert.ToInt16(Math.Round(Math.Sin(dir)*i*10));
            int[] posn= new int[2];
            posn[0]=x;
            posn[1]=y;
            int ite; int ite2;
            for (ite = 0; ite < i; ite++)
            {
                for (ite2 = 0; ite2 < i; ite2++)
                {
                    g.DrawLine(mypen, pos[0] + ite - i / 2, pos[1] + ite2 - i / 2, x + ite - i / 2, y + ite2 - i / 2);
                }
            }
            if (i > 0)
            {
                troactal(i - 1, posn, dir + (R.Next(1, 3600) % 30 - 15) / 180.00 * Math.PI, g, mypen);
                troactal(i - 2, posn, dir + (R.Next(1, 3600) % (8 * i) - (4 * i)) / 180.00 * Math.PI + Math.PI / 8, g, mypen);
                troactal(i - 2, posn, dir + (R.Next(1, 3600) % (8 * i) - (4 * i)) / 180.00 * Math.PI - Math.PI / 8, g, mypen);
                troactal(i - 3, posn, dir + (R.Next(1, 3600) % (8 * i) - (4 * i)) / 180.00 * Math.PI + Math.PI / 4, g, mypen);
                troactal(i - 3, posn, dir + (R.Next(1, 3600) % (8 * i) - (4 * i)) / 180.00 * Math.PI - Math.PI / 4, g, mypen);
            }
            else { drawleaf(pos,dir,g); }
        }

        

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void GenTree(int iterations)
        {
            DrawArea = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height);
            Graphics g;
            g = Graphics.FromImage(DrawArea);
            int[] pos = new int[2];
            Pen mypen = new Pen(Brushes.Black);
            pos[0] = pictureBox1.Width/2;
            pos[1] = pictureBox1.Height-30;
            troactal(iterations, pos, -Math.PI / 2, g, mypen);
            pictureBox1.Image = DrawArea;
            g.Dispose();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            GenTree(Convert.ToInt16(numericUpDown1.Value));
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            panel1.Left = this.Size.Width - 145;
            panel1.Top = this.Size.Height - 290;
            pictureBox1.Width = this.Size.Width - 150;
            pictureBox1.Height = this.Size.Height;
        }
    }
}
Back to top