def update_sections(self): self.update_widths() self.update_depths() bars_x = [] for i in range(0, len(self.layers_x_top)): bars_x.extend(self.layers_x_top[i].create_bars( self.steel, self.width_x, self.depths_x_top[i])) for i in range(0, len(self.layers_x_bot)): bars_x.extend(self.layers_x_bot[i].create_bars( self.steel, self.width_x, self.depths_x_bot[i])) bars_y = [] for i in range(0, len(self.layers_y_top)): bars_y.extend(self.layers_y_top[i].create_bars( self.steel, self.width_y, self.depths_y_top[i])) for i in range(0, len(self.layers_y_bot)): bars_y.extend(self.layers_y_bot[i].create_bars( self.steel, self.width_y, self.depths_y_bot[i])) self.section_x = section.Section( self.concrete, shape.Rectangle(self.width_x, self.thickness), bars_x) self.section_x.concrete_factor = self.concrete_factor self.section_x.steel_factor = self.steel_factor self.section_y = section.Section( self.concrete, shape.Rectangle(self.width_y, self.thickness), bars_y) self.section_y.concrete_factor = self.concrete_factor self.section_y.steel_factor = self.steel_factor
def test_rect_section(): #create materials conc = material.Concrete(30) steel = material.Steel(500, 200000) #define profile profile = shape.Rectangle(500, 700) bars = [ #section.Bar(steel,section.Bar.diam_20M, 65), #section.Bar(steel,section.Bar.diam_20M, 65), #section.Bar(steel,section.Bar.diam_20M, 65), #section.Bar(steel,section.Bar.diam_20M, 65), section.Bar(steel, section.Bar.diam_30M, 635), section.Bar(steel, section.Bar.diam_30M, 635), section.Bar(steel, section.Bar.diam_30M, 635), section.Bar(steel, section.Bar.diam_30M, 635) ] sec = section.Section(conc, profile, bars) #set material factors sec.concrete_factor = 0.65 sec.steel_factor = 0.85 #calc peak axial strength #print(sec.calc_peak_axial_strength()) #print MN Chart file = open('mn.csv', 'w') for M, N in sec.calc_M_N().entries: file.write(str(M) + "," + str(N) + "\n")
def _set_geometry(self, data): offset = [float(data['PADXOFF']), float(data['PADYOFF'])] width = float(data['PADWIDTH']) height = float(data['PADHGHT']) if data["PADSHAPE1"] == "CIRCLE": self.geometry = shape.Circle( [ offset[0] - width / 2, offset[1] ], offset, False ) elif data["PADSHAPE1"] == "RECTANGLE" or data["PADSHAPE1"] == "SQUARE": self.geometry = shape.Rectangle( [ offset[0] - width / 2, offset[1] - height / 2 ], [ offset[0] + width / 2, offset[1] + height / 2 ] ) elif data["PADSHAPE1"] == "OBLONG_X": self.geometry = shape.OblongX( [ offset[0] - width / 2, offset[1] - height / 2 ], [ offset[0] + width / 2, offset[1] + height / 2 ] ) elif data["PADSHAPE1"] == "OBLONG_Y": self.geometry = shape.OblongY( [ offset[0] - width / 2, offset[1] - height / 2 ], [ offset[0] + width / 2, offset[1] + height / 2 ] ) else: pass
D. 세변이 3(밑변), 4, 5이고, 높이가 4인 삼각형을 정의하여 t에 저장한다. E. c의 면적과 둘레를 출력한다. F. r의 면적과 둘레를 출력한다. G. t의 면적과 둘레를 출력한다. H. t의 변들을 리스트로 받아 출력한다. I. 리스트 l을 정의하여, s, c와 r을 요소로 추가한다. J. l의 각 요소에 대해, 해당 요소를 출력하고, 면적과 둘레를 계산하여 출력한다. K. for문 안에서 테스트: getRadius() 메쏘드를 수행한다.(오류 발생) """ # 필요한 module을 수입하기 import shape #shape.py에 정의된 클래스, 함수등을 수입해서 사용하겠다는 의미 확장자는 붙이지 않는다. s = shape.Shape() #shape.의 의미는 "shape.py"에서 정의된 의미 # shape가 shape.py에 정의된 클래스임을 의미 c = shape.Circle(5) r = shape.Rectangle(5, 10) t = shape.Triangle(3, 4, 5, 4) print(s) print(c) print(r) print(t) print(t.getSides()) l = [] l.append(s) l.append(c) l.append(r) for i in range(0, 3): print(l[i]) #getRadius() #오류가 나므로 주석 처리
import shape as sh # 建立Circle、Rectangle和Triangle類別的物件 c = sh.Circle(10) r = sh.Rectangle(5, 2) t = sh.Triangle(8, 3) # 把物件加入Tuple資料組 shapes = c, r, t # 用For迴圈顯示每一個物件的內容和面積 for s in shapes: s.show_shape_info() print('面積:' + str(s.get_area()))
F. r의 면적과 둘레를 출력한다. G. t의 면적과 둘레를 출력한다. H. t의 변들을 리스트로 받아 출력한다. l. 리스트 l을 정의하여,s,c,r,t을 요소로 추가한다. j. l의 각 요소에 대해, 해당 요소를 출력하고, 면적과 둘레를 계산하여 출력한다. *for문 안에서 테스트: getRadius()메쏘드를 수행한다. (오류발생, 이유 생각해보기) """ #필요한 모듈을 수입하기 import shape # Shape.py에 정의된 클래스, 함수 등을 수입해서 사용하겠다는 의미 s = shape.Shape( ) # Shape를 s변수에 저장 # shape.의 의미는 "shape.py에서 정의된" 을 의미. .py 확장자는 붙이지 않는다. #Shape가 shape.py에 정의된 클래스임을 의미. c = shape.Circle(5) # Circle을 c변수에 저장 r = shape.Rectangle(5, 10) # Rectangle을 r 변수에 저장 t = shape.Triangle(3, 4, 5, 4) # Triangle을 t 변수에 저장 print("c의 면적: %d " % (c.area())) # c의 면적과 둘레 출력 print("c의 둘레: %d " % (c.perimeter())) print("r의 면적: %d " % (r.area())) # r의 면적과 둘레 출력 print("r의 둘레: %d " % (r.perimeter())) print("t의 면적: %d " % (t.area())) # t의 면적과 둘레 출력 print("t의 둘레: %d " % (t.perimeter())) print(t.getSide()) # t의 변들을 리스트로 받아 출력 l = [] # 빈 리스트 l 정의 l.append(s) # ㅣ에 차례대로 s,c,r,t를 요소로 추가 l.append(c) l.append(r) l.append(t) print("==== 리스트 해당요소 출력 ====") # 리스트 해당요소 출력하기 for i in range(0, len(l)): # for문을 0부터 l의 요소만큼 돌면서
def main(): s = shape.Square(5) print(s.area()) r = shape.Rectangle(5, 10) print(r.perimeter())
def get_level_objects(level: int): if (level == 0): return (glm.vec2(100, 100), [ e.StaticObstacle(glm.vec2(550, 350), [shape.Rectangle(glm.vec2(550, 350), 1100, 10)]) ]) elif (level == 1): return (glm.vec2(1100, 100), [ e.MovingSinObstacle(glm.vec2(600, 25), [shape.Rectangle(glm.vec2(600, 25), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 1), e.MovingSinObstacle(glm.vec2(600, 75), [shape.Rectangle(glm.vec2(600, 75), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 2), e.MovingSinObstacle(glm.vec2(600, 125), [shape.Rectangle(glm.vec2(600, 125), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 3), e.MovingSinObstacle(glm.vec2(600, 175), [shape.Rectangle(glm.vec2(600, 175), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 4), e.MovingSinObstacle(glm.vec2(600, 225), [shape.Rectangle(glm.vec2(600, 225), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 5), e.MovingSinObstacle(glm.vec2(600, 275), [shape.Rectangle(glm.vec2(600, 275), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 6), e.MovingSinObstacle(glm.vec2(600, 325), [shape.Rectangle(glm.vec2(600, 325), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 7), e.MovingSinObstacle(glm.vec2(600, 375), [shape.Rectangle(glm.vec2(600, 375), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 8), e.MovingSinObstacle(glm.vec2(600, 425), [shape.Rectangle(glm.vec2(600, 425), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 9), e.MovingSinObstacle(glm.vec2(600, 475), [shape.Rectangle(glm.vec2(600, 475), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 10), e.MovingSinObstacle(glm.vec2(600, 525), [shape.Rectangle(glm.vec2(600, 525), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 11), e.MovingSinObstacle(glm.vec2(600, 575), [shape.Rectangle(glm.vec2(600, 575), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 12), e.MovingSinObstacle(glm.vec2(600, 625), [shape.Rectangle(glm.vec2(600, 625), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 13), e.MovingSinObstacle(glm.vec2(600, 675), [shape.Rectangle(glm.vec2(600, 675), 10, 50)], glm.vec2(400, 0), delta_total=(6.28 / 14) * 14), ]) elif (level == 2): return (glm.vec2(100, 650), [ e.StaticObstacle(glm.vec2(200, 595), [shape.Rectangle(glm.vec2(200, 595), 400, 10)]), e.StaticObstacle(glm.vec2(400, 300), [shape.Rectangle(glm.vec2(400, 300), 10, 600)]), e.StaticObstacle(glm.vec2(500, 400), [shape.Rectangle(glm.vec2(500, 400), 10, 600)]), e.StaticObstacle(glm.vec2(600, 300), [shape.Rectangle(glm.vec2(600, 300), 10, 600)]), e.MovingSinObstacle(glm.vec2(650, 350), [ shape.Rectangle(glm.vec2(650, 350 + 25), 100 - 12, 10), shape.Rectangle(glm.vec2(650, 350 - 25), 100 - 12, 10) ], glm.vec2(0, 300), delta_multiplier=0.5), e.StaticObstacle(glm.vec2(700, 400), [shape.Rectangle(glm.vec2(700, 400), 10, 600)]), e.StaticObstacle(glm.vec2(800, 300), [shape.Rectangle(glm.vec2(800, 300), 10, 600)]), e.StaticObstacle(glm.vec2(900, 400), [shape.Rectangle(glm.vec2(900, 400), 10, 600)]) ]) elif (level == 3): return ( glm.vec2(100, 350 / 2), [ e.StaticObstacle( glm.vec2(550, 350), [shape.Rectangle(glm.vec2(550, 350), 1100, 10)]), e.MovingSinObstacle( glm.vec2(1150, 350), shape.create_cross(glm.vec2(1150, 350), 100), glm.vec2(0.0, 100.0)), # h, h e.MovingCircleObstacle( glm.vec2(550, 350 / 2), shape.create_h(glm.vec2(550, 350 / 2), 50), (350 / 2) - 25), e.MovingCircleObstacle( glm.vec2(550, 350 / 2), shape.create_h(glm.vec2(550, 350 / 2), 50), (350 / 4) - 25), # h h h h h h h h e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 1), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 2), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 3), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 4), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 5), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 6), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 7), e.MovingCircleObstacle(glm.vec2(550, 350 + 350 / 2), shape.create_h( glm.vec2(550, 350 + 350 / 2), 50), (350 / 2) - 25, delta_total=(6.28 / 8) * 8), ]) else: return (glm.vec2(550, 600), [])
""" clone one instance of one class (the result is the same with deepcopy function of copy module) ref: https://refactoring.guru/design-patterns/prototype """ import shape if __name__=='__main__': rec_origin = shape.Rectangle(10, 5, 'red', 20, 10) print("==Rectangle==") rec_origin.show_object() print("Clone other rectangle is copy-rectangle") rec_copy = rec_origin.clone() rec_copy.show_object() print("Change central of origin rectangle") rec_origin.change_central(6, 6) rec_origin.show_object() print("Re-show information of copy-rectangle") rec_copy.show_object()