Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 Phractal
- {
- public partial class Form1 : Form
- {
- Graphics gfx;
- public Form1()
- {
- InitializeComponent();
- }
- private double[] Fractal(int iterations)
- {
- double[] map = new double[3] { 1, -2, 1 };
- for (int i = 0; i < iterations; i++)
- map = subdivide(map,iterations-i);
- return map;
- }
- private double[] subdivide(double[] previous, int amp)
- {
- Random rand = new Random();
- double[] returned = new double[previous.Length*2-1];
- for (int i = 0; i < returned.Length; i+=2)
- {
- returned[i] = previous[i / 2];
- if (i != returned.Length - 1)
- returned[i + 1] = ((previous[i / 2] + previous[i / 2 + 1]) / 2) + (double)rand.Next(-amp, amp)/20d;
- /* change the 20d to something that suits you, the larger it is the smaller the amplifier's general strength*/
- }
- return returned;
- }
- private void OnPaint(object sender, PaintEventArgs e)
- {
- gfx = e.Graphics;
- gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- double[] subdivided = Fractal(8);
- Point[] poly = new Point[subdivided.Length];
- for (int i = 0; i < subdivided.Length; i++)
- {
- poly[i] = new Point(640/subdivided.Length*i, 300+(int)(subdivided[i] * 100));
- }
- gfx.FillPolygon(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, this.Size.Height), Color.Black, Color.CornflowerBlue),
- new Point[4]{
- new Point(0,0),
- new Point(this.Size.Width,0),
- new Point(this.Size.Width,this.Size.Height),
- new Point(0,this.Size.Height)});
- gfx.FillPolygon(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, this.Size.Height), Color.FromArgb(30,30,30), Color.Black), poly);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement