Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Phractal
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         Graphics gfx;
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private double[] Fractal(int iterations)
  21.         {
  22.             double[] map = new double[3] { 1, -2, 1 };
  23.             for (int i = 0; i < iterations; i++)
  24.                 map = subdivide(map,iterations-i);
  25.             return map;
  26.         }
  27.  
  28.         private double[] subdivide(double[] previous, int amp)
  29.         {
  30.             Random rand = new Random();
  31.             double[] returned = new double[previous.Length*2-1];
  32.             for (int i = 0; i < returned.Length; i+=2)
  33.             {
  34.                 returned[i] = previous[i / 2];
  35.                 if (i != returned.Length - 1)
  36.                     returned[i + 1] = ((previous[i / 2] + previous[i / 2 + 1]) / 2) + (double)rand.Next(-amp, amp)/20d;
  37.                 /* change the 20d to something that suits you, the larger it is the smaller the amplifier's general strength*/
  38.             }
  39.             return returned;
  40.         }
  41.  
  42.         private void OnPaint(object sender, PaintEventArgs e)
  43.         {
  44.             gfx = e.Graphics;
  45.             gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  46.             double[] subdivided = Fractal(8);
  47.             Point[] poly = new Point[subdivided.Length];
  48.             for (int i = 0; i < subdivided.Length; i++)
  49.             {
  50.                 poly[i] = new Point(640/subdivided.Length*i, 300+(int)(subdivided[i] * 100));
  51.             }
  52.             gfx.FillPolygon(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, this.Size.Height), Color.Black, Color.CornflowerBlue),
  53.                 new Point[4]{
  54.                     new Point(0,0),
  55.                     new Point(this.Size.Width,0),
  56.                     new Point(this.Size.Width,this.Size.Height),
  57.                     new Point(0,this.Size.Height)});
  58.             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);
  59.            
  60.  
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement