Click here to Skip to main content
13,143,424 members (31,087 online)
Click here to Skip to main content
Articles » Multimedia » GDI+ » General » Downloads

Stats

118.3K views
2.9K downloads
173 bookmarked
Posted 21 Jul 2007

Fun With Gravity

, 28 Jul 2008
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)

Share

About the Author

BoneSoft
Software Developer (Senior) BoneSoft Software
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation (No members)



You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 28 Jul 2008
Article Copyright 2007 by BoneSoft
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid