Created
November 6, 2014 20:14
-
-
Save hackingmath/2b3667288af4c02098e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sat Nov 01 19:39:44 2014 | |
@author: Peter Farrell | |
Simulation of world, navigating by arrow buttons! | |
""" | |
#from future import __division__ | |
from visual import * | |
import random | |
from math import tan,sin, cos | |
scene = display(height = 600, | |
width = 600, | |
background = color.cyan) | |
camera = vector(0,5,30) | |
# Place center of scene at a distance 5 units from the camera: | |
scene.center = camera+vector(0,0,-5) | |
# Point the camera: | |
scene.forward = scene.center-camera | |
# scene.fov is "field of view" in radians. 5 times the tangent | |
# of half the field of view is half of the width of the scene: | |
scene.range = -5*tan(scene.fov/2) | |
scene.userspin = False | |
'''#create the axes: | |
xaxis = cylinder(pos=(0,0,0),axis=(10,0,0), radius=0.025) | |
yaxis = cylinder(pos=(0,0,0),axis=(0,10,0), radius=0.025) | |
zaxis = cylinder(pos=(0,0,0),axis=(0,0,10), radius=0.025)''' | |
'''for i in range(20): # make a bunch of boxes and | |
# put them on the floor | |
box(pos = (random.randint(-50,50),2.5, | |
random.randint(-50,50)), | |
height = 5, | |
width = 5, | |
length = 5, | |
color = color.yellow, | |
material = materials.wood)''' | |
t = 0 | |
for i in range(20): # make a bunch of boxes in a spiral: | |
box(pos = (10*sin(t),2*t,10*cos(t)), | |
height = 5, | |
width = 5, | |
length = 5, | |
color = color.yellow, | |
material = materials.wood) | |
t += .5 | |
floor = box(pos = (0,0,0), | |
height = .1, | |
width = 100, | |
length = 100, | |
material = materials.marble, | |
color = color.white) | |
wall = box(pos = (-50,5,0), | |
length = 0.5, | |
width = 100, | |
height = 10, | |
material = materials.wood, | |
color = color.cyan) | |
treestump = box(pos = (20,2.5,-5), | |
height = 5, | |
width = 5, | |
length = 5, | |
color = color.green, | |
material = materials.rough) | |
scene.autoscale = False | |
while True: | |
rate(10) | |
if scene.kb.keys: #if a key is pressed | |
key = scene.kb.getkey() #get which key it is | |
if key == 'left': #rotate left | |
scene.forward = scene.forward.rotate(angle=pi/6, | |
axis=(0,1,0)) | |
if key == 'right': #rotate right | |
scene.forward = scene.forward.rotate(angle=-pi/6, | |
axis=(0,1,0)) | |
if key == 'up': #move forwards | |
scene.center -= scene.forward | |
if key == 'down': #move backwards | |
scene.center += scene.forward |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment