C# 绘图--金刚石

C# 绘图--金刚石

杨贺宏

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

// DrawDiamond.cs by Flycrane

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

using System;

using System.Drawing;

using System.Windows.Forms;

class DrawDiamond : Form

{

public static void Main ()

{

Application.Run( new DrawDiamond() );

}

public DrawDiamond()

{

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

BackColor= Color.Black;

ForeColor= Color.White;

ResizeRedraw= true ;

Width= 400;

Height= 400;

}

protected override void OnPaint(PaintEventArgs e)

{

Graphics myGraphics= e.Graphics;

Pen myPen= new Pen( ForeColor,2 );

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

const int partitionNum= 25;

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

float [] circleX= new float [partitionNum];

float [] circleY= new float [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 ) ( radiusMath.Cos( iangleUnit ) ) + originX;

circleY[i]= ( float ) ( radiusMath.Sin( iangleUnit ) ) + 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月第一版.

Published At
Categories with Web编程
Tagged with
comments powered by Disqus