triangles in Javascript/Html

30 views
Skip to first unread message

EDUCATIA SUPERLATIV

unread,
Nov 14, 2025, 10:13:30 AMNov 14
to VPython-users
Hi VPython-users,

I did try to make a canvas in JavaScript/HTML to display a simple triangle how is defined in the docs and demo, but was not successful.

The definitions of the vertex and triangles are probably more different then is presented in Help.

Any help please with an example?

Best regards,
Ciprian

John

unread,
Nov 14, 2025, 1:29:49 PMNov 14
to VPython-users
Have a look at the webvpython example programs at this link

https://glowscript.org/#/user/GlowScriptDemos/folder/Examples/

Click on "run" to run the demo program in the browser and "view" to view the source code for the program.

https://glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Plot3D

Click on  View this program   to view the source code. 

Also click on  Share or export this program    for instructions on how to share the program. It also provides instructions on how you can embed it in a web page as javascript.

The same vpython demo programs that can be run under python 3 can be found on github here.

https://github.com/vpython/vpython-jupyter/tree/master/Demos

John


EDUCATIA SUPERLATIV

unread,
Nov 14, 2025, 3:37:50 PMNov 14
to VPython-users
Hi John,
I did study all examples, including Plot3D, but there is a use of quad and in a complicated form of JS-scripting.
No other example uses a triangle.

John

unread,
Nov 14, 2025, 4:58:17 PMNov 14
to VPython-users
Searching for triangle in this forum returned this question and answer.

https://groups.google.com/g/vpython-users/c/O4eHEcIZt9U/m/iMinOifZAwAJ

It contains triangle example. Is this what you are looking for?

John

unread,
Nov 14, 2025, 5:05:36 PMNov 14
to VPython-users
The green pyramid is made out of 4 triangles and a quad. The red pyramid is made with the vpython pyramid object.

https://glowscript.org/#/user/johncoady/folder/AI/program/triangle

EDUCATIA SUPERLATIV

unread,
Nov 19, 2025, 6:38:30 AMNov 19
to VPython-users
[SOLVED]

Actually was simple. Here is the code in JS:
let v0 = vertex({pos:vec..., color:color.yellow})
let v1 = vertex({pos:vec..., color:color.yellow})
let v2 = vertex({pos:vec..., color:color.yellow})
triangle({v0:v0, v1:v1, v2:v2})
The error that I made was to not add all the necessary info and the right sentence for the command!!!
Reply all
Reply to author
Forward
0 new messages