DEV Community

Cover image for 3D VPython in RapydScript
artydev
artydev

Posted on

3D VPython in RapydScript

Here is a port of VPython a 3D Physics simulator in RapydScript
You can test it here by selecting the samples

RapydGlow

Here is a demo of a bouncing ball in a Box, you can play with it in real time...

side = 4.0
thk = 0.3
s2 = 2*side - thk
s3 = 2*side + thk
wallR = box (pos=vec( side, 0, 0), size=vec(thk,s2,s3),  color =color.red )
wallL = box (pos=vec(-side, 0, 0), size=vec(thk,s2,s3),  color =color.red)
wallB = box (pos=vec(0, -side, 0), size=vec(s3,thk,s3),  color =color.blue)
wallT = box (pos=vec(0,  side, 0), size=vec(s3,thk,s3),  color =color.blue )
wallBK = box(pos=vec(0, 0, -side), size=vec(s2,s2,thk),  color =color.gray(0.7))

ball = sphere (color=color.green, size = vec(1,1,1) )
ball.mass = 1.0
ball.p = vec(-0.15, -0.23, +0.27)

attach_trail(ball, pps=200, retain=99)

side = side - thk*0.5 - ball.size.x/2
dt = 0.3
ball.pos = vec(1,1,1)

while true:
    rate(200,wait) # execute the move function about 200 times per second

    # Overloading operators to act on vector object
    ball.pos = ball.pos + (ball.p/ball.mass)*dt

    if not (-side < ball.pos.x < side): 
        ball.p.x = -ball.p.x

    if not (-side < ball.pos.y < side):
        ball.p.y = -ball.p.y

    if not (-side < ball.pos.z < side):
        ball.p.z = -ball.p.z

    # Note the three-way numerical comparisons here, not available in JavaScript:

Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
artydev profile image
artydev

Great , you have gone far :-)

I have been very involved in RapydScript an VPython.
Look at the licence of VPython VPython Lic
My name Salvatore DI DIO, is cited in the third paragraph and I must say
I am a little proud :-)

Collapse
 
algerganez58606 profile image
Alger Ganez

In RapydScript, a variant of Python, you can utilize 3D VPython to create dynamic visualizations, such as a virtual pickleball game. By importing the appropriate libraries and defining the game elements like the court, players, and pickleball, you can simulate the gameplay in a 3D environment. For instance, you can use VPython's 3D objects to represent the pickleball court, rackets, and the pickleball.com itself. Then, by applying physics-based rules and interactions, you can simulate the movement and collisions of the players and the pickleball during gameplay. This integration of 3D VPython and RapydScript enables you to create engaging and interactive pickleball simulations, providing a valuable tool for visualizing and analyzing the game's dynamics and strategies.