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] );
}
}
}
参考文献:
1. Charles Petzold. Programming Microsoft Windows With C#.Microsoft Press. 2002.
2. 陆润民. C语言绘图教程.清华大学出版社. 1996年4月第一版.
本文地址:http://com.8s8s.com/it/it44559.htm