def has_common_point(tile_line: Line, jump_line1: Line, jump_line2: Line): common_point = tile_line.common_point_with(jump_line1) if common_point and tile_line.is_inside(common_point): return True common_point = tile_line.common_point_with(jump_line2) if common_point and tile_line.is_inside(common_point): return True return False
def drawX(self, posXY): [px, py] = self.boardPositionToPixelCenter(posXY) for x in [-1, 1]: for y in [-1, 1]: L = self.cell_size / 2 * 0.8 line = Line(a=(px + x * L, py + y * L), b=(px, py), z=1, color=self.colorX, stroke=5) line.render()
def render(self): c = Circle(self.a[0], self.a[1], width=10, color=(0., .9, 0., 1.)) c.render() c = Circle(self.ac[0], self.ac[1], width=10, color=(0., .9, 0.5, 1.)) c.render() l = Line(self.a, self.ac, stroke=2, color=(0, 1., 1., 1.)) l.render() c = Circle(self.b[0], self.b[1], width=10, color=(0., .9, 1., 1.)) c.render() c = Circle(self.bc[0], self.bc[1], width=10, color=(0., .9, 1., 0.5)) c.render() l = Line(self.b, self.bc, stroke=2, color=(0, 1., 1., 1.)) l.render() steps = 100.0 bz = self.bezier() last = self.a for i in range(int(steps)): t = (i + 1) / steps val = bz.at(t) val = val[0] + self.a.x, val[1] + self.a.y glBegin(GL_LINES) glVertex2f(last[0], last[1]) glVertex2f(val[0], val[1]) glEnd() last = val
def _bump_out_borders(lm): for terr in lm.sea_terrs: new_x, new_y = terr.x, terr.y new_x += math.cos(terr.line.normal) * 20.0 new_y += math.sin(terr.line.normal) * 20.0 new_point = Point(new_x, new_y) nl1 = Line(terr.line.a, new_point, terr.line.left) nl2 = Line(new_point, terr.line.b, nl1, terr.line.right) nl1.right = nl2 terr.lines = [nl1, nl2] line2 = terr.line.left.right while line2 != terr.line.right: line2.color = (1, 1, 1, 1) line2 = line2.right
def process_line(self, l_info, unnamed=True): if isinstance(l_info, str) and not is_number(l_info): assert (Line(l_info) in self.lines) return Line(l_info) if not isinstance(l_info, tuple): raise NotImplementedError( f"[process_line] l_info must be tuple or string") l_pred = l_info[0].lower() l_args = l_info[1:] l_val = None if l_pred == "line": assert (len(l_args) == 2) ps = [self.process_point(p) for p in l_args] l_val = FuncInfo("connecting", ps) elif l_pred in ["perp-at", "para-at"]: assert (len(l_args) == 2) p = self.process_point(l_args[0]) l = self.process_line(l_args[1]) l_val = FuncInfo(l_pred, [p, l]) elif l_pred == "perp-bis": assert (len(l_args) == 2) ps = [self.process_point(p) for p in l_args] l_val = FuncInfo(l_pred, ps) elif l_pred in ["isogonal", "isotomic"]: assert (len(l_args) == 4) ps = [self.process_point(p) for p in l_args] l_val = FuncInfo(l_pred, ps) elif l_pred in ["i-bisector", "e-bisector"]: assert (len(l_args) == 3) ps = [self.process_point(p) for p in l_args] l_val = FuncInfo(l_pred, ps) elif l_pred == "reflect-ll": assert (len(l_args) == 2) ls = [self.process_line(l) for l in l_args] l_val = FuncInfo(l_pred, ls) if l_val is not None: L = Line(l_val) if unnamed: self.unnamed_lines.append(L) return L else: raise NotImplementedError( f"[process_line] Unsupported line pred: {l_pred}")
def __init__(self, *args, **kwargs): super(MyWindow, self).__init__(*args, **kwargs) self.set_minimum_size(400, 300) # pyglet.gl.glClearColor(0.2, 0.3, 0.2, 1.0) self.line = Line() self.triangle = Triangle(100, 100) self.point = Point(200, 200) self.objects = [] self.food_manager = FoodManager() self.creature_manager = CreatureManager() self.life_breath()
def render(self, batch): if self.title: self.vertex_lists = [] label = pyglet.text.Label(self.title) t_x, t_y = self.calc_title_position(label) label = pyglet.text.Label(self.title, x=t_x, y=t_y, batch=batch) sep_y = self.y + self.height - 2 * self.title_y_pad - label.content_height print self.x, sep_y, self.x + self.width separator = Line(self.x, sep_y, self.x + self.width, sep_y) batch.add(*separator.render()) batch.add(*self.frame.render()) self.vertex_lists.append(separator.render()) self.vertex_lists.append(self.frame.render()) # def click(self, x, y, button): # # pass # #
def render(self): c = Circle(self.a[0], self.a[1], width=10, color=(0.0, 0.9, 0.0, 1.0)) c.render() c = Circle(self.ac[0], self.ac[1], width=10, color=(0.0, 0.9, 0.5, 1.0)) c.render() l = Line(self.a, self.ac, stroke=2, color=(0, 1.0, 1.0, 1.0)) l.render() c = Circle(self.b[0], self.b[1], width=10, color=(0.0, 0.9, 1.0, 1.0)) c.render() c = Circle(self.bc[0], self.bc[1], width=10, color=(0.0, 0.9, 1.0, 0.5)) c.render() l = Line(self.b, self.bc, stroke=2, color=(0, 1.0, 1.0, 1.0)) l.render() steps = 100.0 bz = self.bezier() last = self.a for i in range(int(steps)): t = (i + 1) / steps val = bz.at(t) val = val[0] + self.a.x, val[1] + self.a.y glBegin(GL_LINES) glVertex2f(last[0], last[1]) glVertex2f(val[0], val[1]) glEnd() last = val
def drawBoard(self): n = self.board.n for i in range(n - 1): x = (i + 1) * (self.cell_size) y = n * (self.cell_size) liney = Line(a=(x, 0), b=(x, y), z=1, color=self.colorFrame, stroke=self.frameWidth) liney.render() linex = Line(a=(0, x), b=(y, x), z=1, color=self.colorFrame, stroke=self.frameWidth) linex.render()
def compute(self, cmd): assert (len(cmd) == 4) obj_name = cmd[1] assert (isinstance(obj_name, str)) obj_type = cmd[2].lower() assert (obj_type in ["point", "line", "circle"]) if obj_type == "point": p = Point(obj_name) self.register_pt(p) computation = self.process_point(cmd[3], unnamed=False) assert (not isinstance(computation.val, str)) c_instr = Compute(p, computation) self.instructions.append(c_instr) elif obj_type == "line": l = Line(obj_name) self.register_line(l) computation = self.process_line(cmd[3], unnamed=False) assert (not isinstance(computation.val, str)) c_instr = Compute(l, computation) self.instructions.append(c_instr) elif obj_type == "circle": c = Circle(obj_name) self.register_circ(c) computation = self.process_circle(cmd[3], unnamed=False) assert (not isinstance(computation.val, str)) c_instr = Compute(c, computation) self.instructions.append(c_instr) else: raise RuntimeError("Invalid define type")
def param(self, cmd): assert (len(cmd) == 3 or len(cmd) == 4) obj_type = cmd[2].lower() assert (obj_type in ["point", "line", "circle"]) if obj_type == "line": l = Line(cmd[1]) self.register_line(l) param_method = "line" if len(cmd) == 4: param_method = cmd[3] pred, args = self.process_param_line(param_method) p_instr = Parameterize(l, (pred, args)) self.instructions.append(p_instr) elif obj_type == "circle": c = Circle(cmd[1]) self.register_circ(c) param_method = "circle" if len(cmd) == 4: param_method = cmd[3] pred, args = self.process_param_circ(param_method) p_instr = Parameterize(c, (pred, args)) self.instructions.append(p_instr) else: p = Point(cmd[1]) self.register_pt(p) param_method = "coords" if len(cmd) == 4: param_method = cmd[3] pred, args = self.process_param_point(param_method) p_instr = Parameterize(p, (pred, args)) self.instructions.append(p_instr)
def render(self): c = Circle( self.a[0],self.a[1], width=10,color=(0.,.9,0.,1.) ) c.render() c = Circle( self.ac[0],self.ac[1], width=10,color=(0.,.9,0.5,1.) ) c.render() l = Line(self.a,self.ac,stroke=2,color=(0,1.,1.,1.)) l.render() c = Circle( self.b[0],self.b[1], width=10,color=(0.,.9,1.,1.) ) c.render() c = Circle( self.bc[0],self.bc[1], width=10,color=(0.,.9,1.,0.5) ) c.render() l = Line(self.b,self.bc,stroke=2,color=(0,1.,1.,1.)) l.render() steps=100.0 bz = self.bezier() last = self.a for i in range(steps): t = (i+1)/steps next = bz.at( t ) next = next[0] + self.a.x, next[1] + self.a.y glBegin(GL_LINES); glVertex2f(last[0], last[1]); glVertex2f(next[0], next[1]); glEnd( ); last = next
def is_one_jump_avail(from_position: model.Vec2Double, to_position: model.Vec2Double, game: model.Game, tiles: List[List[LevelPoint]]): def has_common_point(tile_line: Line, jump_line1: Line, jump_line2: Line): common_point = tile_line.common_point_with(jump_line1) if common_point and tile_line.is_inside(common_point): return True common_point = tile_line.common_point_with(jump_line2) if common_point and tile_line.is_inside(common_point): return True return False max_dy = JumpParams.get_jump_max_dy(game.properties) if math.fabs(from_position.y - to_position.y) > max_dy: return False unit_max_fall_time = (game.properties.unit_jump_time * game.properties.unit_max_horizontal_speed) /\ game.properties.unit_fall_speed max_r = game.properties.unit_jump_time * game.properties.unit_max_horizontal_speed +\ game.properties.unit_fall_speed * unit_max_fall_time if distance(from_position, to_position) > max_r: return False jump = JumpParams.get_jump(from_position, to_position, game.properties) if not jump: return False row_count = int(max_dy) + 1 row_from = min([ int(from_position.y), int(to_position.y), int(jump.middle_position.y) ]) row_to = max([ int(from_position.y), int(to_position.y), int(jump.middle_position.y) ]) rows = tiles[row_from:row_to] # type: List[List[LevelPoint]] col_count = int(max_r) + 1 col_from = min([ int(from_position.x), int(to_position.x), int(jump.middle_position.x) ]) col_to = max([ int(from_position.x), int(to_position.x), int(jump.middle_position.x) ]) jump_line1 = Line(jump.from_position, jump.middle_position) jump_line2 = Line(jump.middle_position, jump.to_position) solid_tiles = [ model.Tile.JUMP_PAD, model.Tile.WALL, model.Tile.PLATFORM ] for row in rows: # type: List[LevelPoint] solid_cells = [ r for r in row[col_from:col_to + 1] if r.tile in solid_tiles ] for cell in solid_cells: # type: LevelPoint if cell.position.x == 26. and cell.position.y == 9.: a = 1 if from_position.y != cell.position.y and to_position.y != cell.position.y\ and has_common_point(cell.lines.top, jump_line1, jump_line2): return False if has_common_point(cell.lines.bottom, jump_line1, jump_line2): return False if has_common_point(cell.lines.left, jump_line1, jump_line2): return False if has_common_point(cell.lines.right, jump_line1, jump_line2): return False return True