カテゴリー
Python

Eclipse でのpython(Anaconda) + pygame の状態

[python]

""" draw_rect1.py """
import sys
import pygame
from pygame.locals import Rect
from pygame.locals import QUIT

pygame.init()
SURFACE = pygame.display.set_mode((400, 300))
FPSCLOCK = pygame.time.Clock()

def main():
""" main routine """

while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

SURFACE.fill((255, 255, 255))

# 赤:矩形(塗りつぶし)
pygame.draw.rect(SURFACE, (255, 0, 0), (10, 20, 100, 50))

# 赤:矩形(太さ3)
pygame.draw.rect(SURFACE, (255, 0, 0), (150, 10, 100, 30), 3)

# 緑:矩形
pygame.draw.rect(SURFACE, (0, 255, 0), ((100, 80), (80, 50)))

# 青:矩形、Rectオブジェクト
rect0 = Rect(200, 60, 140, 80)
pygame.draw.rect(SURFACE, (0, 0, 255), rect0)

# 黄:矩形、Rectオブジェクト
rect1 = Rect((30, 160), (100, 50))
pygame.draw.rect(SURFACE, (255, 255, 0), rect1)

pygame.display.update()
FPSCLOCK.tick(3)

if __name__ == ‘__main__’:
main()

[/python]

カテゴリー
Python

draw_image4.py

[python]
#""" draw_image4.py """
import sys
import pygame
from pygame.locals import QUIT

pygame.init()
SURFACE = pygame.display.set_mode((400, 300))
FPSCLOCK = pygame.time.Clock()

def main():
""" main routine """
logo = pygame.image.load("pythonlogo.jpg")
theta = 0

while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

theta += 1

SURFACE.fill((225, 225, 225))

# ロゴを回転し、中心が(200, 150)の位置にロゴを描画
new_logo = pygame.transform.rotate(logo, theta)
rect = new_logo.get_rect()
rect.center = (200, 150)
SURFACE.blit(new_logo, rect)

pygame.display.update()
FPSCLOCK.tick(30)

if __name__ == ‘__main__’:
main()
[/python]

どうも少しおかしいようです。最初と最後にpreが付いてますが、これはいらないです。

カテゴリー
未分類

pythonでSyntaxhighlighter使ってみました。

[python]
# -*- coding: utf-8 -*-
import vpython as vs
import time

def main():
# シーンの範囲
vs.scene.range = 5

# 箱のサイズ
l, h, w = 2, 2, 2

# 箱の中心位置
x, y, z = 0, 0, 0

# 箱の定義
box = vs.box(color=vs.vector(255, 255, 255),
pos=vs.vector(x, y, z),
size=vs.vector(l, h, w),
axis=vs.vector(l, 0, 0)
)
# 回転角[deg]
deg = 0

while True:
# 360[deg]になったら初期化
if deg == 360:
deg = 0
# フレームレート
vs.rate(10)
# 軸を動かして回転
box.axis = l * vs.vector(vs.sin(deg), 0, vs.cos(deg))
# 0.1[degずつ動かす]
deg += 0.1

if __name__ == ‘__main__’:
main()
[/python]

inserted by FC2 system