<% @Import Namespace="System.Drawing" %> <% @Import Namespace="System.Drawing.Imaging" %> <script language="c#" runat="server"> void Serpinski(int width, int height, int iterations) { // create the Bitmap Bitmap bitmap = new Bitmap(width, height); // Create our triangle's three Points Point top = new Point(width / 2, 0), bottomLeft = new Point(0,height), bottomRight = new Point(width, height); // Now, choose our starting point Point current = new Point(width / 2, height / 2); // Iterate iterations times Random rnd = new Random(); for (int iLoop = 0; iLoop < iterations; iLoop++) { // draw the pixel bitmap.SetPixel(current.X, current.Y, Color.Red); // Choose our next pixel switch (rnd.Next(3)) { case 0: current.X -= (current.X - top.X) / 2; current.Y -= (current.Y - top.Y) / 2; break; case 1: current.X -= (current.X - bottomLeft.X) / 2; current.Y -= (current.Y - bottomLeft.Y) / 2; break; case 2: current.X -= (current.X - bottomRight.X) / 2; current.Y -= (current.Y - bottomRight.Y) / 2; break; } } // Save the image to the OutputStream Response.ContentType = "image/jpeg"; bitmap.Save(Response.OutputStream, ImageFormat.Jpeg); // clean up... bitmap.Dispose(); } void Page_Load(Object senter, EventArgs e) { Serpinski(200,200, 10000); } </script>