Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » GDI+ » General » Downloads
 
Add your own
alternative version

Fun With Gravity

, 28 Jul 2008 CPOL
A gravity simulation particle system.
using System;
using System.Drawing;

namespace ParticleSwarm {
	public class SingleParticle : ParticleSystem {
		private Particle p;

		public SingleParticle() {
			p = new Particle(new Vector(2, 40, 0), new Vector(0.4f, 0, 0), 2, 2, Color.Black);
			base.particles.Add(p);
		}
		public SingleParticle(Particle p) {
			this.p = p;
		}

		public override void Draw(Graphics g, Rectangle bounds) {
			if (p.Location.X >= bounds.Width - 6 || p.Location.Y >= bounds.Bottom - 6) {
				base.IsRunning = false;
			}
			Brush b = new SolidBrush(p.Color);
			Brush back = new SolidBrush(SystemColors.Control);

			float size = p.Size + p.Location.Z;
			if (size < 1) { size = 1; }
			if (!base.trace) { g.Clear(Color.White); }

			p.Velocity.Y += 0.001f;
			p.Velocity.X += 0.003f;
			//p.Velocity.Z += 0.0002f;

			p.Update();
			Pen pn = new Pen(b, 1f);
			g.DrawEllipse(pn, p.Location.X, p.Location.Y, size, size);
		}
	}
}

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
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.
Group type: Organisation (No members)



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