Software / Hardware issues using Python and vpython on a laptop

Product: HP Laptop PC 15s-Fq2000 (2D119AV)
11th Gen Intel(R) Core™ i5-1135G7 @ 2.40GHz 2.40 GHz
8.00 GB (7.65 GB usable)
Operating System: Microsoft Windows 11

Hello ‘again’ Everyone,

As I’m progressing teaching myself Python and vpython from YouTube lessons, pdf’s etc, I need to visualise some of my projects using Arduino and ESP32 micros.
The ‘issue’ I am having of my Python/vpython graphics lessons is that the graphics programs run like a wasp with a headache!
Before posting to the Python Help community, I tried to work out if I have a genuine issue between software and hardware of my new laptop. (Details above).
From the lessons for example ‘delta’, as a variable pos.x = pos.x + deltax used to reflect an incremental change through a While loop and rate(value) I have to significantly change to the lesson examples.

i.e. rate(lesson example) = 0.02 against rate(my laptop) = 0.000002

I have found this through trial and error from when I run Python lesson programs trying to slow down the graphics that are moving an object e.g. bouncing a ball in an enclosed box. At first being a newbie I couldn’t reason why the graphics (the ball) appeared ‘uncontrollable’.

Has anyone met this ? or can offer me any advice ? I’m struggling to understand why standard Python/vpython programs are behaving this way as it’s been quite torturous at times fathoming out what’s going on!

Is it just a fact I have a new laptop and I have to account for the changes in processor speed and efficiency, and if so, are there any software solutions someone could kindly point out I need to read up on?
I did come across a similar posting on stackoverflow which suggested using a different graphics engine but the lessons I am following are all using vpython.

On another point I noticed if I unplugged the laptop power supply after about 10secs the moving graphics became very ‘jumpy’ and not smooth movements.
Additionally what I now observe is with the power supply connected permanently after about 10secs the fan kicks in cooling the processor why I observe a slight change in the graphics.

Are there any Python sofware ‘tweeks’ to help I should be looking at? Code example I’ve built as an example is below:-

from vpython import *

mRadius=0.5

wallThickness=0.1
roomWidth=10
roomDepth=10
roomHeight=10

basefloor=box(pos=vec(0,-roomHeight/2,0),size=vec(roomWidth,wallThickness,roomDepth),color=color.white)
ceiling=box(pos=vec(0,roomHeight/2,0),size=vec(roomWidth,wallThickness,roomDepth),color=color.white,opacity=0.2)
backWall=box(pos=vec(0,0,-roomDepth/2),size=vec(roomWidth,roomHeight,wallThickness),color=color.white)
leftWall=box(pos=vec(-roomWidth/2,0,0),size=vec(wallThickness,roomHeight,roomDepth),color=color.white)
rightWall=box(pos=vec(roomWidth/2,0,0),size=vec(wallThickness,roomHeight,roomDepth),color=color.white)
frontWall=box(pos=vec(0,0,roomDepth/2),size=vec(roomWidth,roomHeight,wallThickness),color=color.white,opacity=0.2)

marbleR=sphere(pos=vector(-5, 4, 3),radius=mRadius,color=color.red)
marbleY=sphere(pos=vector(-5, 3, 1),radius=mRadius,color=color.yellow)
marbleB=sphere(pos=vector(1, 0, -5),radius=mRadius,color=color.blue)
marbleG=sphere(pos=vector(0, -5, 2),radius=mRadius,color=color.green)

deltaRX = deltaRY = deltaRZ = 4
deltaYX = deltaYY = deltaYZ = 4
deltaBX = deltaBY = deltaBZ = 4
deltaGX = deltaGY = deltaGZ = 4

xRPos, yRPos, zRPos = 0, 1, -2
xYPos, yYPos, zYPos = 1, -2, 3
xBPos, yBPos, zBPos = -2, 2, 1
xGPos, yGPos, zGPos = -3, 1, 2
rate = 5
ratio=0.00001*rate

