首页 > 开发 > 综合 > 正文

C# 绘图--金刚石

2024-07-21 02:19:07
字体:
来源:转载
供稿:网友

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

}

}

}

,欢迎访问网页设计爱好者web开发。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表