#!/usr/bin/python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2017/09/14 22:05:23 +0900> u""" pi3d Sphere sample. 球をたくさん描画してみるサンプル。 透視投影で描画しつつグネグネ動かす。 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 from math import radians from math import sin import pi3d # ウインドウ生成 display = pi3d.Display.create(w=640, h=480, frames_per_second=60) # 球をたくさん生成 balls = [] num = 30 for i in range(num): ball = pi3d.Sphere(radius=5) balls.append(ball) # キーボード取得用クラスを生成 keys = pi3d.Keyboard() bs_z = 50.0 x_ang, y_ang, z_ang = 0.0, 0.0, 0.0 # メインループ while display.loop_running(): x_ang = (x_ang + 3.0) % 360.0 y_ang = (y_ang + 4.0) % 360.0 z_ang = (z_ang + 2.2) % 360.0 # 先っぽ tx = 0.0 ty = 0.0 tz = 30.0 * sin(radians(z_ang)) + bs_z # 根元 bx = 0.0 by = 0.0 bz = tz + 200.0 dx = (tx - bx) / num dy = (ty - by) / num dz = (tz - bz) / num for i, ball in enumerate(balls): x = bx + (dx * i) + (15.0 * sin(radians(x_ang + (10.0 * i)))) y = by + (dy * i) + (12.0 * sin(radians(y_ang + (25.0 * i)))) z = bz + (dz * i) ball.position(x, y, z) # スプライトの座標を設定 ball.draw() # スプライトを描画 if keys.read() == 27: # ESCキーが押されたらループを抜けて終了 keys.close() display.destroy() break