Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / XML

Fun With Gravity

Rate me:
Please Sign up or sign in to vote.
4.93/5 (77 votes)
28 Jul 2008CPOL4 min read 153.3K   3.5K   173  
A gravity simulation particle system
using System;
using System.Drawing;
using System.Collections;

namespace ParticleSwarm {
	public abstract class ParticleSystem {
		protected bool running = false;
		protected bool trace = false;
		protected bool showVel = false;
		protected bool showVelBox = false;
		protected bool showAcc = false;
		protected bool showAccBox = false;
		protected bool detectCol = true;
		protected Color backColor = Color.White;
		protected Color fade;
		protected ArrayList particles = new ArrayList();

		public ParticleSystem() {
			fade = Color.FromArgb(10, backColor.R, backColor.G, backColor.B);
		}

		public void Start(Graphics g, Rectangle bounds) {
			running = true;
			Draw(g, bounds);
		}

		public void Stop() {
			running = false;
		}

		public abstract void Draw(Graphics g, Rectangle bounds);
		
		public bool IsRunning {
			get { return this.running; }
			set { this.running = value; }
		}

		public bool Trace {
			get { return trace; }
			set { trace = value; }
		}

		public bool ShowVelocityVectors {
			get { return showVel; }
			set { showVel = value; }
		}

		public bool ShowVelocityBox {
			get { return showVelBox; }
			set { showVelBox = value; }
		}

		public bool ShowAccelerationVectors {
			get { return showAcc; }
			set { showAcc = value; }
		}

		public bool ShowAccelerationBox {
			get { return showAccBox; }
			set { showAccBox = value; }
		}

		public bool DetectCollisions {
			get { return detectCol; }
			set { detectCol = value; }
		}

		public Color BackgroundColor {
			get { return backColor; }
			set {
				backColor = value;
				trace = false;
				System.Windows.Forms.Application.DoEvents();
				trace = true;
			}
		}

		public ArrayList Particles {
			get { return this.particles; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) BoneSoft Software
United States United States
I've been in software development for more than a decade now. Originally with ASP 2.0 and VB6. I worked in Japan for a year doing Java. And have been with C# ever since.

In 2005 I founded BoneSoft Software where I sell a small number of developer tools.
This is a Organisation (No members)


Comments and Discussions