C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to Draw SerpinskiTriangle in Asp.net


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: vijethaMember Level: Gold    
Rating: Points: 10



The following code sample shows how to Draw SerpinskiTriangle in Asp.net

import namespaces

using System.Drawing;
using System.Drawing.Imaging;

Add This Code In PageLoad


protected void Page_Load(object sender, EventArgs e)
{
int width = 200;
int height = 200;
int iterations = 10000;
//create instance for bitmap class
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;
}
}
bitmap.Save(@"D:\img", ImageFormat.Gif);

// Save the image to the OutputStream
Response.ContentType = "image/jpeg";
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);

// clean up...
bitmap.Dispose();

}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Drawing Line Charts In asp.net
Previous Resource: How to write validationexpression for a RegularExpressionValidator
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use