def __init__(self, parent, orientation, thickness=10, left=None, top=None, width=None, height=None, bg_color=None, fg_color=None, border=None, bd_color=None, bd_width=1): if orientation != "vertical" and orientation != "horizontal": raise TypeError, 'orientation' GUIObject.__init__(self, left, top, width, height) self.orientation = orientation self.bg_color = bg_color self.fg_color = fg_color self.thickness = thickness self.border = border self.bd_color = bd_color self.bd_width = bd_width if not self.bg_color: if self.skin_info_widget.rectangle.bgcolor: self.bg_color = Color(self.skin_info_widget.rectangle.bgcolor) else: self.bg_color = Color(self.osd.default_bg_color) if not self.fg_color: if self.skin_info_widget.font.color: self.fg_color = Color(self.skin_info_widget.font.color) else: self.fg_color = Color(self.osd.default_fg_color) if not self.bd_color: if self.skin_info_widget.rectangle.color: self.bd_color = Color(self.skin_info_widget.rectangle.color) else: self.bd_color = Color(self.osd.default_fg_color) if not self.border: self.border = Border(self, Border.BORDER_FLAT, self.bd_color, self.bd_width)
def __init__(self, c ): self.centroid= c self.borders= [ Border(c,oc) for oc in G.P if c!=oc ] #assert not True in [b.isLine for b in self.borders] for b in self.borders: b.verts= [p for p in list(b.seg) if self.RegionBorder(p)]
def render_xlsx(self, outfd, data): + BoldStyle = Style(font=Font(name='Calibri', + size=11, + bold=True, + italic=False, + vertAlign=None, + underline='none', + strike=False, + color='FFFFFFFF'), + fill=PatternFill(fill_type="solid", + start_color='FF000000', + end_color='FF000000')) + RedStyle = Style(font=Font(name='Calibri', + size=11, + bold=False, + italic=False, + vertAlign=None, + underline='none', + strike=False, + color='FF000000'), + border=Border(left=Side(border_style="thick", + color='FF000000'), + right=Side(border_style="thick", + color='FF000000'), + top=Side(border_style="thick", + color='FF000000'), + bottom=Side(border_style="thick", + color='FF000000'), + diagonal=Side(border_style="thick", + color='FF000000'), + diagonal_direction=0, + outline=Side(border_style="thick", + color='FF000000'), + vertical=Side(border_style="thick", + color='FF000000'), + horizontal=Side(border_style="thick", + color='FF000000')), + fill=PatternFill(start_color = 'FFFF0000', + end_color = 'FFFF0000', + fill_type = 'solid')) + GreenStyle = Style(font=Font(name='Calibri', + size=11, + bold=False, + italic=False, + vertAlign=None, + underline='none', + strike=False, + color='FF000000'), + fill=PatternFill(start_color = "FF00FF00", + end_color = "FF00FF00", + fill_type = "solid")) + wb = Workbook(optimized_write = True)
def Render(screen): global text glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) for block in blockList: if block.doesExist(): block.Render() Border.Render() color = (255, 0, 0) rtext = 'Hello World' text.Render(screen, rtext, 20, 50, 1, color) # image = pygame.image.load("Data/GreenBar.png") # UIImage(image) pygame.display.flip()
def Render(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearColor(0.0, 0.0, 0.5, 1) Border.Render() if not CC.Paused: GG.Render() if CC.next_shape_disp != None: CC.next_shape_disp.color = CC.next_shape.color CC.next_shape_disp.vertices = CC.next_shape.vertices * CC.next_shape_disp.scale CC.next_shape_disp.surfaces = CC.next_shape.surfaces CC.next_shape_disp.normals = CC.next_shape.normals CC.next_shape_disp.Render() SwitchMode('ortho') for i in texts: i.Render() SwitchMode('perspective') pygame.display.flip()
pos1 += vel1 * dt pos2 += vel2 * dt pos3 += vel3 * dt if (i % di == 0): dpos1 = pos1 - pos1_l dpos2 = pos2 - pos2_l dpos3 = pos3 - pos3_l if True == False: pt = Point(pos1.real, pos1.imag) pt.setFill("blue") pt.draw(win) pt = Point(pos2.real, pos2.imag) pt.setFill("red") pt.draw(win) pt = Point(pos3.real, pos3.imag) pt.setFill("green") pt.draw(win) cir1.move(dpos1.real, dpos1.imag) cir2.move(dpos2.real, dpos2.imag) cir3.move(dpos3.real, dpos3.imag) pos1_l = pos1 pos2_l = pos2 pos3_l = pos3 time.sleep(dt) t2 = time.time() print(round(di / ((t2 - t1) * alpha), 4), end='\r') t1 = t2 vel1, pos1 = Border.bounce(vel1, pos1, x, y, dt) vel2, pos2 = Border.bounce(vel2, pos2, x, y, dt) vel3, pos3 = Border.bounce(vel3, pos3, x, y, dt)
def main(lfile): # Initialisation de la fenêtre d'affichage pygame.init() Config.screen = pygame.display.set_mode((Config.screenWidth, Config.screenHeight), HWSURFACE | DOUBLEBUF) pygame.display.set_caption(Config.titre+' ('+Config.name_app+')') # le logo d'hommage ^^ Config.logo, Config.logo_r = Tools.load_png('logo.png') # les bords de la surface de jeu Config.bords = Border.Border() # le fond Config.bg, Config.bg_r = Tools.load_png('bg-editor.png') # on met à l'échelle le fond si besoin if (Config.bg_r.width, Config.bg_r.height) != (Config.bords.width, Config.bords.height): Config.bg = pygame.transform.scale(Config.bg, (Config.bords.width, Config.bords.height)) # la zone d'info Config.zinfo = pygame.Surface([(Config.screenWidth - Config.bords.width), Config.screenHeight]) Config.zinfo.fill(THECOLORS["black"]) # zone de saisie/affichage du fichier (centrée dans la zone d'info) lvx = Config.bords.width + ((Config.screenWidth - Config.bords.width) // 2) - (Config.zinfo.get_rect().width // 2) + 3 Ced.levelname = Gui.InputBox(lvx, Config.screenHeight - 55, Config.zinfo.get_rect().width - 10, 32, 'level-{0:03d}.txt'.format(Config.level)) RazLevel() # Affichage Config.screen.blit(Config.bg, (0, 0)) Config.bords.draw() if Ced.view_grid: DrawGrid() EditorMenu() DrawLevel() pygame.display.flip() if lfile is not None: # fichier à charger Ced.levelname.setText(lfile) LoadLevel() # Initialisation de l'horloge Config.clock = pygame.time.Clock() # Boucle d'évènements while True: event_handler() dt = Config.clock.tick(Config.FPS) / 1000 # affichages Config.screen.blit(Config.bg, (0, 0)) Config.bords.draw() if Ced.view_grid: DrawGrid() EditorMenu() DrawLevel() if Config.bossLevel: Ced.boss_sps.draw() if Ced.boss_brL is not None: Ced.boss_brL.draw() if Ced.boss_brR is not None: Ced.boss_brR.draw() Ced.levelname.draw() if Ced.z_select is not None: Ced.z_select.draw() pygame.display.flip()
def Cut_CleanupBorder( oMeshO, oCurveO, aBorderLocatorVertPos ): # Complex function to perform advanced cleanup of a boolean-cut border. Border is identified by 'oVertLocatorOnBorder', a 3D coordinate of a vertex known to be on that border. (Other border verts are located by walking the boundary edges starting from that known vertex) #=== This call runs in a loop AFTER Cut_ApplyCut() which performs the destructive boolean operation. The maximum amount of code is shifted to occur after boolean as in here we can store meta info in the mesh (such as border vertex groups) without boolean destroying it on the next border creation === sCurveName = oCurveO.name bSymmetryX = oCurveO.data.splines[ 0].use_cyclic_u # Symmetry curves are by definition cyclic (e.g. side curve), non-symmetry (e.g. neck opening) are non-cyclic as their points are mirrored with a mirror modifier nSymmetryIterations = bSymmetryX + 1 # The symmetry cutters (e.g. arms and legs) have this set to two so next big loop runs twice for each side #=== A curve will perform two cuts (for each side of the body) if symmetrical. This loop iterates once or twice depending on symmetry === for nSymmetryRun in range(nSymmetryIterations): sCutName = oCurveO.name if nSymmetryIterations > 1: # The name of the cut is suffixed only for symmetrical cuts (e.g. ArmL and ArmR) sCutName += G.C_SymmetrySuffixNames[nSymmetryRun] vecVertLocatorOnBorderPos = aBorderLocatorVertPos[ sCutName] # Fetch back the position of the locator vert from the curve name print( "\n\n=== Cut_CleanupAfterCut() Generating cloth border '{}' for mesh '{}' ===" .format(sCutName, oMeshO.name)) oMesh = oMeshO.data bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE') bpy.ops.uv.seams_from_islands( ) # Boolean cut even removed UV seams!! Reconstruct them so this call can safely avoid merging faces accross seams bm = bmesh.from_edit_mesh(oMesh) #=== Before the sophisticated border cleanup, cleanup the 'tiny face slivers with default UVs' the boolean operation created on the border of the cut by using their UV information (in default state) === bpy.ops.mesh.select_all(action='DESELECT') oLayUV = bm.loops.layers.uv.active for oFace in bm.faces: # Iterate through all faces and delete those that have 2+ verts with UVs in the 'default' position (either 0 or 1) nNumVertsWithDefaultUvInThisFace = 0 for oLoop in oFace.loops: vecUV = oLoop[ oLayUV].uv # Boolean leaves a ton of tiny sliver faces along the cut edge. Fortunately they all have default UV coordinates and are easy to find! if ((vecUV.x == 0 or vecUV.x == 1) and (vecUV.y == 0 or vecUV.y == 1)): nNumVertsWithDefaultUvInThisFace += 1 if (nNumVertsWithDefaultUvInThisFace >= 2): oFace.select_set(True) bpy.ops.mesh.delete( type='FACE' ) # Delete all 'sliver faces' that boolean created along the new cut border. As a result we'll be left with the border being a loop of (messy) vertices that are far easier to cleanup! bpy.ops.uv.seams_from_islands( mark_seams=True, mark_sharp=False ) # The above deletion of faces with default UVs leaves neighboring edges marked as seams. Recalc seams from UV islands #=== Locate the 'border locator vert' from the 3D coordinates given === (Given as 3D position because of boolean destructive operations made passing by ID or any mesh metainfo impossible) bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='VERT') oVertLocatorOnBorder = None for oVert in bm.verts: ###WEAK: Iteration through verts to find position... Can we find a C function to return closest vert more quickly?? if oVert.co == vecVertLocatorOnBorderPos: oVertLocatorOnBorder = oVert break if oVertLocatorOnBorder == None: raise Exception( "###EXCEPTION: Cut_CleanupBorder() could not find oVertLocatorOnBorder from position {} on border '{}'" .format(vecVertLocatorOnBorderPos, sCurveName)) #=== Obtain the verts of the just-cut border by starting at the 'oVertLocatorOnBorder' locater vert and by 'walking' the mesh along boundary edges === oVertNow = oVertLocatorOnBorder while oVertNow.tag == False: #print("-CleanupAfterCut() finds border vert %5d" % (oVertNow.index)) oVertNow.tag = True # Tag this vert so we know when to stop ###CHECK: We are tagging verts & edges... untag them to prevent other parts of algorithms to screw up? oVertNow.select_set(True) oEdgeOnEdge = None for oEdge in oVertNow.link_edges: if oEdge.is_boundary == True and oEdge.tag == False: oEdgeOnEdge = oEdge if oEdgeOnEdge == None: raise Exception( "###EXCEPTION: Cut_CleanupAfterCut could not iterate through boundary edges while collecting border verts." ) oEdgeOnEdge.tag = True # Tag this edge so we don't traverse it again. oVertNow = oEdgeOnEdge.other_vert(oVertNow) #=== Now that we're past boolean, vertex groups are no longer destroyed so we can (finally) create the heavily-used vertex group for this border (that will also store border lenght information for each border vertex) === oVertGroup_Border = oMeshO.vertex_groups.new( name=G.C_VertGrp_Border + sCutName ) # Create a new vertex group to store only our border verts oMeshO.vertex_groups.active_index = oVertGroup_Border.index bpy.ops.object.vertex_group_assign() #=== With the border verts finally in a vertex group our deletion / insertion of verts along the edge behaves a lot more intuitively without us having to manually insert verts in arrays and such (very useful!) === #=== Even with the removal of tiny sliver polys with default UVs gone, there remains several degenerate polys with all verts on the border! Leaving these would mess up the borders so a simple deletion is appropriate === aVertsBorder = [ oVert for oVert in bm.verts if oVert.select ] ###INFO: vertex_group_assign invalidates any previous BMVert pointer we have! Have to rebuild from selected!! aFacesToDelete = [] for oVert in aVertsBorder: for oFace in oVert.link_faces: # Iterate through the faces of this border vert to delete those with very high angles bAllFaceVertsOnBorder = True for oLoop in oFace.loops: if oLoop.vert.select == False: bAllFaceVertsOnBorder = False break if bAllFaceVertsOnBorder: #print("Face %5d has all verts on border!" % (oFace.index)) aFacesToDelete.append( oFace ) ###WEAK: Does add all polys three times in this array but delete below takes it without complaining... bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE') for oFace in aFacesToDelete: oFace.select_set(True) bpy.ops.mesh.delete( type='FACE' ) # As the selected faces are so small and MUST be right on the border, a simple deletion won't punch holes in the cloth ###CHECK! # #=== Remove the worse of the vertex doubles on the border to help face operation below... A little bit destructive to UVs so only a small amount! === # aVertsBorder = [oVert for oVert in bm.verts if oVert.select] ###INFO: Disabled as our vert inserter / remover code below does this well without UV damage! # bmesh.ops.remove_doubles(bm, verts=aVertsBorder, dist=0.003) #=== Iterate through the edges connected to border vertices, and for those that have one vert on border and one vert in-cloth, select those that are too short for further merging === print("== Finding adjacent verts to border that are too close ==") bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='VERT') bpy.ops.object.vertex_group_select() aVertsBorder = [ oVert for oVert in bm.verts if oVert.select ] ###INFO: vertex_group_assign invalidates any previous BMVert pointer we have! Have to rebuild from selected!! aVertsInClothToDissolve = [] for oVertBorder in aVertsBorder: for oEdgeBorder in oVertBorder.link_edges: oVertInCloth = oEdgeBorder.other_vert(oVertBorder) if oEdgeBorder.is_boundary == False: nEdgeLen = oEdgeBorder.calc_length() if nEdgeLen < 0.007: ###TUNE ###IMPROVE: Parameter!! ###CHECK: Careful with face! Visualize what it does as if too many faces accross a circular area we get faces around the border!! #print("Near-Border Edge Merge=%5d Len=%6.4f" % (oEdgeBorder.index, nEdgeLen)) aVertsInClothToDissolve.append(oVertInCloth) #=== Iterate through the verts that are candidates for dissolve to only dissolve those that are not on seams === bpy.ops.mesh.select_all(action='DESELECT') for oVertInClothToDissolve in aVertsInClothToDissolve: bVertOnSeam = False for oEdge in oVertInClothToDissolve.link_edges: if oEdge.seam: bVertOnSeam = True break if bVertOnSeam == False: oVertInClothToDissolve.select_set(True) bpy.ops.mesh.dissolve_verts( ) ###INFO: Extremely useful method of removing a superflous vert without damaging UV that is far less risky then making faces out of (potentially large amount) of face contiguity bpy.ops.mesh.select_all( action='SELECT' ) ###WEAK ###OPT Could select only around border area for re-tesselation... is this much slower for whole mesh?? bpy.ops.mesh.quads_convert_to_tris( ) ###REVIVE: use_beauty=true # Re-tesselate with beauty to really clean up the geometry around the border. With the above call this yields a substantial improvement #=== With the key re-face operation complete, tag the border verts on seams to prevent UV collapse during the upcoming collapse / subdivide algorithm === bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='VERT') bpy.ops.object.vertex_group_select() for oVertBorder in bm.verts: oVertBorder.tag = False if oVertBorder.select: for oEdge in oVertBorder.link_edges: if oEdge.seam: oVertBorder.tag = True ###WEAK? We set tag but never unset... can damage some other part of some algorithm later?? break #=== With the edge faces much cleaner, now iterate through the edges to subdivide the edges that are too long === bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE') for nEdgeSubDivideIteration in range( 3 ): ###IMPROVE ###CHECK: This half-baked hack of dividing / merging border edges would not have to be if only loop tool's relax could update UVs!! bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.vertex_group_select( ) ###INFO: Relying on vert group to automatically update the selection as we insert / remove elements is a real lifesaver!! (No need to manually insert/remove into arrays as we modify topology!) aEdgesBorder = [oEdge for oEdge in bm.edges if oEdge.select] nLenEdgeAvg = 0.0 nLenEdgeMin = sys.float_info.max nLenEdgeMax = -sys.float_info.max ###INFO: float_info.min is essentially zero! for oEdge in aEdgesBorder: nLenEdge = oEdge.calc_length() nLenEdgeAvg = nLenEdgeAvg + nLenEdge if nLenEdgeMin > nLenEdge: nLenEdgeMin = nLenEdge if nLenEdgeMax < nLenEdge: nLenEdgeMax = nLenEdge nLenEdgeAvg /= len(aEdgesBorder) nLenEdgeCutoffMax = ( nLenEdgeAvg + (nEdgeSubDivideIteration + 3) * nLenEdgeMax ) / ( nEdgeSubDivideIteration + 4 ) ###TUNE: Currently subdividing edges that are ratio of the way between average and max... ###IMPROVE: Calc standard deviation would be more meaningful! #nLenEdgeCutoffMin = (nLenEdgeAvg + (nEdgeSubDivideIteration+6)*nLenEdgeMin) / (nEdgeSubDivideIteration+7) nLenEdgeCutoffMin = (nLenEdgeAvg * 0.66) #print("\n== Edge refine {} calculated avg edge len={:6.4f} min={:6.4f} max={:6.4f} cutmin={:6.4f} cutmax={:6.4f}".format(nEdgeSubDivideIteration , nLenEdgeAvg, nLenEdgeMin, nLenEdgeMax, nLenEdgeCutoffMin, nLenEdgeCutoffMax)) #=== Now that lenghts stats about the border edges has been collected, subdivide those that are on the longer side === aEdgesToSplit = [] aEdgesToMerge = [] for oEdge in aEdgesBorder: nLenEdge = oEdge.calc_length() if nLenEdge > nLenEdgeCutoffMax: #print("+ Subdividing edge {:5d} with length {:6.4f}".format(oEdge.index, nLenEdge)) aEdgesToSplit.append(oEdge) if nLenEdge < nLenEdgeCutoffMin: if oEdge.verts[0].tag == False and oEdge.verts[ 1].tag == False: # Avoid collapsing edges that have a seam vert (would damage UV) #print("- Collapsing edge {:5d} with length {:6.4f}".format(oEdge.index, nLenEdge)) aEdgesToMerge.append( oEdge ) # We append edges to delete in this array so we can merge them all at once (deleting here would change topology of oMesh.edges requiring slow update call at every collapse #=== Collapse and subdivide the edges found in previous loop. Done separately for efficiency === bmesh.ops.subdivide_edges(bm, edges=aEdgesToSplit, cuts=1, smooth=1.0) bmesh.ops.collapse(bm, edges=aEdgesToMerge) #=== Smooth the border's edge with Loop Tool's brilliant implementation of edge relax. This implementation does NOT pull border verts toward in-cloth verts as is the only way we have to really clean border! print( "== Border smoothing ===" ) ###IMPROVE: Regular=True with lots of iterations really evens out border but messes up UV... an improvement would be to do it but then adjust UVs after! bmesh.update_edit_mesh(oMesh, tessface=True, destructive=True) bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='VERT') bpy.ops.object.vertex_group_select() Border.Border_Smooth( ) ###WEAK: Can substantially push verts around and introduces slight damage along the border. Adjusting the UVs as vertex are slid along the border would fix this (hopefully LoopTools author can fix his call for this!) #=== Re-tesselate the border === ###CHECK: Needed here? print("== Final tesselation of border ==") bpy.ops.mesh.select_more( ) #Select one more of verts so we can tesselate the polys of the border bpy.ops.mesh.quads_convert_to_tris() ###REVIVE: use_beauty=True bpy.ops.mesh.select_all(action='DESELECT') #=== At this point the border's UV has a few disjointed UVs. Iterate through all border verts to weld the UVs === print("== UV Weld ==") bpy.ops.object.vertex_group_select( ) ###INFO: Above calls results in border selection with missing vertices (where they were inserted) but curiously these are in the vertex group! So select the vertex group to easily obtain latest collection of border verts! aVertsBorder = [oVert for oVert in bm.verts if oVert.select] for oVert in aVertsBorder: bVertHasSeam = False for oEdge in oVert.link_edges: # Avoid collapsing UVs on verts connected to edges that are seams if oEdge.seam: bVertHasSeam = True break if bVertHasSeam == False: bmesh.ops.average_vert_facedata(bm, verts=[ oVert ]) ###INFO: This is the call to merge UVs at a single vert #=== We're done smoothing and preparing the border. Now store length information into our vertex group so that no matter how cloth is deformed during simulation we can recreate the border as originally designed === #=== Obtain the collection of selected edges for iteration and clear the tag flag we need to use in next loop === aVertsBorder = [oVert for oVert in bm.verts if oVert.select] for oVertBorder in aVertsBorder: # First clear the tag flag of all border verts to indicate they haven't been traversed oVertBorder.tag = False for oEdge in oVertBorder.link_edges: ###WEAK: Do we need to untag at end of function again?? oEdge.tag = False # Previous code tagged the edges, seize the occasion to untag them #=== Iterate through the border's base edges to store the cumulative lenght in its associated vertex group === print("== Storing border length information ==") oVertNow = aVertsBorder[ 0] ###IMPROVE: Choose vert from spacial positioning instead of this random occurence oVertFirst = oVertNow # Remember what vert we started so we know when to stop oLayVertGrps = bm.verts.layers.deform.active ###INFO: From technique at http://www.blender.org/documentation/blender_python_api_2_67_1/bmesh.html nLenBorderCumulative = 0.0 while True: oVertNow[oLayVertGrps][ oVertGroup_Border. index] = nLenBorderCumulative / G.C_BorderLenIntoVertGrpWeightRatio oVertNext = None for oEdgeNow in oVertNow.link_edges: if oEdgeNow.select == True: ###IMPROVE: Would be better by check to is_boundary or is selected safer?? oVertOther = oEdgeNow.other_vert(oVertNow) #=== Calculate the angle between the edge being considered and the cross vector between the vert normal and the edge tangent -> Used to always traverse the border in the direction of the cross vector as border UV application can only service that direction vecVertNormal = oVertNow.normal vecEdgeTangent = oEdgeNow.calc_tangent( oEdgeNow.link_loops[0] ) # Boundary edges only have one loop vecCross = vecVertNormal.cross(vecEdgeTangent) vecEdge = oVertOther.co - oVertNow.co nAngleEdgeToCross = degrees(vecEdge.angle(vecCross)) if nAngleEdgeToCross < 90: # If the edge being considered is going in the opposite direction of the cross vector we ignore it as border UVs can only create seamless UV mapping going toward the cross vector #print("- Vert {:5d} has angle {:8.4f}".format(oVertNow.index, nAngleEdgeToCross)) oVertNext = oVertOther break if oVertNext == None: raise Exception( "###EXCEPTION: Cut_CleanupBorder() could not iterate through entire border loop while storing border length." ) nEdgeLength = oEdgeNow.calc_length() #print("- BorderLen: Vert %6d of length %6.4f at %6.4f" % (oVertNow.index, nEdgeLength, nLenBorderCumulative)) nLenBorderCumulative += nEdgeLength oVertNow = oVertNext oVertNow.tag = True if oVertNow == oVertFirst: # If we're back at the starting vert, store the last (ie. maximum) lenght in start vert and exit #print("- BorderLen: Vert %6d at len %6.4f (FIRST)" % (oVertNow.index, nLenBorderCumulative)) oVertNow[oLayVertGrps][ oVertGroup_Border. index] = nLenBorderCumulative / G.C_BorderLenIntoVertGrpWeightRatio break #=== Cleanup and return mesh to edit mode === print( "----- Cut_CleanupBorder() finishes on border '{}' for mesh '{}' -----" .format(sCutName, oMeshO.name)) bpy.ops.mesh.select_all(action='DESELECT') bmesh.update_edit_mesh(oMesh, tessface=True, destructive=True)
class Scrollbar(GUIObject): """ left x coordinate. Integer top y coordinate. Integer width Integer height Integer bg_color Background color (Color) fg_color Foreground color (Color) """ def __init__(self, parent, orientation, thickness=10, left=None, top=None, width=None, height=None, bg_color=None, fg_color=None, border=None, bd_color=None, bd_width=1): if orientation != "vertical" and orientation != "horizontal": raise TypeError, 'orientation' GUIObject.__init__(self, left, top, width, height) self.orientation = orientation self.bg_color = bg_color self.fg_color = fg_color self.thickness = thickness self.border = border self.bd_color = bd_color self.bd_width = bd_width if not self.bg_color: if self.skin_info_widget.rectangle.bgcolor: self.bg_color = Color(self.skin_info_widget.rectangle.bgcolor) else: self.bg_color = Color(self.osd.default_bg_color) if not self.fg_color: if self.skin_info_widget.font.color: self.fg_color = Color(self.skin_info_widget.font.color) else: self.fg_color = Color(self.osd.default_fg_color) if not self.bd_color: if self.skin_info_widget.rectangle.color: self.bd_color = Color(self.skin_info_widget.rectangle.color) else: self.bd_color = Color(self.osd.default_fg_color) if not self.border: self.border = Border(self, Border.BORDER_FLAT, self.bd_color, self.bd_width) def set_handle_position(self, pos): self.handle_position = pos def get_handle_rect(self): (a, b, c) = self.parent.get_view_percent(self.orientation) logger.log( 9, 'SB: a,b,c = %s,%s,%s', a, b, c) if a == 100 or b == 100 or c == 100: return self.get_rect() if self.orientation == 'vertical': fg_width = self.width fg_height = b * self.height / 100 # fg_x = self.left fg_x = 0 # fg_y = self.top + (a * self.height / 100) fg_y = (a * self.height / 100) else: fg_width = b * self.width / 100 fg_height = self.height # fg_x = self.left + (a * self.width / 100) fg_x = (a * self.width / 100) # fg_y = self.top fg_y = 0 logger.log( 9, 'SB: handle_rect = %s,%s,%s,%s', fg_x, fg_y, fg_width, fg_height) return (fg_x, fg_y, fg_width, fg_height) def get_handle_size(self): (a, b, c, d) = self.get_handle_rect() # print 'SB: get_handle_size: c,d="%s,%s"' % (c, d) return (c, d) def get_handle_coords(self): (a, b, c, d) = self.get_handle_rect() # print 'SB: get_handle_coords: a,b="%s,%s"' % (a, b) return (a, b) def calculate_position(self): if self.orientation == 'vertical': self.width = self.thickness self.height = self.parent.height if self.parent.show_h_scrollbar: self.height = self.height - self.parent.h_scrollbar.thickness self.left = self.parent.width - self.width # self.top = self.parent.top self.top = 0 else: self.width = self.parent.width if self.parent.show_v_scrollbar: self.width = self.width - self.parent.v_scrollbar.thickness self.height = self.thickness # self.left = self.parent.left self.left = 0 self.top = self.parent.height - self.height if isinstance(self.border, Border): # self.border.set_position(self.left, self.top) self.border.set_position(0, 0) self.border.width = self.width self.border.height = self.height if config.DEBUG > 1: print 'SB: parent_rect = %s,%s,%s,%s' % (self.parent.left, self.parent.top, self.parent.width, self.parent.height) print 'SB: self_rect = %s,%s,%s,%s' % (self.left, self.top, self.width, self.height) def _draw(self): """ The actual internal draw function. """ # if not self.width or not self.height: # raise TypeError, 'Not all needed variables set.' self.calculate_position() bg_c = self.bg_color.get_color_sdl() bg_a = self.bg_color.get_alpha() self.surface = self.osd.Surface(self.get_size(), 0, 32) self.surface.fill(bg_c) self.surface.set_alpha(bg_a) fg_c = self.fg_color.get_color_sdl() logger.log( 9, 'SB: fg_c = %s,%s,%s,%s', fg_c) fg_a = self.fg_color.get_alpha() fg_box = self.osd.Surface(self.get_handle_size(), 0, 32) fg_box.fill(fg_c) fg_box.set_alpha(fg_a) self.surface.blit(fg_box, self.get_handle_coords()) if self.border: self.border.draw() logger.log( 9, 'SB::_draw: pos=%s,%s', self.left, self.top) self.blit_parent()
class Scrollbar(GUIObject): """ left x coordinate. Integer top y coordinate. Integer width Integer height Integer bg_color Background color (Color) fg_color Foreground color (Color) """ def __init__(self, parent, orientation, thickness=10, left=None, top=None, width=None, height=None, bg_color=None, fg_color=None, border=None, bd_color=None, bd_width=1): if orientation != "vertical" and orientation != "horizontal": raise TypeError, 'orientation' GUIObject.__init__(self, left, top, width, height) self.orientation = orientation self.bg_color = bg_color self.fg_color = fg_color self.thickness = thickness self.border = border self.bd_color = bd_color self.bd_width = bd_width if not self.bg_color: if self.skin_info_widget.rectangle.bgcolor: self.bg_color = Color(self.skin_info_widget.rectangle.bgcolor) else: self.bg_color = Color(self.osd.default_bg_color) if not self.fg_color: if self.skin_info_widget.font.color: self.fg_color = Color(self.skin_info_widget.font.color) else: self.fg_color = Color(self.osd.default_fg_color) if not self.bd_color: if self.skin_info_widget.rectangle.color: self.bd_color = Color(self.skin_info_widget.rectangle.color) else: self.bd_color = Color(self.osd.default_fg_color) if not self.border: self.border = Border(self, Border.BORDER_FLAT, self.bd_color, self.bd_width) def set_handle_position(self, pos): self.handle_position = pos def get_handle_rect(self): (a, b, c) = self.parent.get_view_percent(self.orientation) _debug_('SB: a,b,c = %s,%s,%s' % (a, b, c), 2) if a == 100 or b == 100 or c == 100: return self.get_rect() if self.orientation == 'vertical': fg_width = self.width fg_height = b * self.height / 100 # fg_x = self.left fg_x = 0 # fg_y = self.top + (a * self.height / 100) fg_y = (a * self.height / 100) else: fg_width = b * self.width / 100 fg_height = self.height # fg_x = self.left + (a * self.width / 100) fg_x = (a * self.width / 100) # fg_y = self.top fg_y = 0 _debug_( 'SB: handle_rect = %s,%s,%s,%s' % (fg_x, fg_y, fg_width, fg_height), 2) return (fg_x, fg_y, fg_width, fg_height) def get_handle_size(self): (a, b, c, d) = self.get_handle_rect() # print 'SB: get_handle_size: c,d="%s,%s"' % (c, d) return (c, d) def get_handle_coords(self): (a, b, c, d) = self.get_handle_rect() # print 'SB: get_handle_coords: a,b="%s,%s"' % (a, b) return (a, b) def calculate_position(self): if self.orientation == 'vertical': self.width = self.thickness self.height = self.parent.height if self.parent.show_h_scrollbar: self.height = self.height - self.parent.h_scrollbar.thickness self.left = self.parent.width - self.width # self.top = self.parent.top self.top = 0 else: self.width = self.parent.width if self.parent.show_v_scrollbar: self.width = self.width - self.parent.v_scrollbar.thickness self.height = self.thickness # self.left = self.parent.left self.left = 0 self.top = self.parent.height - self.height if isinstance(self.border, Border): # self.border.set_position(self.left, self.top) self.border.set_position(0, 0) self.border.width = self.width self.border.height = self.height if config.DEBUG > 1: print 'SB: parent_rect = %s,%s,%s,%s' % ( self.parent.left, self.parent.top, self.parent.width, self.parent.height) print 'SB: self_rect = %s,%s,%s,%s' % (self.left, self.top, self.width, self.height) def _draw(self): """ The actual internal draw function. """ # if not self.width or not self.height: # raise TypeError, 'Not all needed variables set.' self.calculate_position() bg_c = self.bg_color.get_color_sdl() bg_a = self.bg_color.get_alpha() self.surface = self.osd.Surface(self.get_size(), 0, 32) self.surface.fill(bg_c) self.surface.set_alpha(bg_a) fg_c = self.fg_color.get_color_sdl() _debug_('SB: fg_c = %s,%s,%s,%s' % fg_c, 2) fg_a = self.fg_color.get_alpha() fg_box = self.osd.Surface(self.get_handle_size(), 0, 32) fg_box.fill(fg_c) fg_box.set_alpha(fg_a) self.surface.blit(fg_box, self.get_handle_coords()) if self.border: self.border.draw() _debug_('SB::_draw: pos=%s,%s' % (self.left, self.top), 2) self.blit_parent()
def main(): # Initialisation de la fenêtre d'affichage pygame.init() Config.screen = pygame.display.set_mode( (Config.screenWidth, Config.screenHeight), HWSURFACE | DOUBLEBUF) pygame.display.set_caption(Config.titre) # le son pygame.mixer.init(44100, -16, 2, 4096) # le logo d'hommage ^^ Config.logo, Config.logo_r = Tools.load_png('logo.png') # les bords de la surface de jeu Config.bords = Border.Border() # le niveau Level.LoadLevel(Config.level) if Config.bossLevel: # niveau d'un boss Boss.doBossLevel() else: # le fond Tools.InitBG() Tools.ReadHighScore() # la zone d'info Config.zinfo = pygame.Surface([(Config.screenWidth - Config.bords.width), Config.screenHeight]) Config.zinfo.fill(THECOLORS["black"]) # Le joueur (la raquette) Config.player = Player.Bat('player-bat-02.png', 'player-bat-02-L.png', 'player-bat-02-S.png') # La première balle Ball.BallInit() # les ennemis Enemys.init() # les sons Tools.InitSounds() pygame.mixer.music.set_volume((Config.Volume / 100)) # Affichage Config.screen.blit(Config.bg, (0, 0)) Config.bords.draw() Tools.MsgInfo() Level.DrawLevel() Config.player.draw() Ball.Ballsdraw() Enemys.draw() pygame.display.flip() # Initialisation de l'horloge Config.clock = pygame.time.Clock() # timer user pour la màj des fps (déclenché 1 fois/seconde) pygame.time.set_timer(USEREVENT, 1000) # timer pour la génération des ennemis (déclenché toutes les 10s) pygame.time.set_timer((USEREVENT + 1), 10000) # timer pour la génération des bombes et missiles du boss (déclenché toutes les 5s) pygame.time.set_timer((USEREVENT + 2), 5000) Config.Sounds['intro'].play() # Boucle d'évènements while True: event_handler() dt = Config.clock.tick(Config.FPS) / 1000 Ball.Ballsupdate() if Config.Perdu: Config.life -= 1 if Config.life > 0: Tools.MsgCenter("Oops...", 28, Config.zinfo.get_rect().centery, "cyan", True) pygame.display.flip() # petite tempo pygame.time.wait(1500) Config.Perdu = False Bonus.initBonus() Config.player.reset() Ball.BallInit() else: # perdu... Tools.GameOver() else: if Config.bossLevel: if Config.boss.update(): Config.life -= 1 if Config.life <= 0: # perdu... Tools.GameOver() Config.player.update() Bonus.update() Enemys.update() if Config.bossLevel: if Config.boss.isDead: # niveau suivant Tools.MsgCenter("!! Bravo !!", 28, Config.zinfo.get_rect().centery, "blue", True) pygame.display.flip() # petite tempo pygame.time.wait(5000) Tools.NextLevel() if Level.FinishedLevel(): # niveau suivant Tools.MsgCenter("Level UP!", 28, Config.zinfo.get_rect().centery, "green", True) pygame.display.flip() # petite tempo pygame.time.wait(1500) Tools.NextLevel() # affichages Config.screen.blit(Config.bg, (0, 0)) Config.bords.draw() Tools.MsgInfo() Level.DrawLevel() Config.player.draw() Ball.Ballsdraw() Bonus.draw() Bonus.drawAdds() Enemys.draw() pygame.display.flip()
def Render(screen): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) GamePlay.Render(screen) Border.Render(screen) pygame.display.flip()