日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python演示动画_Python八大行星漂亮动画演示-Go语言中文社区

發布時間:2024/3/24 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python演示动画_Python八大行星漂亮动画演示-Go语言中文社区 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

"""一個簡單的演示八大行星公轉的動畫,采用arcade街機游戲模塊制作,安裝Arcade請用pip install arcade --user。

A simple animation to simulate the rotation of eight planets is made by using Arcade module. To install Arcade, use PIP install arcade--user.

"""

__author__ = "lixingqiu"

__date__ = "2019/3/8"

import time

import math

import arcade

import random

SCREEN_WIDTH = 1350

SCREEN_HEIGHT = 780

SCREEN_TITLE = "eight planet 八大行星"

class Planet(arcade.Sprite):

def __init__(self,image,a,b,angle,speed):

"""image:造型圖片,a:Long axis長半軸,b:semi-minor axis短半軸,angle:初始角度"""

super().__init__(image)

self.center_x = SCREEN_WIDTH / 2

self.center_y = SCREEN_HEIGHT / 2

self.direction = angle # 自定義direction,不用原有屬性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)) # 根據橢圓參數方程算起始坐標

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):

"""

繼承自窗口的MyGame類.

"""

def __init__(self, width, height, title):

super().__init__(width, height, title)

arcade.set_background_color(arcade.color.WHITE)

def setup(self):

""" 這里是對游戲中的各個對象進行設置 """

self.planet_list = arcade.SpriteList() # 新建角色列表,以便統一渲染

# 背景角色生成

pass

# 太陽角色生成

pass

# 行星角色生成

pass

for i in range(8): # 生成8個行星

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) # 新建行星

self.planet_list.append(aplanet) # 添加到所有行星列表

def update(self, x):

"""每幀更新游戲內在邏輯"""

self.planet_list.update()

self.sun.update_animation()

def on_draw(self):

"""渲染屏幕 """

arcade.start_render()

# 開始畫背景

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()

總結

以上是生活随笔為你收集整理的python演示动画_Python八大行星漂亮动画演示-Go语言中文社区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。