Changeset 9285 for 2017/30/MikkoH/Sq/Sq/Sq/Sq.cs
 Timestamp:
 20170731 18:53:44 (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

2017/30/MikkoH/Sq/Sq/Sq/Sq.cs
r9284 r9285 5 5 public class Sq : PhysicsGame 6 6 { 7 List<Vector> ps = new List<Vector>(), crc = new List<Vector>();8 double x, y, z, a, fac = Math.Pow(2, 15), rad = 50, radc = 0.01, mag = 4;7 List<Vector> ps, crc; 8 double rad = 50, radc = 0.01, mag = 2; 9 9 10 10 public override void Begin() … … 13 13 Mouse.IsCursorVisible = true; 14 14 Level.Background.Color = Color.Black; 15 16 for (int i = 300; i <= 300; i += 10) ps.Add(new Vector(300, i));17 for (int i = 300; i <= 300; i += 10) ps.Add(new Vector(i, 300));18 for (int i = 300; i >= 300; i = 10) ps.Add(new Vector(300, i));19 for (int i = 300; i >= 300; i = 10) ps.Add(new Vector(i, 300));20 15 21 for (int i = 0; i <= 150; i++)22 crc.Add(new Vector(Math.Sin(i) * rad, Math.Cos(i) * rad));16 ps = CreateSquare(100, 10); 17 crc = CreateCircle(50, 150); 23 18 } 24 19 20 // s = length of side, d = distance between pts 21 List<Vector> CreateSquare(int s, int d) 22 { 23 List<Vector> sq = new List<Vector>(); 24 for (int i = s; i <= s; i += d) sq.Add(new Vector(s, i)); 25 for (int i = s; i <= s; i += d) sq.Add(new Vector(i, s)); 26 for (int i = s; i >= s; i = d) sq.Add(new Vector(s, i)); 27 for (int i = s; i >= s; i = d) sq.Add(new Vector(i, s)); 28 return sq; 29 } 30 31 // rad = starting radius, n = number of pts 32 List<Vector> CreateCircle(int rad, int n) 33 { 34 List<Vector> crc = new List<Vector>(); 35 for (int i = 0; i <= n; i++) 36 crc.Add(new Vector(Math.Sin(i) * rad, Math.Cos(i) * rad)); 37 return crc; 38 } 39 40 // rotates any shape clockwise or anti if reversed 41 void Rotate(List<Vector> vs, bool reverse = false) 42 { 43 double d = Time.SinceLastUpdate.TotalSeconds; 44 if (reverse) d = d; 45 for (int i = 0; i < vs.Count; i++) 46 vs[i] = new Vector(vs[i].X * Math.Cos(d)  vs[i].Y * Math.Sin(d), 47 vs[i].X * Math.Sin(d) + vs[i].Y * Math.Cos(d)); 48 } 49 50 // does everything 25 51 protected override void Paint(Canvas c) 26 52 { 27 53 c.BrushColor = Color.Red; 28 54 55 // draws the square and squeezes it 29 56 for (int i = 0; i < ps.Count; i++) 30 57 { 31 58 c.DrawLine(ps[i % ps.Count], ps[(i + ps.Count / 4) % ps.Count]); 32 ps[i] = Vector.FromLengthAndAngle(ps[i].Magnitude + mag, ps[i].Angle);59 //ps[i] = Vector.FromLengthAndAngle(ps[i].Magnitude + mag, ps[i].Angle); 33 60 if (ps[i].Magnitude < 1  ps[i].Magnitude > 200) mag = mag; 34 } 61 ps[i] += new Vector(5, 5); 62 } 35 63 36 64 c.BrushColor = Color.Blue; 37 65 66 // draws the circle and squeezes it 38 67 for (int i = 0; i < crc.Count; i++) 39 68 { … … 48 77 base.Paint(c); 49 78 } 50 51 void Rotate(List<Vector> vs, bool reverse = false)52 {53 double d = Time.SinceLastUpdate.TotalSeconds;54 if (reverse) d = d;55 for (int i = 0; i < vs.Count; i++)56 vs[i] = new Vector(vs[i].X * Math.Cos(d)  vs[i].Y * Math.Sin(d),57 vs[i].X * Math.Sin(d) + vs[i].Y * Math.Cos(d));58 }59 79 }
Note: See TracChangeset
for help on using the changeset viewer.