主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:210次

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
{

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] );

}

}

}

关键字词: