""" A simple animation showing the revolution of eight planets , use arcade Making of arcade game module , install Arcade Please use pip install arcade --user. A
simple animation to simulate the rotation of eight planets is made by using
= "lixingqiu" __date__ = "2019/3/8" import time import math import arcade
import random SCREEN_WIDTH = 1350 SCREEN_HEIGHT = 780 SCREEN_TITLE = "eight
planet planets " class Planet(arcade.Sprite): def
__init__(self,image,a,b,angle,speed): """image: Shape picture ,a：Long axis Long halfshaft ,b：semi-minor
axis Short halfshaft ,angle： Initial angle """ super().__init__(image) self.center_x = SCREEN_WIDTH / 2
self.center_y = SCREEN_HEIGHT / 2 self.direction = angle #
custom direction, Do not use the original attribute angle self.a = a self.b = b self.speed = speed def
update(self): """ Calculating Initial Coordinates Based on Elliptic Parametric
Equation""" self.direction = self.direction + 365 / self.speed self.direction =
self.direction % 360 x = SCREEN_WIDTH / 2 + self.a *
math.cos(math.radians(self.direction)) # Calculate the starting coordinates according to the elliptic parameter equation y = SCREEN_HEIGHT / 2 +
self.b * math.sin(math.radians(self.direction)) self.center_x = x self.center_y
= y super().update() class MyGame(arcade.Window): """ Inherited from window MyGame class . """ def
__init__(self, width, height, title): super().__init__(width, height, title)
Here is the setting of each object in the game """ self.planet_list = arcade.SpriteList() # New role list , For unified rendering #
Background role generation pass # Sun character generation pass # Planetary character generation pass for i in range(8): # generate 8 Planets angle =
self.angle_list[i] a,b = self.ab_list[i] image = self.planets_image[i] speed =
self.days[i] aplanet = Planet(image,a,b,angle,speed) # New planet
self.planet_list.append(aplanet) # Add to all planet list def update(self, x):
""" Update game logic per frame """ self.planet_list.update() self.sun.update_animation() def
on_draw(self): """ Render screen """ arcade.start_render() # Start drawing background self.background.draw()
self.sun.draw() self.planet_list.draw() def main(): """ Main method """ window
= MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) window.setup() arcade.run()
if __name__ == "__main__": main()

Technology
Daily Recommendation
views 5