Computer Science, asked by srisaiagencies6994, 1 year ago

Write a vpython program that represents the x, y, and z axes by three cylinders of different colors.

Answers

Answered by SyedMahfuj
0
VPython vs GlowScript

GlowScript for those who have used VPython

This document is intended for those who may wish to write their GlowScript programs directly in RapydScript rather than using the VPython definitions.

The capabilities and syntax of GlowScript are based on those of VPython. For those familiar with VPython, this is a summary of the differences between the two environments. For those familiar with Python, it offers a summary of the main differences between the programming languages Python and RapydScript.

VPython uses the OpenGL 3D graphics library; it does not run in a browser. GlowScript uses the closely related WebGL 3D graphics library that is included in major web browsers. See the first page of the GlowScript Help for browser details.

Using the editor in GlowScript

GlowScript uses the ACE text editor. Here is a list of keyboard shortcuts for find, replace, etc.

for loops

In Python, when a for-loop increment is a fraction, you must use the arange() function, like this: "for x in arange(0, 10, 0.1)". In RapydScript you simply say "for x in range(0, 10, 0.1)".

vec instead of vector; vec is required

In VPython you can say b.pos = (1,2,0), and the (1,2,0) is converted to vector(1,2,0). This is not possible in GlowScript, where you must be specific about vector quantitities. Here are the possibilities:

b.pos = vec(1,2,0)    # okay
b.pos = (1,2,0)       # error

A related issue is that in VPython b.x is a shorthand for b.pos.x. The shorthand b.x is not available in GlowScript; you must refer to b.pos.x. Because GlowScript requires that all vectors be explicitly stated to be vectors, the name "vector" has been shortened to "vec".

In VPython, pos, axis, and up are vectors, but size and color are not. In GlowScript size and color are also vector quantities. Here is how to create a non-cubic box with a special color:

box( pos=vec(2,1,0), size=vec(4,2,0.5), color=vec(1,0.6,0)} )

An interesting capability that results from treating color as a vector is that you can blend two colors c1 and c2as (a*c1 + b*c2)/(a+b).

axis, size, radius, and length

In VPython axis and length (size.x) are tied to each other. When you change axis of a VPython object, length is set to the magnitude of axis. Similarly, when you set length, you also set the magnitude of axis.

In GlowScript axis and size are not tied to each other. You can set axis without affecting size, and you can set size without affecting axis. Only in the case of the arrow object is there a special attribute, axis_and_length, for changing both direction and length at the same time.

All basic GlowScript objects (box, cylinder, etc., but not arrow) have size attributes, which is not the case in VPython, and these objects fit into a bounding box given by size. By default, size = vec(1,1,1) except for the ring object where size is vec(0.1,1,1) to give a thickness of 0.1. This means that you can change a box to a sphere or vice versa and they'll fit into the same cube of 1 unit on a side (so the default diameter of a sphere is 1 rather than the default radius being 1). Similarly, you can interchange cones and pyramids and cylinders and helices.

There is no radius or length or height or widthattribute for these objects. Rather, you specify the bounding box with size. A convenient way to specify the diameter D of a sphere is by setting size to D*vec(1,1,1). Note that you can make an ellipsoid from a sphere, or make a cylinder with an elliptical cross section, by making size.y different from size.z.

curve

A GlowScript curve is an array of point objects, each of which has attributes of pos, color, and radius.

See the curve documentation for ways to manipulate the list of points in a curve.

Unlike VPython, you can vary the radius of the cross section along the curve by setting the radius attribute of the point objects. Also, the curve object itself has its own pos, size, axis, and up attributes, so that you can move or rotate or resize the entire curve object quickly and easily.

Animations and rate

VPython animation loops must contain a rate statement to make the animation run at an appropriate rate. In a web browser environment, one must occasionally pause to permit the screen to be redrawn, and programs must be written to run for short amounts of time and then exit, having specified a time in the future when they want to run again. This structure is enabled in GlowScript by you marking in your program where such pauses can occur in your program. This special mark is the word "wait":
.




SyedMahfuj: I had taken help,but
Similar questions