@kobb3:
vet du vad, skulle du kunna göra en tjänst? det verkar ju som att min dator inte kan läsa mitt program, skulle inte du kunna testa mitt program och kolla om det kommer en graf? för att uppgiften var att få en graf av bollarna. och jag kan ju inte öppna grafen, så skulle du kunna bara testa snabbt om det fungerar?
jag skulle vara otroligt tacksam
from visual import * # must import visual or vis first
import matplotlib.pyplot as plt
ball = sphere(pos=(-5,0,0), radius=0.5, color=color.cyan)
ball2 = sphere(pos=(5,0,0), radius=1, color=(1,0.7,0.7))
wallR = box(pos=(6,0,0), size=(0.2,12,12), color=color.green)
wallL = box(pos=(-6,0,0), size=(0.2,12,12), color=color.green)
wallU = box(pos=(0,6,0), size=(12,0.2,12), color=color.blue)
wallD = box(pos=(0,-6,0), size=(12,0.2,12), color=color.blue)
wallB = box(pos=(0,0,-6), size=(12,12,0.2), color=color.red)
ball.velocity = vector(25,5,15)
ball2.velocity = vector(10,2,5)
ball.acc = 2.5
deltat = 0.005
t = 0
vscale = 0.1
vscale2 = 0.5
varr = arrow(pos=ball.pos, axis=vscale*ball.velocity, color=color.yellow)
varr2 = arrow(pos=ball2.pos, axis=vscale*ball2.velocity, color=color.magenta)
ball.trail = curve(color=ball.color)
ball2.trail = curve(color=ball2.color)
scene.autoscale = False
ballXpos = [] #Här startas listan ballXpos
tid = [] #Här startas listan tid
while True:
rate(100)
if ball.pos.x +0.5 > wallR.pos.x:
ball.velocity.x = -ball.velocity.x
if ball.pos.x -0.5 < wallL.pos.x:
ball.velocity.x = -ball.velocity.x
if ball.pos.y +0.5 < wallU.pos.y:
ball.velocity.y = -ball.velocity.y
if ball.pos.y -0.5 > wallD.pos.y:
ball.velocity.y = -ball.velocity.y
if ball.pos.z -0.5 < wallB.pos.z:
ball.velocity.z = -ball.velocity.z
if ball.pos.z +0.5 > 6:
ball.velocity.z = -ball.velocity.z
ballXpos.append(ball.pos.x) #Här lägger jag värden i listan
tid.append(t) #Här lägger jag värden i listan
ball.pos = ball.pos + ball.velocity*deltat
varr.pos = ball.pos
varr.axis = vscale*ball.velocity
ball.trail.append(pos=ball.pos)
t = t + deltat
if ball2.pos.x +1 > wallR.pos.x:
ball2.velocity.x = -ball2.velocity.x
if ball2.pos.x -1 < wallL.pos.x:
ball2.velocity.x = -ball2.velocity.x
if ball2.pos.y +1 < wallU.pos.y:
ball2.velocity.y = -ball2.velocity.y
if ball2.pos.y -1 > wallD.pos.y:
ball2.velocity.y = -ball2.velocity.y
if ball2.pos.z -1 < wallB.pos.z:
ball2.velocity.z = -ball2.velocity.z
if ball2.pos.z +1 > 6:
ball2.velocity.z = -ball2.velocity.z
ball2.pos = ball2.pos + ball2.velocity*deltat
varr2.pos = ball2.pos
varr2.axis = vscale2*ball2.velocity
ball2.trail.append(pos=ball2.pos)
t = t + deltat
from visual.graph import * # import graphing features
f1 = gcurve(color=color.cyan) # a graphics curve
for x in arange(0, 8.05, 0.1):
f1.plot(pos=ball.pos) # plot
"""
Här skrivs ut en plot med bollens x-position över tid.
"""
fig = plt.figure(facecolor='white')
plt.title('XY plot')
ax = fig.add_subplot(111)
ax.set_xlabel('x')
ax.set_ylabel('y')
x=tid #Här anger jag x-axis som tid
y=ballXpos #Här anger jag y-axis som ballXpos
TextWindow = "label 1"
plt.plot(x,y,c='blue',label=TextWindow)
plt.legend(loc='upper right')
plt.show()