![]() |
Hi guys, I'm back now. I have the great news that I am now a VPython programmer! (For those of you who don't know what it is, click Here , and be amazed). Python is a computer language that allows you to communicate directly to your computer and have it do exactly what you want.It can add numbers, reverse words, and even draw. But VPython is the real deal. The V stands for Visual, meaning 3-D virtual things. It allows you to maniputlae 3-D geometrical shapes, and have them move around. Shown is a screen shot of my masterpiece. I wish I could have them moving around in the backround, but that is beyond me :P. If you would like to see it in its entirety, click on the previous link. There it says: Download: Free downloads for Windows, Macintosh, and Linux. If you are using Microsoft, click Windows. If you are on an apple device, click Macintosh. And for those gifted few on Linux, click Linux. You should download the latest version if you do have the guts to download it. When you've finally opened the fidgety thing, copy and paste the following code:
from visual import *
import random bbs=0 dt=0.1 #creates the main place lamp=local_light(pos=(-30,0,30)) floor=box(size=(40,1,40), materials=materials.wood, pos=(0,-12,0), color=color.orange) post11=cylinder(radius=1.2, length=20, color=(1,1,1), axis=(0,5,0), pos=(18,-11.5,18), materials=materials.marble) post12=cylinder(radius=1.2, length=20, color=(1,1,1), axis=(0,5,0), pos=(-18,-11.5,18), materials=materials.marble) post13=cylinder(radius=1.2, length=20, color=(1,1,1), axis=(0,5,0), pos=(18,-11.5,-18), materials=materials.marble) post14=cylinder(radius=1.2, length=20, color=(1,1,1), axis=(0,5,0), pos=(-18,-11.5,-18), materials=materials.marble) pelota=sphere(radius=1.5, color=color.yellow, pos=(18,0,18), material=materials.plastic) pelota2=sphere(radius=1.5, color=color.yellow, pos=(-18,0,18), material=materials.plastic) pelota3=sphere(radius=1.5, color=color.yellow, pos=(18,0,-18), material=materials.plastic) pelota4=sphere(radius=1.5, color=color.yellow, pos=(-18,0,-18), material=materials.plastic) pelota5=sphere(radius=1.5, color=color.red, pos=(-18,-1.5,18), material=materials.plastic) pelota6=sphere(radius=1.5, color=color.red, pos=(18,-1.5,-18), material=materials.plastic) pelota7=sphere(radius=1.5, color=color.red, pos=(18,-1.5,18), material=materials.plastic) pelota8=sphere(radius=1.5, color=color.red, pos=(-18,-1.5,-18), material=materials.plastic) pelota9=sphere(radius=1.5, color=color.green, pos=(18,-3,18), material=materials.plastic) pelota10=sphere(radius=1.5, color=color.green, pos=(-18,-3,-18), material=materials.plastic) pelota11=sphere(radius=1.5, color=color.green, pos=(18,-3,-18), material=materials.plastic) pelota12=sphere(radius=1.5, color=color.green, pos=(-18,-3,18), material=materials.plastic) ceiling=box(size=(40,1,40), materials=materials.wood, pos=(0,9,0), color=color.orange) #creates a snowman s1=sphere(radius=1, pos=(0,-5,0)) s2=sphere(radius=1.75, pos=(0,-7,0)) s3=sphere(radius=2.75, pos=(0,-10,0)) arm1=arrow(shaftwidth=0.25, axis=(5,1.5,0), color=(0.62,0.31,0.09), pos=(0.75,-7,0), length=3.5) arm2=arrow(shaftwidth=0.25, axis=(-5,1.5,0), color=(0.62,0.31,0.09), pos=(-0.75,-7,0), length=3.5) left_eye=sphere(radius=0.2, color=color.black, pos=(0.35,-4.8,0.8)) right_eye=sphere(radius=0.2, color=color.black, pos=(-0.35,-4.8,0.8)) nose=arrow(shaftwidth=0.15, color=(1,0.5,0.01), pos=(0,-5,0.67), axis=(0,0,5), length=1.5) #Creates Snow Globe snow_globe=sphere(radius=7, color=(0,0.1,0.8), opacity=0.17, pos=(0,-6.2,0))
#Creates snowballs
n1=random.randrange(0,4)
n2=random.randrange(0,4) n3=random.randrange(0,4) n4=random.randrange(0,4) n5=n1-5.5 n6=n2-5.5 n7=n3-5.5 n8=n4-5.5 m1=random.randrange(0,4) m2=m1-5.5
snow1=sphere(pos=(4,(n5),3), radius=0.25)
snow2=sphere(pos=(2,(n6),-2), radius=0.25) snow3=sphere(pos=(-2,(n7),0), radius=0.25) snow4=sphere(pos=(-4,(n8),1), radius=0.25) snow5=sphere(pos=(3,(m2),-3), radius=0.25)
#creates the slinkys
spring=helix(pos=(15,-11.5,15), radius=3, color=(0,0.75,0.5), axis=(0,5,0), length=20, coils=15) spring2=helix(pos=(10,-11.5,15), radius=3, color=(0.5,0.75,0), axis=(0,5,0), length=20, coils=15)
#creates the donut on a string
donut=ring(color=color.green, pos=(-10,5,-5), radius=1.5, thickness=(0.5), axis=(0,0,5)) donut.velocity=vector(0,0,3) line=cylinder(pos=(-10,5,-10),color=color.blue, radius=1, length=20, axis=(0,0,5)) suspension1=cylinder(pos=(-10,5,9.25), color=color.blue, radius=1, length=4.4, axis=(0,5,0)) suspension2=cylinder(pos=(-10,5,-9.25), color=color.blue, radius=1, length=4.4, axis=(0,5,0))
#creates the cone
spinny=cone(pos=(-10,-9.8,-12.5), axis=(5,-5.5,8), radius=2, length=3,color=color.red) #Creates the cube square=box(pos=(0,7,-13), size=(3,3,3), color=color.blue) square.velocity=vector(0,-1,0)
#creates the 'lollipops'
post=cylinder(length=5, radius=0.3, pos=(-12, -11.5, 12), axis=(0,5,0)) post2=cylinder(length=5, radius=0.3, pos=(-14, -11.5, 12), axis=(0,5,0)) tr=sphere(radius=1, color=color.red, opacity=0.7, pos=(-12,-6.5,12)) tr.velocity=vector(-1,0,0)
#Creates the veritcal post with rings
p_o_s_t=cylinder(length=20, pos=(16, -11.5, -10), axis=(0,5,0), color=(0.25,0.25,0.25), radius=0.7) rr1=ring(color=color.red, axis=(0,5,0),thickness=1, radius=4, pos=(16,-10.5,-10)) rr2=ring(color=color.green, axis=(0,5,0),thickness=1, radius=3, pos=(16,-8.5,-10)) rr3=ring(color=color.yellow, axis=(0,5,0),thickness=1, radius=2, pos=(16,-6.5,-10)) rr4=ring(color=color.blue, axis=(0,5,0),thickness=1, radius=1, pos=(16,-4.5,-10)) rr5=ring(color=(0.653,0.498,0.973), axis=(0,5,0),thickness=1, radius=0.5, pos=(16,-2.5,-10))
#creates the spinning pyramid
pyr=pyramid(size=(5,3.5,3.5), color=(1,0.689,0.738), axis=(0,5,0), pos=(-15,-11.5,0))
#creates the extrusion
tri=shapes.triangle(pos=(0,-9.5), length=1.5) hole=shapes.circle(pos=(0,-9.5), radius=0.3) ppl=paths.arc(pos=(-13,-1.5,15), radius=0.9) zazaza=extrusion(pos=ppl, shape=tri-hole, color=(1,1,0.57))
#Creates "Welcome" in several languages
text(text="WELCOME!", color=(0.653,0.498,0.973), pos=(-8.5,10,17), height=2.25, depth=2, material=materials.unshaded) text(text="ДОБРО", color=(0.653,0.498,0.973), pos=(-19,14,16), height=1.25, depth=1, material=materials.unshaded)#Russian text(text="ПОЖАЛОВАТЬ!", color=(0.653,0.498,0.973), pos=(-22,12,16), height=1.25, depth=1, material=materials.unshaded)#More in Russian text(text="¡BIENVENIDOS!", color=(0.653,0.498,0.973), pos=(9.5,12,16), height=1.25, depth=1, material=materials.unshaded)#spanish text(text="WILKOMMEN!", color=(0.653,0.498,0.973), pos=(-8,14,16), height=1.25, depth=1, material=materials.unshaded)#German text(text="KARIBU!", color=(0.653,0.498,0.973), pos=(8,14,16), height=1.25, depth=1, material=materials.unshaded)#Swahili
#lets amination take place
while True: #lets snow fall rate(45) if snow1.y<=n5: snow1.pos=snow1.pos+(0,-0.1,0) if snow1.y<-11.5: snow1.pos=(4,n5,3) rate(45) if snow2.y<=n6: snow2.pos=snow2.pos+(0,-0.1,0) if snow2.y<-11.5: snow2.pos=(2,n6,-2) rate(35) if snow3.y<=n7: snow3.pos=snow3.pos+(0,-0.1,0) if snow3.y<-11.5: snow3.pos=(-2,n7,0) rate(40) if snow4.y<=n8: snow4.pos=snow4.pos+(0,-0.1,0) if snow4.y<-11.5: snow4.pos=(-4,n8,1) rate(40) if snow5.y<=m2: snow5.pos=snow5.pos+(0,-0.1,0) if snow5.y<-11.5: snow5.pos=(5,m2,-3) #changes the length of the slinkys rate(150) if spring.length>=1: spring.length=spring.length+(0.5) if spring.length>20: spring.length=1 rate(150) if spring2.length<=20: spring2.length=spring2.length-(0.5) if spring2.length<1: spring2.length=20 #moves the ring on the pole rate(175) donut.pos=donut.pos+donut.velocity*dt donut.velocity.z=donut.velocity.z if donut.z<=-5: donut.velocity.z=-donut.velocity.z if donut.z>5: donut.velocity.z=-(donut.velocity.z) #rotates the cone rate(165) spinny.rotate(angle=pi/7, axis=(0,pi/2,0), origin=(-10,-9.8,-9.5)) #bounces the cube rate(180) square.pos = square.pos + square.velocity*dt if square.y < -9: square.velocity.y = -square.velocity.y else: square.velocity.y = square.velocity.y - 9.8*dt #changes the cube's color if square.velocity.y>0: square.color=color.red else: square.color=color.blue #moves the 'lollipop' rate(110) tr.pos = tr.pos + tr.velocity*dt if tr.x < -14: tr.velocity.x = -tr.velocity.x else: tr.velocity.x = tr.velocity.x - 9.8*dt #changes the sticks' color if tr.velocity.x>0: post2.color=(1,1,1) post.color=(0,0,0) else: post2.color=(0,0,0) post.color=(1,1,1) #moves the rings on the pole rate(115) if rr1.y>=-10.5: rr1.pos=rr1.pos+(0,0.25,0) if rr1.y==8: rr1.pos=(16,-10.5,-10) if rr2.y>=-8.5: rr2.pos=rr2.pos+(0,0.25,0) if rr2.y==6: rr2.pos=(16,-8.5,-10) if rr3.y>=-6.5: rr3.pos=rr3.pos+(0,0.25,0) if rr3.y==4: rr3.pos=(16,-6.5,-10) if rr4.y>=-4.5: rr4.pos=rr4.pos+(0,0.25,0) if rr4.y==2: rr4.pos=(16,-4.5,-10) if rr5.y>=-2.5: rr5.pos=rr5.pos+(0,0.25,0) if rr5.y==0: rr5.pos=(16,-2.5,-10) #Spins the pyramid rate(210) pyr.rotate(angle=pi/16, axis=(0,5,0), origin=(-15,-11.5,0)) bbs=bbs+1 if bbs%2==0: zazaza.color=(1,1,0.57) else: zazaza.color=color.cyan |
Friday, June 29, 2012
3-D virtual world
and be amazed...
Subscribe to:
Posts (Atom)
