C#模拟小球碰撞(图形界面)

有小BUG的。

涉及动量守和定律,和能量守恒定律。

碰撞的时候,有粘连重叠问题。求大神纠正!小弟,找了好久都没找到!

运行效果截图

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Cool_Graphics01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Thread t = new Thread(new ThreadStart(CrossThreedFlush));
            t.IsBackground = true;
            t.Start();

        }
        private delegate void DelegateGDIMove(Circle[] cs);
        //线程占用主控制权,还没有与主线程发生异步
        private void CrossThreedFlush()
        {
            Color[] color = { Color.Red, Color.Blue, Color.Green, Color.DarkOrange, Color.Black, Color.DeepPink, Color.Purple, Color.Yellow };
            Circle[] cs = new Circle[3];
            /* for (int i = 0; i < 7; i++)
             {
                 cs[i] = new Circle();
                 cs[i].Center = new PointF(50*i+50, 50*i+50);
                 cs[i].Radius = 25;
                 cs[i].MoveSpeed = 3.0f;
                 cs[i].Weight = 15;
                 cs[i].Direct = 1.2 * i + 0.2;
                 cs[i].CircleColor = color[i];
             }
            */
            cs[0] = new Circle();
            cs[0].Center = new PointF(100, 50);
            cs[0].Radius = 20;
            cs[0].MoveSpeed = 3.0f;
            cs[0].Weight = cs[0].Radius*cs[0].Radius*cs[0].Radius;
            cs[0].Direct = 0;
            cs[0].CircleColor = Color.Red;

            cs[1] = new Circle();
            cs[1].Center = new PointF(50, 50);
            cs[1].Radius = 25;
            cs[1].MoveSpeed = 3.0f;
            cs[1].Weight = cs[1].Radius*cs[1].Radius*cs[1].Radius;
            cs[1].Direct = Math.PI * 0.25;
            cs[1].CircleColor = Color.Green;

            cs[2] = new Circle();
            cs[2].Center = new PointF(50, 120);
            cs[2].Radius = 30;
            cs[2].MoveSpeed = 3.0f;
            cs[2].Weight = cs[2].Radius * cs[2].Radius * cs[2].Radius;
            cs[2].Direct = Math.PI*0.5;
            cs[2].CircleColor = Color.Blue;
            /*
            cs[3] = new Circle();
            cs[3].Center = new PointF(200, 150);
            cs[3].Radius = 32;
            cs[3].MoveSpeed = 3.0f;
            cs[3
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值