日期:2009-07-11  浏览次数:20465 次


C# 绘图--金刚石

杨贺宏


//-------------------------------------


// DrawDiamond.cs by Flycrane

//-------------------------------------

using System;

using System.Drawing;

using System.Windows.Forms;



class DrawDiamond : Form

{

publicstaticvoidMain()

{

Application.Run( new DrawDiamond() );

}

public DrawDiamond()

{

Text= "金刚石图案-Flycrane";

BackColor= Color.Black;

ForeColor= Color.White;

ResizeRedraw= true;

Width= 400;

Height= 400;

}



protectedoverridevoid OnPaint(PaintEventArgs e)

{

Graphics myGraphics= e.Graphics;

Pen myPen= new Pen( ForeColor,2 );



float radius= (float) ( Width/2.2 );

constint partitionNum= 25;

float angleUnit= (float) ( 2*Math.PI/partitionNum );



float[] circleX= newfloat[partitionNum];

float[] circleY= newfloat[partitionNum];



// center of the circle.

float originX=ClientSize.Width/2;

float originY=ClientSize.Height/2;



//store coordinates of the nodes on the circle verge.

for ( int i=0;i<partitionNum;i++ )

{

circleX[i]= (float) ( radius*Math.Cos( i*angleUnit ) ) + originX;

circleY[i]= (float) ( radius*Math.Sin( i*angleUnit ) ) + originY;

}



//link nodes on the circle verge.

for ( int i=0;i<=partitionNum-2;i++ )

{

for ( int j=i+1;j<=partitionNum-1;j++ )

myGraphics.DrawLine( myPen,circleX[i],circleY[i],circleX[j],circleY[j] );

}

}

}