def _common_init(self, **keys): """ """ if len(keys["points"]) < 3: raise Exception("ACenterPolygon: Too few points in..") self._indexes = [] self._points = pgl.Point3Array([pgl.Vector3()] + keys["points"]) for i in xrange(1, len(keys["points"])): self._points[0] += self._points[i] self._indexes.append(pgl.Index([0, i, i + 1])) self._points[0] += self._points[len(keys["points"])] self._indexes.append(pgl.Index([0, len(keys["points"]), 1])) self._points[0] = self._points[0] / len(keys["points"]) self._indexes = pgl.IndexArray(self._indexes)
def genericLeaf(allo_length, allo_surf, **kwds): if kwds.has_key('surface'): surface = kwds['surface'] length = math.sqrt(surface / (allo_length*allo_surf) ) else: length = kwds.get('length', 1) alpha = kwds.get('alpha', 0) color = kwds.get('color', __niceGreen) step = length/10. x = array(arange(step,length,step)) #begin and end are specific y = (-3.0*allo_length*allo_surf) * (x**2/length - x) cos = math.cos(math.radians(alpha/2.0)) sin = math.sin(math.radians(alpha/2.0)) list = [] idxList = [] for i in range(len(x)): list.append(pgl.Vector3(x[i],0,0)) list.append(pgl.Vector3(x[i],y[i]*cos,y[i]*sin)) list.append(pgl.Vector3(x[i],-y[i]*cos,y[i]*sin)) list.append(pgl.Vector3(0,0,0)) list.append(pgl.Vector3(length,0,0)) for i in range(len(x) -1): idxList.append(pgl.Index(3*(i+1), 3*(i+1)+1, 3*i+1, 3*i )) idxList.append(pgl.Index(3*i+2, 3*(i+1)+2, 3*(i+1), 3*i )) idxList.append(pgl.Index(0, 1, len(list)-2 )) idxList.append(pgl.Index(2, 0, len(list)-2 )) idxList.append(pgl.Index(3*(len(x)-1)+1, 3*(len(x)-1), len(list)-1 )) idxList.append(pgl.Index(3*(len(x)-1), 3*(len(x)-1)+2, len(list)-1 )) p3r = pgl.Point3Array(list) ir = pgl.IndexArray(idxList) fs = pgl.FaceSet(p3r, ir) return pgl.Shape(fs, color)
def mangoLeaf(length = 1, alpha=0, color = __niceGreen): x = array(arange(0.1,length,0.1)) y = (-3/(length*5.)) * (x**2/length - x) cos = math.cos(math.radians(alpha/2.0)) sin = math.sin(math.radians(alpha/2.0)) list = [] idxList = [] for i in range(len(x)): list.append(pgl.Vector3(x[i],0,0)) list.append(pgl.Vector3(x[i],y[i]*cos,y[i]*sin)) list.append(pgl.Vector3(x[i],-y[i]*cos,y[i]*sin)) list.append(pgl.Vector3(0,0,0)) list.append(pgl.Vector3(length,0,0)) for i in range(len(x) -1): idxList.append(pgl.Index(3*(i+1), 3*(i+1)+1, 3*i+1, 3*i )) idxList.append(pgl.Index(3*i+2, 3*(i+1)+2, 3*(i+1), 3*i )) #idxList.append(pgl.Index(3*i,3*i+1,3*(i+1)+1, 3*(i+1))) #idxList.append(pgl.Index(3*i,3*(i+1),3*(i+1)+2,3*i+2)) idxList.append(pgl.Index(0, 1, len(list)-2 )) idxList.append(pgl.Index(2, 0, len(list)-2 )) idxList.append(pgl.Index(3*(len(x)-1)+1, 3*(len(x)-1), len(list)-1 )) idxList.append(pgl.Index(3*(len(x)-1), 3*(len(x)-1)+2, len(list)-1 )) #idxList.append(pgl.Index(len(list)-2, 1, 0)) #idxList.append(pgl.Index(len(list)-2, 0, 2)) #idxList.append(pgl.Index(len(list)-1, 3*(len(x)-1), 3*(len(x)-1)+1)) #idxList.append(pgl.Index(len(list)-1, 3*(len(x)-1)+2, 3*(len(x)-1))) #p3r = pgl.Point3Array(list) #ir = pgl.IndexArray(idxList) fs = pgl.FaceSet(list,idxList) return pgl.Shape(fs, color)