#!/usr/bin/python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2017/09/04 10:22:27 +0900> u""" pi3d Hello World. 球を生成して描画するサンプル。位置を動かしてみる。 ESCキーで終了する。 Windows10 x64 + Python 2.7.12 32bit + pi3d 2.20 """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import math import pi3d # ウインドウ生成 display = pi3d.Display.create(w=640, h=480, frames_per_second=60) x, y, z = 0.0, 0.0, 15.0 x_ang, y_ang, z_ang = 0.0, 0.0, 0.0 # 球を生成 ball = pi3d.Sphere(x=x, y=y, z=z) # キーボード取得用クラスを生成 keys = pi3d.Keyboard() # メインループ while display.loop_running(): # sinカーブで位置を動かす x_ang += 3.0 y_ang += 4.5 z_ang += 0.8 x = 5.0 * math.sin(math.radians(x_ang)) y = 3.0 * math.sin(math.radians(y_ang)) z = 7.0 * math.sin(math.radians(z_ang)) + 15.0 # 球の位置を設定 ball.position(x, y, z) # 球を描画 ball.draw() if keys.read() == 27: # ESCキーが押されたらループを抜けて終了 keys.close() display.destroy() break