scene.autoscale = False
while True:

    rate=(100)
    
    xRPos=xRPos+deltaRX*ratio
    yRPos=yRPos+deltaRY*ratio
    zRPos=zRPos+deltaRZ*ratio

    xYPos=xYPos+deltaYX*ratio
    yYPos=yYPos+deltaYY*ratio
    zYPos=zYPos+deltaYZ*ratio

    xBPos=xBPos+deltaBX*ratio
    yBPos=yBPos+deltaBY*ratio
    zBPos=zBPos+deltaBZ*ratio

    xGPos=xGPos+deltaGX*ratio
    yGPos=yGPos+deltaGY*ratio
    zGPos=zGPos+deltaGZ*ratio

    marbleR.pos= vec(xRPos,yRPos,zRPos)
    marbleY.pos= vec(xYPos,yYPos,zYPos)
    marbleB.pos= vec(xBPos,yBPos,zBPos)
    marbleG.pos= vec(xGPos,yGPos,zGPos)
    
    if (xRPos+mRadius >= roomWidth/2) or (xRPos-mRadius <= -roomWidth/2):
        deltaRX = deltaRX*(-1)
    if (yRPos+mRadius >= roomHeight/2) or (yRPos-mRadius <= -roomHeight/2):
        deltaRY = deltaRY*(-1)
    if (zRPos+mRadius >= roomDepth/2) or (zRPos-mRadius <= -roomDepth/2):
        deltaRZ = deltaRZ*(-1)

    if (xYPos+mRadius >= roomWidth/2) or (xYPos-mRadius <= -roomWidth/2):
        deltaYX = deltaYX*(-1)
    if (yYPos+mRadius >= roomHeight/2) or (yYPos-mRadius <= -roomHeight/2):
        deltaYY = deltaYY*(-1)
    if (zYPos+mRadius >= roomDepth/2) or (zYPos-mRadius <= -roomDepth/2):
        deltaYZ = deltaYZ*(-1)

    if (xGPos+mRadius >= roomWidth/2) or (xGPos-mRadius <= -roomWidth/2):
        deltaGX = deltaGX*(-1)
    if (yGPos+mRadius >= roomHeight/2) or (yGPos-mRadius <= -roomHeight/2):
        deltaGY = deltaGY*(-1)
    if (zGPos+mRadius >= roomDepth/2) or (zGPos-mRadius <= -roomDepth/2):
        deltaGZ = deltaGZ*(-1)

    if (xBPos+mRadius >= roomWidth/2) or (xBPos-mRadius <= -roomWidth/2):
        deltaBX = deltaBX*(-1)
    if (yBPos+mRadius >= roomHeight/2) or (yBPos-mRadius <= -roomHeight/2):
        deltaBY = deltaBY*(-1)
    if (zBPos+mRadius >= roomDepth/2) or (zBPos-mRadius <= -roomDepth/2):
        deltaBZ = deltaBZ*(-1)
    

Many thanks in advance.

Usually there is a way for a graphics program to wait for a frame to be draw.
What is the vpython way to wait for the frame to be draw, and seen by the user?
I do not know anything about vpython so cannot help with the details.

For a 60Hz screen you would expect a frame to be drawn every 0.01666 seconds,
or 16.66ms. A rate of 0.02 implies a 50Hz screen that is not typical in computer world.

I notice that vpython has a function rate(...), but your code has rate=(100). Is that the problem?

Thank you for your replies :slight_smile:
First I just used rate(number between 1 to 100) and had varying results of the graphic position wrt time.
I then used (from an example on stackoverflow) a integer multiplier rate=5 which had an improved/another ‘retarding’ effect.
One other test I tried which was ‘enlightening’ as a newbie was using print(position value) I can post that example, which massively slowed the graphics down and helped me to understand the ‘problem’ as I could see the numerical equivalent values changing even though the graphic ‘object’ wasn’t!
The numerical values scrolling through the ‘terminal’ view were a little strange in that were float type numbers where the values AFTER the decimal point were changing? I did read somewhere that this is function of how Python handles these numbers.
I will look at using numerical values in terms of the the 60Hz frame rate and see how that helps.