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

📄 form1.cs

📁 这是《C#图形程序设计》这本书的源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
				a[i]=a[i]-b[i]*c[i-1];
				c[i]=c[i]/a[i];
			}
			qx[1]=dx[1]/a[1];
			qy[1]=dy[1]/a[1];
			for(i=2;i<=n-1;i++)
			{
				qx[i]=(dx[i]-b[i]*qx[i-1])/a[i];
				qy[i]=(dy[i]-b[i]*qy[i-1])/a[i];
			}
			px[n-1]=qx[n-1];
			py[n-1]=qy[n-1];
			for(i=n-2;i>=1;i--)
			{
				px[i]=qx[i]-c[i]*px[i+1];
				py[i]=qy[i]-c[i]*py[i+1];
			}
			p0:
				for(i=0;i<=n-1;i++)
				{
					bx3=(3*(x[i+1]-x[i])/tt[i+1]-2*px[i]-px[i+1])/tt[i+1];
					bx4=((2*(x[i]-x[i+1])/tt[i+1]+px[i]+px[i+1])/tt[i+1])/tt[i+1];
					by3=(3*(y[i+1]-y[i])/tt[i+1]-2*py[i]-py[i+1])/tt[i+1];
					by4=((2*(y[i]-y[i+1])/tt[i+1]+py[i]+py[i+1])/tt[i+1])/tt[i+1];
					t=0;
					do
					{
						t=t+es;
						cx=(int)(x[i]+(px[i]+(bx3+bx4*t)*t)*t);
						cy=(int)(y[i]+(py[i]+(by3+by4*t)*t)*t);
						p4.X=cx;
						p4.Y=cy;
						g.DrawLine(pen1,p3,p4);
						p3=p4;
					}while(t<tt[i+1]);
				}
		}

		private void menuItem8_Click(object sender, System.EventArgs e)
		{
			float[] coeff_x=new float[4];
			float[] coeff_y=new float[4];
			float[] points_x=new float[43234+1000];
			float[] points_y=new float[43234+1000];
			PointF p=new Point();
			PointF p1=new Point();
			int degree,i,j;
			degree=1;
            Class1 c=new Class1();
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);

			double delt;
			g.Clear(pictureBox1.BackColor);
			coeff_x[0]=10;
			coeff_x[1]=30;

			coeff_y[0]=10;
			coeff_y[1]=5;

			for(j=0;j<=degree;j++)
			{
				if(j==0)
				{
					p.X=110;
					p.Y=110;
				}
				p1.X=10+10*coeff_x[j];
				p1.Y=10+10*coeff_y[j];
				g.DrawLine(pen1,p,p1);
				p=p1;
			}
			delt=(float)(1.0/43234);
			double t=0.0;
			for(i=0;i<=43234;i++)
			{
				if(i==0)
				{
					p.X=110;
					p.Y=110;
				}
				t=t+delt;
				p1.X=(int)(10+10*c.ThreeBezier(degree,coeff_x,t));
				p1.Y=(int)(10+10*c.ThreeBezier(degree,coeff_y,t));
				pen1.Color=Color.Red;
				g.DrawLine(pen1,p,p1);
				p=p1;
			}
		}

		private void menuItem9_Click(object sender, System.EventArgs e)
		{
			float[] coeff_x=new float[4];
			float[] coeff_y=new float[4];
			float[] points_x=new float[43234+1000];
			float[] points_y=new float[43234+1000];
			PointF p=new Point();
			PointF p1=new Point();
			int degree,i,j;
			degree=2;
			Class1 c=new Class1();
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);

			double delt;
			g.Clear(pictureBox1.BackColor);
			coeff_x[0]=10;
			coeff_x[1]=30;
			coeff_x[2]=40;

			coeff_y[0]=10;
			coeff_y[1]=5;
			coeff_y[2]=13;

			for(j=0;j<=degree;j++)
			{
				if(j==0)
				{
					p.X=110;
					p.Y=110;
				}
				p1.X=10+10*coeff_x[j];
				p1.Y=10+10*coeff_y[j];
				g.DrawLine(pen1,p,p1);
				p=p1;
			}
			delt=(float)(1.0/43234);
			double t=0.0;
			for(i=0;i<=43234;i++)
			{
				if(i==0)
				{
					p.X=110;
					p.Y=110;
				}
				t=t+delt;
				p1.X=(int)(10+10*c.ThreeBezier(degree,coeff_x,t));
				p1.Y=(int)(10+10*c.ThreeBezier(degree,coeff_y,t));
				pen1.Color=Color.Red;
				g.DrawLine(pen1,p,p1);
				p=p1;
			}
		}

		private void menuItem10_Click(object sender, System.EventArgs e)
		{
			float[] coeff_x=new float[4];
			float[] coeff_y=new float[4];
			float[] points_x=new float[43234+1000];
			float[] points_y=new float[43234+1000];
			PointF p=new Point();
			PointF p1=new Point();
			int degree,i,j;
			degree=3;
			Class1 c=new Class1();
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);

			double delt;
			g.Clear(pictureBox1.BackColor);
			coeff_x[0]=10;
			coeff_x[1]=30;
			coeff_x[2]=40;
			coeff_x[3]=40;

			coeff_y[0]=10;
			coeff_y[1]=5;
			coeff_y[2]=13;
			coeff_y[3]=30;

			for(j=0;j<=degree;j++)
			{
				if(j==0)
				{
					p.X=110;
					p.Y=110;
				}
				p1.X=10+10*coeff_x[j];
				p1.Y=10+10*coeff_y[j];
				g.DrawLine(pen1,p,p1);
				p=p1;
			}
			delt=(float)(1.0/43234);
			double t=0.0;
			for(i=0;i<=43234;i++)
			{
				if(i==0)
				{
					p.X=110;
					p.Y=110;
				}
				t=t+delt;
				p1.X=(int)(10+10*c.ThreeBezier(degree,coeff_x,t));
				p1.Y=(int)(10+10*c.ThreeBezier(degree,coeff_y,t));
				pen1.Color=Color.Red;
				g.DrawLine(pen1,p,p1);
				p=p1;
			}
		}

		private void menuItem11_Click(object sender, System.EventArgs e)
		{
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);
			g.Clear(pictureBox1.BackColor);
			int cx,cy,i,n,xa,ya;
			int[] x=new int[3]{30,120,240};
			int[] y=new int[3]{40,180,40};
			n=9;
			double t,t2,a0,a1,a2,b0,b1,b2,dt;
			cx=10;
			cy=200;

			a0=x[0];a1=2*(x[1]-x[0]);
			a2=x[2]-2*x[1]+x[0];

			b0=y[0];b1=2*(y[1]-y[0]);
			b2=y[2]-2*y[1]+y[0];
			dt=1.0/n;
			for(i=0;i<=n;i++)
			{
				t=i*dt;
				t2=t*t;
				xa=(int)(a0+a1*t+a2*t2+cx);
				ya=(int)(cy-(b0+b1*t+b2*t2));
				if(i==0)
				{
					p1.X=xa;
					p1.Y=ya;
				}
				else
				{
					p2.X=xa;
					p2.Y=ya;
					g.DrawLine(pen1,p1,p2);
					p1=p2;
				}
			}
		}

		private void menuItem12_Click(object sender, System.EventArgs e)
		{
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);
			g.Clear(pictureBox1.BackColor);
			int cx,cy,i,n,xa,ya;
			n=9;
			double t,t2,t3,a0,a1,a2,a3,b0,b1,b2,b3,dt;
			cx=10;
			cy=160;
			int[] x=new int[4]{30,100,180,280};
			int[] y=new int[4]{30,110,180,30};

			a0=x[0];
			a1=-3*(x[0]-x[1]);
			a2=3*x[0]-6*x[1]+3*x[2];
			a3=-x[0]+3*x[1]-3*x[2]+x[3];

			b0=y[0];
			b1=-3*(y[0]-y[1]);
			b2=3*y[0]-6*y[1]+3*y[2];
			b3=-y[0]+3*y[1]-3*y[2]+y[3];

			dt=1.0/n;
			for(i=0;i<=n;i++)
			{
				t=i*dt;
				t2=t*t;
				t3=t2*t;
				xa=(int)(a0+a1*t+a2*t2+a3*t3+cx);
				ya=(int)(cy-(b0+b1*t+b2*t2+b3*t3));
				if(i==0)
				{
					p1.X=xa;
					p1.Y=ya;
				}
				else
				{
					p2.X=xa;
					p2.Y=ya;
					g.DrawLine(pen1,p1,p2);
					p1=p2;
				}
			}
		}

		private void menuItem15_Click(object sender, System.EventArgs e)
		{
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);
			g.Clear(pictureBox1.BackColor);
			int cx,cy,i,n,xa,ya;
			n=9;
			double t,t2,a0,a1,a2,b0,b1,b2,dt;
			cx=10;
			cy=160;
			int[] x=new int[3]{30,180,240};
			int[] y=new int[3]{20,180,20};
			a0=(x[0]+x[2])/2;
			a1=x[1]-x[0];
			a2=(x[2]-2*x[1]+x[0])/2;
			b0=(y[0]+y[1])/2;
			b1=y[1]-y[0];
			b2=(y[2]-2*y[1]+y[0])/2;
			dt=1.0/n;
			for(i=0;i<=n;i++)
			{
				t=i*dt;
				t2=t*t;
				xa=(int)(a0+a1*t+a2*t2+cx);
				ya=(int)(cy-(b0+b1*t+b2*t2));
				if(i==0)
				{
					p1.X=xa;
					p1.Y=ya;
				}
				else
				{
					p2.X=xa;
					p2.Y=ya;
					g.DrawLine(pen1,p1,p2);
					p1=p2;
				}
			}
		}

		private void menuItem16_Click(object sender, System.EventArgs e)
		{
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Black);
			g.Clear(pictureBox1.BackColor);
			int cx,cy,i,n,xa,ya;
			n=9;
			double t,t2,t3,a0,a1,a2,a3,b0,b1,b2,b3,dt;
			cx=10;
			cy=200;
			int[] x=new int[4]{30,160,240,320};
			int[] y=new int[4]{10,180,180,10};
			a0=(x[0]+4*x[1]+x[2])/6;
			a1=-(x[0]-x[2])/2;
			a2=(x[2]-2*x[1]+x[0])/2;
			a3=-(x[0]-3*x[1]+3*x[2]-x[3])/6;

			b0=(y[0]+4*y[1]+y[2])/6;
			b1=-(y[0]-y[2])/2;
			b2=(y[2]-2*y[1]+y[0])/2;
			b3=-(y[0]-3*y[1]+3*y[2]-y[3])/6;

			dt=1.0/n;
			for(i=0;i<=n;i++)
			{
				t=i*dt;
				t2=t*t;
				t3=t2*t;
				xa=(int)(a0+a1*t+a2*t2+a3*t3+cx);
				ya=(int)(cy-(b0+b1*t+b2*t2+b3*t3));
				if(i==0)
				{
					p1.X=xa;
					p1.Y=ya;
				}
				else
				{
					p2.X=xa;
					p2.Y=ya;
					g.DrawLine(pen1,p1,p2);
					p1=p2;
				}
			}
		}

		private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			Graphics g=pictureBox1.CreateGraphics();
			Pen pen1=new Pen(Color.Blue,1);
			PointF pa=new Point();
			PointF pb=new Point();
			label1.Text="X的坐标"+e.X.ToString();
			label2.Text="Y的坐标"+e.Y.ToString();
			if(num==0)
			{
				g.Clear(pictureBox1.BackColor);
				p.X=e.X;
				p.Y=e.Y;
				g.DrawEllipse(pen1,e.X,e.Y,2,2);
			}
			if(num==1)
			{
				p1.X=e.X;
				p1.Y=e.Y;
				g.DrawEllipse(pen1,e.X,e.Y,2,2);
			}
			if(num==2)
			{
				p2.X=e.X;
				p2.Y=e.Y;
				g.DrawEllipse(pen1,e.X,e.Y,2,2);
			}
			if(num==3)
			{
				p3.X=e.X;
				p3.Y=e.Y;
				g.DrawEllipse(pen1,e.X,e.Y,2,2);
				num=4;
			}
			if(num==4)
			{
				float[] coeff_x=new float[4];
				float[] coeff_y=new float[4];
				float[] points_x=new float[43234+1000];
				float[] points_y=new float[43234+1000];
				int degree,i,j;
				degree=3;
				Class1 c=new Class1();
				double delt;
				coeff_x[0]=p.X;
				coeff_x[1]=p1.X;
				coeff_x[2]=p2.X;
				coeff_x[3]=p3.X;

				coeff_y[0]=p.Y;
				coeff_y[1]=p1.Y;
				coeff_y[2]=p2.Y;
				coeff_y[3]=p3.Y;

				for(j=0;j<=3;j++)
				{
					if(j==0)
					{
						pa.X=p.X;
						pa.Y=p.Y;
					}
					pb.X=coeff_x[j];
					pb.Y=coeff_y[j];
					pen1.Color=Color.Black;
					g.DrawLine(pen1,pa,pb);
					pa=pb;
				}
				delt=(float)(1.0/43234);
				double t=0.0;
				for(i=0;i<=43234;i++)
				{
					if(i==0)
					{
						pa.X=p.X;
						pa.Y=p.Y;
					}
					t=t+delt;
					pb.X=(int)(c.ThreeBezier(degree,coeff_x,t));
					pb.Y=(int)(c.ThreeBezier(degree,coeff_y,t));
					pen1.Color=Color.Red;
					g.DrawLine(pen1,pa,pb);
					pa=pb;
				}
			}
			num=num+1;
			if(num>=4)num=0;
		}
	}
}

⌨️ 快捷键说明

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