Velocity Reviews > problem with exam task for college

# problem with exam task for college

stefaang@gmail.com
Guest
Posts: n/a

 01-14-2013
Hi,

I only skimmed through the code, but I think your problem resides at the "while True" in your brandstofmeter update(). This function never stops..

jeltedeproft@hotmail.com
Guest
Posts: n/a

 01-14-2013
this is what i have right now, it tells me i can't multiply a vector with a vector, i have to find a way to multiply the speed with the updated angle (=hoek in dutch)

code :

from visual import *
import time
import math
import random

class lunar_lander(object):
def __init__(self):
scene.title = 'mini star wars'
scene.width = 375
scene.height = 550
scene.center = (0,0)
self.pos = (0,0)
self.axis = 0
self.brandstofmeter = brandstofmeter()
self.ruimteschip = ruimteschip()
self.view = game_view(self)

def play(self):
t=0
dt=0.01
while t<999999999:
time.sleep(0.01)
self.brandstofmeter.update
self.ruimteschip.update(dt)
t = t + dt

class game_view(object):
def __init__(self,owner):
autoscale=True
box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white)
box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white)

maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red)
maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green)
maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red)
maanc = curve(pos=[(80,-347),(140,-347)],color=color.green)
maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-33],color=color.red)

for i in random.sample(range (-250,250),20):
for j in random.sample(range (-375,375),20):
sterren = points(pos = [i,j,0],size = 2, color=color.white)

class brandstofmeter(object):
def __init__(self):
self.size = (25,45)
axis = 0
self.pos = (220,345)
self.view = brandstofmeter_view(self)

def update(self):
while True:
if scene.kb.keys:
s = scene.kb.getkey()
if (s == 'up'):
self.view.update(self)

class brandstofmeter_view(object):
def __init__(self,owner):
self.owner = owner
meter = box(pos = owner.pos,size = owner.size,color = color.green)

def update (self,owner):
self.size = self.size - (0,0.45)

class ruimteschip(object):
def __init__(self):
self.pos = vector(0,330)
self.axis = (1,0,0)
self.view = ruimteschip_view(self)
self.vlam = self.view.vlam
self.frame = self.view.frame
self.hoek = pi / 2

def update(self,dt):
zwaartekracht = vector(0,-2,0)
self.gas = vector(0,10,0)
self.acceleration = zwaartekracht
self.axis = (1,0,0)
if scene.kb.keys:
s = scene.kb.getkey()
if (s == "up"):
self.acceleration =+ self.gas * vector(math.cos(self.hoek),math.sin(self.hoek))
if (s == "left"):
self.hoek =+ pi/12
if (s == "right") :
self.hoek =- pi/12

self.pos = self.pos + self.acceleration
if self.pos.x > 250:
self.pos.x = -250
if self.pos.x < -250:
self.pos.x = 250

if self.acceleration != (0,-2,0):
self.vlam.visible = True
else :
self.vlam.visible = False
self.view.update(self)

class ruimteschip_view(object):
def __init__(self,owner):
self.owner = owner
self.frame = frame(pos = owner.pos,axis = owner.axis)
self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)])
self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,4,(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50) ,(18,4,(12,46),(9,44),(3,39),(0,39)])
self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)])
self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)])
self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)])

def update(self,owner):
self.frame.axis = owner.axis
self.frame.pos = owner.pos

Dennis Lee Bieber
Guest
Posts: n/a

 01-14-2013
On Mon, 14 Jan 2013 08:01:03 -0800 (PST), http://www.velocityreviews.com/forums/(E-Mail Removed)
declaimed the following in gmane.comp.python.general:

> this is what i have right now, it tells me i can't multiply a vector with a vector, i have to find a way to multiply the speed with the updated angle (=hoek in dutch)
>

It's a trite saying but:

How would you perform this vector multiplication by hand? Write down
the steps... Now convert those steps into Python code.

using NumPy vector types which should support the needed
multiplications.

>>> import numpy
>>> a = numpy.array( (2.78, 3.14, 195 )
>>> b = numpy.array( (1.5, 2.0, 1.0) )
>>>
>>> a*b

array([ 4.17, 6.28, 1958. ])
>>> a.dot(b)

1968.45
>>>

--
Wulfraed Dennis Lee Bieber AF6VN
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/