The following program :
from vpython import *
scene.background=color.white*0.7
class revo:
n=100
da=2
a=da*pi/180
def norma(L):
s = vec(0, 0, 0)
for v in L:
s = s + v
return s / len(L)
def __init__(self,min,max,f,col,op):
self.xmin=min
self.xmax=max
self.fonc=f
self.couleur=col
self.opacity=op
self.step=(max-min)/revo.n
def P2D (self):
return [(self.xmin + i * self.step, self.fonc(self.xmin + i * self.step)) for i in range(revo.n + 1)]
def Vertices(self):
Vert=[]
for i in range(0, int(360 / revo.da)):
V = [vertex(pos=vec(x[0], x[1], 0), normal=vec(0, 0, 1)) for x in self.P2D()]
for v in V:
v.rotate(axis=vec(0, 1, 0), angle=revo.a * i, origin=vec(0, 0, 0))
Vert.append(V)
V = [vertex(pos=vec(x[0], x[1], 0), normal=vec(0, 0, 1)) for x in self.P2D()]
Vert.append(V)
return Vert
def Quads(self):
LQ = []
SV=self.Vertices()
for k in range(0, int(360 / revo.da)):
V1 = SV[k]
V2 = SV[k + 1]
for i in range(revo.n):
s1 = V1[i]
s2 = V1[i + 1]
s3 = V2[i + 1]
s4 = V2[i]
LP = [s1.pos, s2.pos, s3.pos, s4.pos]
N = revo.norma(LP)
s1.normal = N
s2.normal = N
s3.normal = N
s4.normal = N
LQ.append(quad(vs=[s1, s2, s3, s4]))
return LQ
def nappe(self):
scene.visible=False
R = compound(self.Quads())
R.color = self.couleur
R.opacity = self.opacity
scene.visible=True
return R
def g(x):
return x*x
R=revo(0,5,g,color.green,0.5)
scene.visible=True
REV=R.nappe()
works very well with installed python and Pycharm editor and represents the surface generated by a curve y=f(x) turning around the y axis. (here a simple parabola y=x^2)
Now if I try it with Trinket
I have the error message
Unexpected identifier 'self'
The same with web vpython, without any line number
If somebody can explain.
T