简体   繁体   English

如何在VPython中为盒子的每个表面着色?

[英]How to color every face of a box in VPython?

I want to make a Rubik's cube with VPython and I've faced a problem in the first stage! 我想用VPython制作一个Rubik's cube,在第一阶段我遇到了一个问题! I want to color every face of a box with a different color but I can't find that! 我想用不同的颜色给盒子的每个表面上色,但是我找不到! In the tutorial you only can color all of the faces of the box with one certain color! 在本教程中,您只能使用一种特定的颜色为盒子的所有面着色!

What should I do? 我该怎么办?

Note: I'm using VPython 7 and Python 3.6 注意:我正在使用VPython 7和Python 3.6

You can try make a box with different color faces out of 6 boxes similar to what is shown in this demo, where the box has red blue and grey faces. 您可以尝试从6个盒子中制作一个具有不同颜色面孔的盒子,类似于此演示中显示的盒子,其中盒子有红色的蓝色和灰色的面孔。

http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Bounce-VPython http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Bounce-VPython

You can also make a compound object out of a number of objects. 您还可以从许多对象中制成一个复合对象。

http://www.glowscript.org/docs/VPythonDocs/compound.html http://www.glowscript.org/docs/VPythonDocs/compound.html

So you can make a compound object called multicolored box made out of six boxes of different colors. 因此,您可以由六个不同颜色的盒子组成一个称为“五彩盒子”的复合对象。

You can also try creating your own box out of triangles and/or quads and color each face. 您也可以尝试根据三角形和/或四边形创建自己的框,并为每个面着色。

http://www.glowscript.org/docs/VPythonDocs/triangle.html http://www.glowscript.org/docs/VPythonDocs/triangle.html

You can also make a box with different colored faces using a compound object made up of 6 pyramid objects each of a different color. 您还可以使用由6个不同颜色的金字塔对象组成的复合对象来制作具有不同颜色面孔的盒子。

def cubelet(....): # a "factory function"
#create a list of the 6 pyramids with different colors; suppose its name is L

L = [pyramid(color=color.red,pos=vec(),axis=vec()), ... ]
return compound(L)

c = cubelet(....)

This "factory function" (a function that returns an object) returns an object that has the usual properties of primitive objects such as box. 此“工厂函数”(返回对象的函数)返回的对象具有原始对象(如box)的通常属性。 You can manipulate this compound object by changing c.pos or c.axis, etc. You can create copies of this cubelet: 您可以通过更改c.pos或c.axis等来操纵此复合对象。可以创建此多维数据集的副本:

c2 = c.clone(pos=vec(10,5,0), size=vec(2,1,0.2))

For pyramid see documentation 对于金字塔,请参阅文档

http://www.glowscript.org/docs/VPythonDocs/pyramid.html http://www.glowscript.org/docs/VPythonDocs/pyramid.html

Just arrange 6 of these in the shape of a box. 只需将其中6个以盒子的形状排列即可。 For compound object see 对于复合对象,请参见

http://www.glowscript.org/docs/VPythonDocs/compound.html http://www.glowscript.org/docs/VPythonDocs/compound.html

to make a compound object out of 6 pyramids. 从6个金字塔中制成一个复合对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM