⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 这是《C#图形程序设计》这本书的源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
				}
			}
			for(n=0;n<=nn;n++)
			{
				for(i=1;i<=120;i++)
				{
					x=(int)((x2[i]-x1[i])/Math.Log(nn+1)*Math.Log(n+1)+x1[i]);
					y=(int)((y2[i]-y1[i])/Math.Log(nn+1)*Math.Log(n+1)+y1[i]);
					x+=220;
					y+=160;
					if(i==1)
					{
						p1.X=x;p1.Y=y;
					}
					else
					{
						bx=x;by=y;
						p2.X=bx;p2.Y=by;
						g.DrawLine(pen1,p1,p2);
						p1=p2;
					}
				}
				p1.X=x;p1.Y=y;
				g.DrawLine(pen1,p2,p1);
			}
		}

		private void menuItem9_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int n,nn,x,y,bx,by,i,r;
			double a,d,pi,t;
			double[] x1=new double[130];
			double[] y1=new double[130];
			double[] x2=new double[130];
			double[] y2=new double[130];
			x=p1.X;y=p1.Y;
			bx=p2.X;by=p2.Y;
			pi=3.14159;nn=25;i=0;

			for(a=0;a<=2*pi;a+=pi/60)
			{
				r=120;
				i++;
				x1[i]=r*Math.Cos(a);
				y1[i]=-r*Math.Sin(a);
				d=r*(1+0.5*Math.Sin(12*a));
				t=d*(1/2+0.5*Math.Sin(4*a));
				x2[i]=t*Math.Cos(a);
				y2[i]=-t*Math.Sin(a);
			}

			for(n=0;n<=nn;n++)
			{
				for(i=1;i<=120;i++)
				{
					x=(int)((x2[i]-x1[i])/Math.Log(nn+1)*Math.Log(n+1)+x1[i]);
					y=(int)((y2[i]-y1[i])/Math.Log(nn+1)*Math.Log(n+1)+y1[i]);
					x+=200;
					y+=160;
					if(i==1)
					{
						p1.X=x;p1.Y=y;
					}
					else
					{
						bx=x;by=y;
						p2.X=bx;p2.Y=by;
						g.DrawLine(pen1,p1,p2);
						p1=p2;
					}
				}
				p1.X=x;p1.Y=y;
				g.DrawLine(pen1,p2,p1);
			}
		}



		private void menuItem10_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,l,x0,y0,x1,x,y1,y,x2,y2;
			double pi,a,c,r,th,d,t;
			pi=3.14159;
			x=640;
			y=300;
			l=280;
			x0=320;
			y0=600;
			c=pi/3.0;
			r=x/9.0;
			for(px=x/16;px<=x;px+=x/8)
			{
				for(py=y/8;py<=7*y/8;py+=y/4)
				{
					for(a=0;a<=2*pi+pi/60.0;a+=pi/64.0)
					{
						d=r*(0.8+0.2*Math.Sin(12*a));
						t=d*(0.5+0.5*Math.Sin(4*a));
						x1=(int)(t*Math.Cos(a)+px);
						y1=(int)(t*Math.Sin(a)+py);
						th=c*(x-x1)/640.0+c;
						x2=(int)((l+y1)*Math.Cos(th)+x0);
						y2=(int)(-(l+y1)*Math.Sin(th)+y0);
						if(a==0)
						{
							p1.X=x2;p1.Y=y2;
						}
						else
						{
							p2.X=x2;p2.Y=y2;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
				}
			}
		}

		private void menuItem12_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,l,x1,y1,x2,y2,x,w;
			float pi;
			double a,th,d;
			pi=3.14159f;
			x=660;
			l=100;
			w=150;
			for(px=w/2;px<=7*w+w/2;px+=w)
			{
				for(a=0;a<=2*pi;a+=pi/60.0)
				{
					d=60*Math.Sin(6*a);
					x1=(int)(d*Math.Cos(a)+16*Math.Sin(2*a))+px;
					y1=(int)(d*Math.Sin(a)-16*Math.Cos(2*a));
					th=2*pi*(x-x1)/1200.0f;
					x2=(int)((l+y1)*Math.Cos(th))+240;
					y2=(int)((l+y1)*Math.Sin(th))+200;
					if(a==0)
					{
						p1.X=x2;p1.Y=y2;
					}
					else
					{
						p2.X=x2;p2.Y=y2;
						g.DrawLine(pen1,p1,p2);
						p1=p2;
					}
				}
			}
		}

		private void menuItem15_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,l,x1,y1,x2,y2,x,w,j,i;
			int[] x3=new int[300];
			int[] y3=new int[300];
			float pi;
			double a,th,d;
			pi=3.14159f;
			x=660;
			l=0;
			w=160;
			j=0;
			for(a=0;a<=2*pi;a+=pi/80.0)
			{
				j++;
				d=42*Math.Sin(4*a);
				x3[j]=(int)(d*Math.Cos(a)+16*Math.Sin(2*a));
				y3[j]=(int)(d*Math.Sin(a)-16*Math.Cos(2*a));
			}
			for(py=w/4;py<=3*w/4;py+=w/2)
			{
				for(px=x/16;px<=15*x/16;px+=x/8)
				{
					for(i=1;i<=j;i++)
					{
						x1=x3[i]+px;
						y1=y3[i]+py;
						th=2*pi*(x-x1)/x;
						x2=(int)((l+y1)*Math.Cos(th)+240);
						y2=(int)((l+y1)*Math.Sin(th)+200);
						if(i==1)
						{
							p1.X=x2;p1.Y=y2;
						}
						else
						{
							p2.X=x2;p2.Y=y2;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
				}
			}
		}

		private void menuItem16_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,l,x1,y1,x2,y2,x,w,j,i;
			int[] x3=new int[300];
			int[] y3=new int[300];
			float pi;
			double a,th,d,t;
			pi=3.14159f;
			x=660;
			l=0;
			w=160;
			j=0;
			for(a=0;a<=2*pi;a+=pi/120.0)
			{
				j++;
				d=32*(0.8+0.2*Math.Sin(18*a));
				t=d*(1.0+Math.Sin(6*a));
				x3[j]=(int)(t*Math.Cos(a)*1.2);
				y3[j]=(int)(t*Math.Sin(a));
			}
			for(py=w/4;py<=3*w/4;py+=w/2)
			{
				for(px=x/16;px<=15*x/16;px+=x/8)
				{
					for(i=1;i<=j;i++)
					{
						x1=x3[i]+px;
						y1=y3[i]+py;
						th=2*pi*(x-x1)/x;
						x2=(int)((l+y1)*Math.Cos(th)+240);
						y2=(int)((l+y1)*Math.Sin(th)+200);
						if(i==1)
						{
							p1.X=x2;p1.Y=y2;
						}
						else
						{
							p2.X=x2;p2.Y=y2;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
				}
			}
		}

		private void menuItem17_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,l,x1,y1,x2,y2,x,w,j,i;
			int[] x3=new int[300];
			int[] y3=new int[300];
			float pi;
			double a,th,d,t;
			pi=3.14159f;
			x=660;
			l=0;
			w=160;
			j=0;
			for(a=0;a<=2*pi;a+=pi/120.0)
			{
				j++;
				d=40*Math.Sqrt(Math.Abs(Math.Cos(3*a)));
				t=d+10*Math.Sqrt(Math.Abs(Math.Cos(9*a)));
				x3[j]=(int)(t*Math.Cos(a)*1.2);
				y3[j]=(int)(t*Math.Sin(a));
			}
			for(py=w/4;py<=3*w/4;py+=w/2)
			{
				for(px=x/16;px<=15*x/16;px+=x/8)
				{
					for(i=1;i<=j;i++)
					{
						x1=x3[i]+px;
						y1=y3[i]+py;
						th=2*pi*(x-x1)/x;
						x2=(int)((l+y1)*Math.Cos(th)+240);
						y2=(int)((l+y1)*Math.Sin(th)+200);
						if(i==1)
						{
							p1.X=x2;p1.Y=y2;
						}
						else
						{
							p2.X=x2;p2.Y=y2;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
				}
			}
		}

		private void menuItem18_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,l,x1,y1,x2,y2,x,w,j,i;
			int[] x3=new int[300];
			int[] y3=new int[300];
			float pi;
			double a,th,d;
			pi=3.14159f;
			x=660;
			l=0;
			w=160;
			j=0;
			for(a=0;a<=2*pi;a+=pi/120.0)
			{
				j++;
				d=19.0*Math.Sin(4*(a+pi/8));
				x3[j]=(int)(d*Math.Cos(a)+49.0*Math.Cos(a)*Math.Cos(a)*Math.Cos(a));
				y3[j]=(int)(d*Math.Sin(a)+49.0*Math.Sin(a)*Math.Sin(a)*Math.Sin(a));
			}
			for(py=w/4;py<=3*w/4;py+=w/2)
			{
				for(px=x/16;px<=15*x/16;px+=x/8)
				{
					for(i=1;i<=j;i++)
					{
						x1=x3[i]+px;
						y1=y3[i]+py;
						th=2*pi*(x-x1)/x;
						x2=(int)((l+y1)*Math.Cos(th)+240);
						y2=(int)((l+y1)*Math.Sin(th)+200);
						if(i==1)
						{
							p1.X=x2;p1.Y=y2;
						}
						else
						{
							p2.X=x2;p2.Y=y2;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
				}
			}
		}

		private void menuItem14_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,l,x1,y1,x2,y2,x,w,j,i;
			int[] x3=new int[300];
			int[] y3=new int[300];
			float pi;
			double a,th,d;
			pi=3.14159f;
			x=660;
			l=0;
			w=160;
			j=0;
			for(a=0;a<=2*pi;a+=pi/80.0)
			{
				j++;
				d=42*Math.Sin(4*a);
				x3[j]=(int)(d*Math.Cos(a)+16*Math.Sin(2*a));
				y3[j]=(int)(d*Math.Sin(a)-16*Math.Cos(2*a));
			}
			for(px=w/6;px<=x-w/6;px+=x/10)
			{
				for(py=w/6;py<=5*w/6;py+=w/3)
				{
					for(i=1;i<=j;i++)
					{
						x1=x3[i]+px;
						y1=y3[i]+py;
						th=2*pi*(x-x1)/x;
						x2=(int)((l+y1)*Math.Cos(th)+240);
						y2=(int)((l+y1)*Math.Sin(th)+200);
						if(i==1)
						{
							p1.X=x2;p1.Y=y2;
						}
						else
						{
							p2.X=x2;p2.Y=y2;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
				}
			}
		}

		private void menuItem20_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,x,y,k,un,j,i,s,uv;
			double[] x3=new double[300];
			double[] y3=new double[300];
			double sq,y1,r;
			double x1;
			double sc,bt,m,th,pi,a,l,d,dd;
			un=10;
			uv=360/un;
			k=uv/2;
			sc=uv/100.0;
			s=0;
			j=0;pi=3.14159;r=150.0;
			for(a=0;a<=2*pi;a+=pi/60)
			{
				j++;
				d=90*(0.8+0.2*Math.Sin(12*a));
				dd=d*(0.5+0.5*Math.Sin(4*a));
				y3[j]=dd*Math.Cos(a);
				x3[j]=dd*Math.Sin(a);
			}
			for(px=-180+k;px<=180-k;px+=uv)
			{
				for(py=-180+k;py<=180-k;py+=uv)
					for(i=1;i<=j;i++)
					{
						x1=x3[i]*sc+px;
						y1=y3[i]*sc+py;
						sq=x1*x1+y1*y1;
						if(sq<(r*r))
						{
							if(x1<0)s=1;
							if(x1==0)x1=0.1;
							l=Math.Sqrt(sq);
							bt=2*Math.Atan2(l,r);
							th=Math.Atan2(y1,x1);
							m=r*Math.Sin(bt);
							x=(int)(s*m*Math.Cos(th));
							y=(int)(s*m*Math.Sin(th));
						}
						else
						{
							x=(int)x1;
							y=(int)y1;
						}
						x=260+x;
						y=y+200;
						if(i==1)
						{
							p1.X=x;
							p1.Y=y;
						}
						else
						{
							p2.X=x;
							p2.Y=y;
							g.DrawLine(pen1,p1,p2);
							p1=p2;
						}
					}
			}
		}

		private void menuItem23_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int px,py,x2,y2,j,i,r;
			double[] x3=new double[300];
			double[] y3=new double[300];
			double pi,a,d,t,x,y;
			pi=3.14159;
			r=45;
			j=0;
			for(a=0;a<=2*pi;a+=pi/60)
			{
				j++;
				d=r*(1+0.2*Math.Sin(12*a));
				t=d*(0.5+0.5*Math.Sin(4*a));
				y3[j]=t*Math.Cos(a);
				x3[j]=t*Math.Sin(a);
				for(px=170;px<=470;px+=60)
				{
					for(py=50;py<=350;py+=60)
					{
						for(i=1;i<=j;i++)
						{
							x=x3[i]+px;
							y=y3[i]+py;
							x2=260-(int)(180*Math.Cos(pi*(x-140)/360));
							y2=200+(int)(180*Math.Cos(pi*(y-20)/360));
							if(i==1)
							{
								p1.X=x2;
								p1.Y=y2;
							}
							else
							{
								p2.X=x2;
								p2.Y=y2;
								g.DrawLine(pen1,p1,p2);
								p1=p2;
							}
						}
					}
				}
			}
		}

		private void menuItem24_Click(object sender, System.EventArgs e)
		{
			Graphics g=this.CreateGraphics();
			Pen pen1=new Pen(Color.Red);
			g.Clear(this.BackColor);
			int x,y,l;
			double px,py,x0,y0,x2,a,aa,pi,d,m;
			pi=3.14159;
			l=180;
			m=2*l/Math.Sqrt(3.0);
			d=l/4*1.3;

			for(aa=0;aa<=2*pi;aa+=pi/3)
			{
				for(px=l/4;px<=3*l/4;px+=l/2)
				{
					for(py=l/4;py<=3*l/4;py+=l/2)
						for(a=0;a<=2*pi+pi/60;a+=pi/48)
						{
							x0=d*(0.5+0.5*Math.Sin(6*a))*Math.Cos(a)+px;
							y0=d*(0.5+0.5*Math.Sin(6*a))*Math.Sin(a)+py;
							x2=x0*y0*m/(l*l)+(l-y0)*m/l/2-m/2;
							x=(int)(x2*Math.Cos(aa)-y0*Math.Sin(aa))+260;
							y=(int)(x2*Math.Sin(aa)+y0*Math.Cos(aa))+200;
							if(a==0)
							{
								p1.X=x;
								p1.Y=y;
							}
							else
							{
								p2.X=x;
								p2.Y=y;
								g.DrawLine(pen1,p1,p2);
								p1=p2;
							}
						}
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -