コード例 #1
0
 private static void RenderObject(Context ctx, AstronomicalObject obj,
                                  double xOffset, double yOffset)
 {
     ctx.SetSourceRGB(0.769, 0.282, 0.295);
     ctx.Arc(xOffset + obj.X, yOffset + obj.Y, obj.Diameter, 0, 2 * PI);
     ctx.ClosePath();
     ctx.Fill();
 }
コード例 #2
0
        public override void Update(long deltaTime)
        {
            for (var i = 0; i < _planets.Length; i++)
            {
                _planets[i] = UpdateObject(_planets[i], _sun);
            }

            _moon = UpdateObject(_moon, _planets[2]);
        }
コード例 #3
0
        private static AstronomicalObject UpdateObject(
            AstronomicalObject target,
            AstronomicalObject reference)
        {
            target.Phase += target.RotationSpeed;
            if (target.Phase >= 360)
            {
                target.Phase = 0;
            }

            target.X = reference.X + target.Distance * Cos(PI * target.Phase / 180);
            target.Y = reference.Y + target.Distance * Sin(PI * target.Phase / 180);
            return(target);
        }
コード例 #4
0
        public override void Init(Dictionary <string, string> model)
        {
            _sun = new AstronomicalObject
            {
                Name     = "Sun",
                Diameter = 1392684
            };
            _moon = new AstronomicalObject
            {
                Name          = "Moon",
                Distance      = 20,
                Diameter      = 4,
                RotationSpeed = 2.5
            };

            var mercury = new AstronomicalObject
            {
                Name          = "Mercury",
                Distance      = 57909000,
                Diameter      = 4879.4,
                RotationSpeed = 4.5
            };
            var venus = new AstronomicalObject
            {
                Name          = "Venus",
                Distance      = 109160000,
                Diameter      = 12103.6,
                RotationSpeed = 1.9
            };
            var earth = new AstronomicalObject
            {
                Name          = "Earth",
                Distance      = 149600000,
                Diameter      = 12756.3,
                RotationSpeed = 1
            };
            var mars = new AstronomicalObject
            {
                Name          = "Mars",
                Distance      = 227990000,
                Diameter      = 6792.4,
                RotationSpeed = 1.0 / 2
            };
            var jupiter = new AstronomicalObject
            {
                Name          = "Jupiter",
                Distance      = 778360000,
                Diameter      = 142984,
                RotationSpeed = 1.0 / 11
            };
            var saturn = new AstronomicalObject
            {
                Name          = "Saturn",
                Distance      = 1433500000,
                Diameter      = 120536,
                RotationSpeed = 1.0 / 13
            };
            var uranus = new AstronomicalObject
            {
                Name          = "Uranus",
                Distance      = 2872400000,
                Diameter      = 51118,
                RotationSpeed = 1.0 / 15
            };
            var neptune = new AstronomicalObject
            {
                Name          = "Neptune",
                Distance      = 4498400000,
                Diameter      = 49528,
                RotationSpeed = 1.0 / 18
            };

            _planets = new []
            {
                mercury, venus, earth, mars, jupiter, saturn, uranus, neptune
            };

            for (var i = 0; i < _planets.Length; i++)
            {
                var planet = _planets[i];
                planet.Distance /= 1000000;
                planet.X         = planet.Distance;
                planet.Diameter /= 1000;
                _planets[i]      = planet;
            }

            _sun.Diameter /= 40000;
            _moon.X        = earth.X + _moon.Distance;
        }
コード例 #5
0
 private static string AstrObjToString(AstronomicalObject obj)
 {
     return(obj.Name + ", " + obj.X + ", " + obj.Y);
 }