using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ICanShowYouTheWorld { public partial class Form1 : Form { public class PlanetaryDisplay { public int theta; public int delta; public int x; public int y; public int r; public int offset; public string name; public Color color; public Label planet; public TrackBar speed; public Label slow; public Label fast; public int componentOffset; public PlanetaryDisplay(int _x, int _r, int _offset, string _name, Color _color, int _componentOffset, Control.ControlCollection _thisCollection) { planet = new System.Windows.Forms.Label(); planet.AutoSize = true; planet.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); planet.ForeColor = System.Drawing.Color.White; planet.Location = new System.Drawing.Point(12, 73 + componentOffset); planet.Name = "label2"; planet.Size = new System.Drawing.Size(135, 16); planet.TabIndex = 4; planet.Text = String.Format("Planet #{0}: {1}", _componentOffset + 1, _name); _thisCollection.Add(planet); speed = new System.Windows.Forms.TrackBar(); speed.Location = new System.Drawing.Point(16, 92 + componentOffset); speed.Maximum = 5; speed.Minimum = 1; speed.Size = new System.Drawing.Size(104, 45); speed.TabIndex = 5; speed.Value = 1; speed.Scroll += new System.EventHandler(this.speed_ValueChange); _thisCollection.Add(speed); slow = new System.Windows.Forms.Label(); slow.AutoSize = true; slow.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); slow.ForeColor = System.Drawing.Color.White; slow.Location = new System.Drawing.Point(12, 124 + componentOffset); slow.Name = "label3"; slow.Size = new System.Drawing.Size(34, 13); slow.TabIndex = 6; slow.Text = "Slow"; _thisCollection.Add(slow); fast = new System.Windows.Forms.Label(); fast.AutoSize = true; fast.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); fast.ForeColor = System.Drawing.Color.White; fast.Location = new System.Drawing.Point(86, 124 + componentOffset); fast.Name = "label4"; fast.Size = new System.Drawing.Size(31, 13); fast.TabIndex = 7; fast.Text = "Fast"; _thisCollection.Add(fast); } public void speed_ValueChange(object sender, EventArgs args) { this.delta = speed.Value; } } public static int SUN_R = 50; public static int THETA = 0; public static int DELTA = 1; public static int MERC_X; public static int MERC_Y; public static int MERC_R; public static int MERC_OFFSET; public static List solarSystem; public static System.Windows.Forms.Timer drawTimer; public Form1() { InitializeComponent(); solarSystem = new List(); MERC_R = 20; MERC_OFFSET = 100; MERC_X = (Canvas.Width / 2) - MERC_OFFSET; MERC_Y = Canvas.Height / 2; solarSystem.Add(new PlanetaryDisplay(MERC_X, MERC_R, MERC_OFFSET, "Mercury", Color.OrangeRed, 0, this.Controls)); drawTimer = new System.Windows.Forms.Timer(); drawTimer.Interval = 17; drawTimer.Tick += MovePlanets; drawTimer.Enabled = true; } public void MovePlanets(object sender, EventArgs args) { solarSystem[0].theta += solarSystem[0].delta; solarSystem[0].x = (Canvas.Width / 2) - ((int)(Math.Cos((double)(solarSystem[0].theta * (Math.PI / 180))) * solarSystem[0].offset)); solarSystem[0].y = (Canvas.Height / 2) - ((int)(Math.Sin((double)(solarSystem[0].theta * (Math.PI / 180))) * solarSystem[0].offset)); Canvas.Refresh(); } private void Canvas_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; using (Brush sunBrush = new SolidBrush(Color.Yellow)) { g.FillCircle(sunBrush, Canvas.Width / 2, Canvas.Height / 2, SUN_R); using (Font myFont = new Font(new FontFamily("Courier New"), 12)) { g.DrawString("Sun", myFont, sunBrush, Canvas.Width / 2 - 20, Canvas.Height / 2 - SUN_R - 20); } } using (Brush mercBrush = new SolidBrush(solarSystem[0].color)) { g.FillCircle(mercBrush, solarSystem[0].x, solarSystem[0].y, solarSystem[0].r); using (Font myFont = new Font(new FontFamily("Courier New"), 12)) { g.DrawString(solarSystem[0].name, myFont, mercBrush, solarSystem[0].x - 30, solarSystem[0].y - solarSystem[0].r - 20); } } } private void Planets_UpDown_ValueChanged(object sender, EventArgs e) { } private void Merc_TrackBar_Scroll(object sender, EventArgs e) { // foreach (PlanetaryDisplay i in collection) // if (i.speed == sender) // i.Delta = sender.Value; DELTA = Merc_TrackBar.Value; } } public static class GraphicsExtensions { public static void DrawCircle(this Graphics g, Pen pen, float centerX, float centerY, float radius) { g.DrawEllipse(pen, centerX - radius, centerY - radius, radius + radius, radius + radius); } public static void FillCircle(this Graphics g, Brush brush, float centerX, float centerY, float radius) { g.FillEllipse(brush, centerX - radius, centerY - radius, radius + radius, radius + radius); } } }