def draw(self): # 水面 if not self.surface is None: surface = self.surface a_x, a_y, a_z = surface.corner_A() b_x, b_y, b_z = surface.corner_B() c_x, c_y, c_z = surface.corner_C() d_x, d_y, d_z = surface.corner_D() a_x, a_y = self.projection(a_x, a_y, a_z) b_x, b_y = self.projection(b_x, b_y, b_z) c_x, c_y = self.projection(c_x, c_y, c_z) d_x, d_y = self.projection(d_x, d_y, d_z) path_s = ui.Path() path_s.move_to(a_x, a_y) path_s.line_to(b_x, b_y) path_s.line_to(c_x, c_y) path_s.line_to(d_x, d_y) path_s.line_to(a_x, a_y) ui.set_color(surface.color) path_s.fill() # uiのメソッドによるフォント描画 self.draw_string() # 文字を描画する for character in self.characters: # [[x,y,z,type,flag],[],...],[] contours = character.glyph(self.height) # フォントを描画する for points in contours: if len(points) < 1: continue path = ui.Path() # 最初のglyph座標 if points[0][4] is True: p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) path.move_to(p_x, p_y) else: continue controls = [] # 制御点を格納する # 2番目以降のglyph座標 for i in range(1, len(points)): if points[i][4] is True: self.draw_glyph(points[i], controls, path) # 最後のglyph座標 self.draw_glyph(points[0], controls, path) ui.set_color('black') if self.is_Fill is True: path.fill() else: path.stroke()
def draw(self): # 数字を描画する for number in self.numbers: for square_index in range(0, number.square_count()): a_x, a_y = number.corner_A(square_index) b_x, b_y = number.corner_B(square_index) c_x, c_y = number.corner_C(square_index) d_x, d_y = number.corner_D(square_index) # 影の描画を行う if number.is_enable_shadow is True: path_s = ui.Path() path_s.move_to(a_x + 5, a_y + 5) path_s.line_to(b_x + 5, b_y + 5) path_s.line_to(c_x + 5, c_y + 5) path_s.line_to(d_x + 5, d_y + 5) ui.set_color(number.shadow_color) path_s.fill() path = ui.Path() path.move_to(a_x, a_y) path.line_to(b_x, b_y) path.line_to(c_x, c_y) path.line_to(d_x, d_y) ui.set_color(number.mycolor()) path.fill() # 円を描画する path_r = ui.Path() path_r.move_to(350, 100) path_r.add_arc(100, 100, 250, 0, radians(self.round_angle)) path_r.stroke() # 三角 for triangle in self.triangles: a_x, a_y = triangle.corner_A() b_x, b_y = triangle.corner_B() c_x, c_y = triangle.corner_C() # 影の描画を行う if triangle.is_enable_shadow is True: path_t_s = ui.Path() path_t_s.move_to(a_x + 5, a_y + 5) path_t_s.line_to(b_x + 5, b_y + 5) path_t_s.line_to(c_x + 5, c_y + 5) ui.set_color(triangle.shadow_color) path_t_s.fill() path_t = ui.Path() path_t.move_to(a_x, a_y) path_t.line_to(b_x, b_y) path_t.line_to(c_x, c_y) ui.set_color(triangle.mycolor()) path_t.fill()
def draw(self): # map if not self.map is None: # self.is_map_draw = True row_count = len(self.map.dots) col_count = len(self.map.dots[0]) for row in range(row_count): for col in range(col_count): points = self.map.points(row, col) if points is None: continue p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) path_m = ui.Path() path_s = None if self.is_enable_shadow is True: path_s = ui.Path() path_s.move_to(p_x + self.shadow_gap, p_y + self.shadow_gap) path_m.move_to(p_x, p_y) for i in range(1, len(points)): p_x, p_y = self.projection(points[i][0], points[i][1], points[i][2]) if self.is_enable_shadow is True: path_s.line_to(p_x + self.shadow_gap, p_y + self.shadow_gap) path_m.line_to(p_x, p_y) p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) if self.is_enable_shadow is True: path_s.line_to(p_x + self.shadow_gap, p_y + self.shadow_gap) path_m.line_to(p_x, p_y) if self.is_enable_shadow is True: ui.set_color(self.shadow_color) path_s.fill() ui.set_color('blue') path_m.fill()
def draw(self): # map if not self.map is None: row_count = len(self.map.dots) col_count = len(self.map.dots[0]) for row in range(row_count): for col in range(col_count): points = self.map.points(row, col) if points is None: continue p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) path_m = ui.Path() path_s = None if self.is_enable_shadow is True: path_s = ui.Path() path_s.move_to(p_x + self.shadow_gap, p_y + self.shadow_gap) path_m.move_to(p_x, p_y) for i in range(1, len(points)): p_x, p_y = self.projection(points[i][0], points[i][1], points[i][2]) if self.is_enable_shadow is True: path_s.line_to(p_x + self.shadow_gap, p_y + self.shadow_gap) path_m.line_to(p_x, p_y) p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) if self.is_enable_shadow is True: path_s.line_to(p_x + self.shadow_gap, p_y + self.shadow_gap) path_m.line_to(p_x, p_y) if self.is_enable_shadow is True: ui.set_color(self.shadow_color) path_s.fill() inner = self.dot_product( points[0][0], points[0][1], points[0][2], points[3][0], points[3][1], points[3][2], points[2][0], points[2][1], points[2][2] ) ui.set_color((0.0, 0.0, (inner * -1) + 0.35, 1.0)) path_m.fill()
def draw(self): if self.data is None or len(self.data.touches) == 0: return c = self.bounds.center() if self.data.translation is not None: c += self.data.translation for touch in self.data.touches.values(): (x, y) = touch.location p = ui.Path.oval(x - 40, y - 40, 80, 80) ui.set_color('white') p.stroke() ui.set_color((0, 1, 0, 0.5)) p.fill() (x, y) = self.data.location p = ui.Path() p.move_to(x - 40, y) p.line_to(x + 40, y) p.move_to(x, y - 40) p.line_to(x, y + 40) ui.set_color('darkgreen') p.stroke() if len(self.translate_track) > 1: p = ui.Path() p.move_to(*(self.bounds.center() + self.translate_track[0])) for pos in self.translate_track[1:]: p.line_to(*(self.bounds.center() + pos)) ui.set_color((1, 0, 0, 0.5)) p.stroke() if self.data.translation is not None: radius = 40 * self.data.scale if self.data.scale is not None else 1 p = ui.Path.oval(c.x - radius, c.y - radius, 2 * radius, 2 * radius) ui.set_color('red') p.stroke() if self.data.rotation is not None: p = ui.Path() p.move_to(c.x, c.y) p.line_to(c.x + radius, c.y) clockwise = self.data.rotation >= 0 p.add_arc(c.x, c.y, radius, 0, math.radians(self.data.rotation), clockwise) p.line_to(c.x, c.y) ui.set_color((1, 0, 0, 0.5)) p.fill() ui.set_color('red') p.stroke()
def draw(self): scl=min(self.width,self.height) self.scl=scl btn_siz=min(22/scl,0.05) #work in normalized units ui.concat_ctm(ui.Transform.scale(scl,scl)) #origin at center ui.concat_ctm(ui.Transform.translation(.5,.5)) ui.set_color('#d0d0d0') o = ui.Path.oval(-.5+btn_siz, -.5+btn_siz, 1-2*btn_siz, 1-2*btn_siz) o.line_width=2/scl o.stroke() if self.image: self.image.draw(-.5+2*btn_siz, -.5+2*btn_siz, 1-4*btn_siz, 1-4*btn_siz) #rotate by angle ui.concat_ctm(ui.Transform.rotation(self.a)) ui.set_color(self.tint_color if self.tint_color else '#1aa1b5') arc = ui.Path() arc.move_to(.5-btn_siz, 0) ang = -(self.a+pi) arc.add_arc(0, 0, .5-btn_siz, 0, ang, False) arc.line_width=2/scl arc.stroke() # center origin at button ui.concat_ctm(ui.Transform.translation(.5-btn_siz,0)) #optional: to keep images upright #ui.concat_ctm(ui.Transform.rotation(-self.a)) p=ui.Path.oval(-btn_siz,-btn_siz,2*btn_siz,2*btn_siz) p.fill()
def draw(self): # 三角 for triangle in self.triangles: if triangle.is_hide is True: continue a_x, a_y, a_z = triangle.corner_A() b_x, b_y, b_z = triangle.corner_B() c_x, c_y, c_z = triangle.corner_C() # 図形が表裏どちらが表示されているか判別する # スクリーン投影する前の座標から判別を行う is_face = self.is_face( a_x, a_y, a_z, b_x, b_y, b_z, c_x, c_y, c_z) # 三次元空間から二次元スクリーンへの投影を反映する s_a_x, s_a_y = self.screen_project(a_x, a_y, a_z) s_b_x, s_b_y = self.screen_project(b_x, b_y, b_z) s_c_x, s_c_y = self.screen_project(c_x, c_y, c_z) path_t = ui.Path() path_t.move_to(s_a_x, s_a_y) path_t.line_to(s_b_x, s_b_y) path_t.line_to(s_c_x, s_c_y) path_t.line_to(s_a_x, s_a_y) ui.set_color(triangle.mycolor()) if is_face is False: path_t.stroke() else: path_t.fill()
def rest(self, beats, position, C0): rests = [] rest_beats = beats rest_div = 4 for i in range(0, 16): while rest_beats - rest_div >= 0: rest_beats -= rest_div rests.append(rest_div) rest_div /= 2 for rest_type in rests: if C0 == C0_treble_y: bottom = treble_lines[4] else: bottom = bass_lines[0] if rest_type == 4: rest = ui.Path.rect(position + (note_gap * 1.5), bottom - (step * 4), step * 3, step) rest.fill() elif rest_type == 2: rest = ui.Path.rect(position + (note_gap / 2), bottom - (step * 5), step * 3, step) rest.fill() elif rest_type == 1: rest = ui.Path() rest.move_to(position - (step / 3), bottom - (step * 7.1)) rest.add_arc(position + (step * 2.5), bottom - (step * 4), step * 2, 4, 2.3, False) rest.add_quad_curve(position, bottom - step, position - (step * 0.7), bottom - (step * 2.9)) rest.add_quad_curve(position + step, bottom - (step * 2.6), position - (step * 1.7), bottom - (step * 3.9)) rest.add_arc(position - (step * 2), bottom - (step * 6), step * 2, 1, 5.7, False) rest.close() rest.stroke() rest.fill()
def draw_light(self): if self.light is None: return light_x, light_y, light_z = self.light_point() self.light.center.x = light_x self.light.center.y = light_y self.light.center.z = light_z points = self.light.local_points() triangles = [] for p_triangles in points: vertexes = [] for vertex in p_triangles: x, y, z = self.camera.camera_rotation(vertex[0], vertex[1], vertex[2]) vertexes.append([x, y, z]) triangles.append(vertexes) for vertexes in triangles: a_x, a_y = self.projection(vertexes[0][0], vertexes[0][1], vertexes[0][2]) b_x, b_y = self.projection(vertexes[1][0], vertexes[1][1], vertexes[1][2]) c_x, c_y = self.projection(vertexes[2][0], vertexes[2][1], vertexes[2][2]) path = ui.Path() path.move_to(a_x, a_y) path.line_to(b_x, b_y) path.line_to(c_x, c_y) path.line_to(a_x, a_y) ui.set_color((1.0, 1.0, 1.0, 1.0)) path.fill() pass
def __init__(self): ShapeNode.__init__(self, path=self.ship_path(), fill_color=BACKGROUND, stroke_color='#bbb') Particle.__init__(self) self.no_flame = ui.Path() self.flame = ShapeNode(path=self.no_flame, fill_color=(0, 0.0, 1.0, 0.4), stroke_color=(0, 1.0, 1.0, 0.5), parent=self) self.ljet = ShapeNode(path=self.no_flame, fill_color=(0, 0, 1.0, 0.1), stroke_color=(0, 1.0, 1.0, 0.5), parent=self) self.rjet = ShapeNode(path=self.no_flame, fill_color=(0, 0, 1.0, 0.1), stroke_color=(0, 1.0, 1.0, 0.5), parent=self) self.maxalt = 0 self.fuel = 5000 self.mass = 1000 self.thrust = 0 self.thrust_ramp = 0 self.thrust_sound = Sound('thrust.mp3') self.add_child(self.thrust_sound)
def draw_round_shadow(self, point_for_vector): #床の適当な座標を取得 point = self.floor.points(0, 0) # 床の水平位置から、床の中央に適当な円を描画する shadow_r = 50 * (500 / abs((point_for_vector[0][1] + point_for_vector[1][1] + point_for_vector[2][1]) / 3 - point[0][1])) step = 10 # 丸影の図形の頂点頻度 少ない程丸に近い # character の x, z 位置を取得する shadow_center_x = (point_for_vector[1][0] + point_for_vector[2][0]) / 2 shadow_center_z = (point_for_vector[1][2] + point_for_vector[2][2]) / 2 path_s = ui.Path() for angle in range(0, 361, step): s_x = shadow_r * cos(radians(angle)) + shadow_center_x s_y = point[0][1] s_z = shadow_r * sin(radians(angle)) + shadow_center_z # ビュー座標 s_x, s_y, s_z = self.camera_rotation(s_x, s_y, s_z) # 透視投影 p_s_x, p_s_y = self.projection(s_x, s_y, s_z) if angle == 0: path_s.move_to(p_s_x, p_s_y) else: path_s.line_to(p_s_x, p_s_y) ui.set_color((0.0, 0.0, 0.0, 0.6)) path_s.fill()
def draw_shadow(self, contours, light_point, font_normal_v3): # 法線の逆ベクトル r_font_normal_v3 = [ -1 * font_normal_v3[0], -1 * font_normal_v3[1], -1 * font_normal_v3[2] ] #フォントの影をを描画する path_s = ui.Path() for points in contours: if len(points) < 3: continue for point in points: # 光源からの影を描画するように修正する light_figure_v3 = [ point[0] - light_point[0], point[1] - light_point[1], point[2] - light_point[2] ] # フォントと光源の距離 light_figure_distance = abs( dot_product(light_figure_v3, font_normal_v3)) # 床の任意の点からフォント座標へのベクトル floor_figure_v3 = [ point[0] - self.floor_any_point[0], point[1] - self.floor_any_point[1], point[2] - self.floor_any_point[2] ] # フォントと床の距離 floor_figure_distance = abs( dot_product(floor_figure_v3, self.floor_normal_v3)) # 影の座標を算出する if light_figure_distance != 0: rate = floor_figure_distance / light_figure_distance point[0] = point[0] + (light_figure_v3[0] * rate) point[1] = point[1] + (light_figure_v3[1] * rate) point[2] = point[2] + (light_figure_v3[2] * rate) # ビュー座標変換を行う point[0], point[1], point[2] = self.camera_rotation( point[0], point[1], point[2]) # 最初のglyph座標 p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) path_s.move_to(p_x, p_y) controls = [] # 制御点を格納する # 2番目以降のglyph座標 for i in range(1, len(points)): self.draw_glyph(points[i], controls, path_s) # 最後のglyph座標 self.draw_glyph(points[0], controls, path_s) # フォントの色設定と塗り潰し ui.set_color((0.0, 0.0, 0.0, 0.5)) path_s.fill()
def setup(self): self.background_color = (1, 1, 1) dx, dy, dz = (i / 2 for i in boxdim) dz *= 2 self.box = Rect3(-dx, -dy, 0, dx * 2, dy * 2, dz, makenode=False) u = ui.Path() u.line_width = 1 for (x1, y1, z1), (x2, y2, z2) in self.box.iteredges(): u.move_to(x1 * dz / (dz + z1), y1 * dz / (dz + z1)) u.line_to(x2 * dz / (dz + z2), y2 * dz / (dz + z2)) #print x1*dz/(2*dz+z1)+512,y1*dz/(2*dz+z1)+384 u = ShapeNode(u, position=(x1 * dz / (dz + z1) - 256, y1 * dz / (dz + z1) - 192), z_position=-10**10) u.anchor_point = (0, 0) u.stroke_color = (.6, ) * 3 self.add_child(u) self.balls = [] self.blocks = [] self.addblock((-3, -3)) for x in range(6): for y in range(6): if random.random() < .7: continue #self.addblock((x-3,y-3)) self.test = LabelNode(position=self.bounds.center()) self.test.color = (0, 0, 0) self.add_child(self.test)
def draw(self): # 三角 for triangle in self.triangles: if triangle.is_hide is True: continue a_x, a_y, a_z = triangle.corner_A() b_x, b_y, b_z = triangle.corner_B() c_x, c_y, c_z = triangle.corner_C() # 図形が表裏どちらが表示されているか判別する # スクリーン投影する前の座標から判別を行う inner = self.dot_product(a_x, a_y, a_z, b_x, b_y, b_z, c_x, c_y, c_z) # 三次元空間から二次元スクリーンへの投影を反映する s_a_x, s_a_y = self.screen_project(a_x, a_y, a_z) s_b_x, s_b_y = self.screen_project(b_x, b_y, b_z) s_c_x, s_c_y = self.screen_project(c_x, c_y, c_z) path_t = ui.Path() path_t.move_to(s_a_x, s_a_y) path_t.line_to(s_b_x, s_b_y) path_t.line_to(s_c_x, s_c_y) path_t.line_to(s_a_x, s_a_y) if inner > 0.0: ui.set_color((0.0, 0.0, 0.0, 1.0)) else: self.set_ui_color(triangle.mycolor(), inner) path_t.fill()
def draw_random(): with ui.ImageContext(canvasWidth, canvasHeight) as imageContext: rect = ui.Path.rect(border, border, canvasWidth - border * 2, canvasHeight - border * 2) ui.set_color("white") rect.fill() path = ui.Path() center = ui.Point(250, 250) path.move_to(center.x, center.y) drawLoop = random.randint(3, 100) for i in range(drawLoop): path.line_to(getRandomLength(), getRandomLength()) path.close() r = getRandomColor() g = getRandomColor() b = getRandomColor() fillColor = (r, g, b) ui.set_color(fillColor) path.fill() drawColor = (r - 0.1, g - 0.1, b - 0.1) ui.set_color(drawColor) path.stroke() return imageContext.get_image()
def demo_ProgressPathView(): import math import random p = ui.Path() p.move_to(20, 20) p.line_to(480, 20) p.line_to(480, 250) p.add_arc(250, 250, 230, 0, math.radians(110)) p.add_curve(50, 450, 20, 250, 480, 250) p.close() # This makes the end look nicer ppv = ui2.ProgressPathView(p) view = ui.View(background_color="white") view.add_subview(ppv) view.width = view.height = ppv.width = ppv.height = 500 view.present("sheet", hide_title_bar=True) def advance(): """Advance by a random amount and repeat.""" pg = ppv.progress + random.random() / 20 if pg < 1: ppv.progress = pg ui.delay(advance, random.random() / 2) else: ppv.progress = 1 advance()
def setup(self): sx, sy = self.size.w * .5, self.size.h * .5 # I would expect the white rect to have its lower left corner # at the center of the screen. But it does not, it is sitting # on the origin of the node, x and y seem to have no effect. self.white = ShapeNode(ui.Path.rect(sx, sy, 200, 200), parent=self, position=(0, 0)) # a reference rect as our white rect is kinda off screen self.red = ShapeNode(ui.Path.rect(0, 0, 150, 150), parent=self, fill_color='red', position=(sx, sy)) # Here I would expect a line from the right top corner # of the red rect going to a point (25, 50) in the # top right direction. But again the path is centered # on the node and also the y coordinate is being inverted. path = ui.Path() path.move_to(75, 75) path.line_to(sx + 100, sy + 125) path.line_width = 3 self.cyan = ShapeNode(path, parent=self.red, stroke_color='cyan', position=(0, 0))
def draw_random(): with ui.ImageContext(canvasWidth, canvasHeight) as imageContext: rect = ui.Path.rect(border, border, canvasWidth - border*2, canvasHeight - border*2) ui.set_color("white") rect.fill() path = ui.Path() center = ui.Point(canvasWidth/2, canvasHeight/2) path.move_to(center.x, center.y) drawLoop = random.randint(3, 100) for i in range(drawLoop): lineType = random.choice(("line", "curve")) if(lineType == "line"): path.line_to(getRandomLength(), getRandomLength()) else: path.add_quad_curve(getRandomLength(), getRandomLength(), getRandomLength(), getRandomLength()) path.close() r = getRandomColor() g = getRandomColor() b = getRandomColor() fillColor = (r, g, b) ui.set_color(fillColor) path.fill() drawColor = (r-0.1, g-0.1, b-0.1) ui.set_color(drawColor) if drawLoop < 40: path.stroke() return imageContext.get_image()
def drawHead(origin, end, thisType): theta = getAngle(origin, end) cs = math.cos(theta) ss = math.sin(theta) R = [[cs, -ss], [ss, cs]] w = distance(origin, end) * headWidth h = distance(origin, end) * headHeight if thisType == 1: initCoords = [[0, w / 2, -w / 2, 0], [0, -h, -h, -h]] # fourth coordinate is where shaft meets head elif thisType == 2: initCoords = [[0, w / 2, 0, -w / 2, 0], [0, -h, -h / 2, -h, -h / 2]] elif thisType == 3: initCoords = [[0, 0], [0, -w]] else: raise ValueError('invalid head type') coords = dot(R, initCoords) Xs = [x + end[0] for x in coords[0]] Ys = [y + end[1] for y in coords[1]] XYs = zip(Xs, Ys) if thisType == 3: arrow = ui.Path.oval(XYs[0][0] - w, XYs[0][1] - w, 2 * w, 2 * w) else: arrow = ui.Path() arrow.move_to(XYs[0][0], XYs[0][1]) for x, y in XYs[:-1]: # last coordinate not used arrow.line_to(x, y) arrow.fill() return (XYs[-1])
def draw_wall(self): # 壁 wall_points = self.wall.points() wall_vertexes = [] for wall_point in wall_points: x, y, z = self.camera.camera_rotation(wall_point[0], wall_point[1], wall_point[2]) wall_vertexes.append([x, y, z]) p_a_x, p_a_y = self.projection(wall_vertexes[0][0], wall_vertexes[0][1], wall_vertexes[0][2]) p_b_x, p_b_y = self.projection(wall_vertexes[1][0], wall_vertexes[1][1], wall_vertexes[1][2]) p_c_x, p_c_y = self.projection(wall_vertexes[2][0], wall_vertexes[2][1], wall_vertexes[2][2]) p_d_x, p_d_y = self.projection(wall_vertexes[3][0], wall_vertexes[3][1], wall_vertexes[3][2]) path_w = ui.Path() path_w.move_to(p_a_x, p_a_y) path_w.line_to(p_b_x, p_b_y) path_w.line_to(p_c_x, p_c_y) path_w.line_to(p_d_x, p_d_y) path_w.line_to(p_a_x, p_a_y) ui.set_color((1.0, 1.0, 1.0, 0.5)) path_w.fill()
def render_bottom_texture(width=100.0): left_path = ui.Path() left_path.move_to(0, 0) left_path.line_to(width / 2, width / 4) left_path.line_to(width / 2, 0) right_path = ui.Path() right_path.move_to(width, 0) right_path.line_to(width / 2, 0) right_path.line_to(width / 2, width / 4) img_height = width / 4 with ui.ImageContext(width, width / 4) as ctx: ui.set_color('#009900') left_path.fill() ui.set_color('#3fb427') right_path.fill() return Texture(ctx.get_image())
def render_curve2(p, cs=72., c1=(0, 0, 0), c2=(1, 1, 1)): k = 1. cs *= 11 / 12. x, y = zip(*p) minx, miny = min(x), min(y) maxx, maxy = max(x), max(y) w, h = maxx - minx, maxy - miny y = [h - i for i in y] with ui.ImageContext(w + cs, h + cs) as ctx: a = 0 o = ui.Path() o.line_cap_style = 1 o.line_join_style = 1 o.move_to(x[0] - minx + cs / 2, y[0] + miny + cs / 2) for i in range(1, len(p)): o.line_to(x[i] - minx + cs / 2, y[i] + miny + cs / 2) #o.line_to(x[-1]-minx+cs/2,y[-1]+miny+cs/2) while a < cs / k: o.line_width = cs - a * k if a == 0: ui.set_color(c2) a += cs / 10 / k else: c = (a / cs * k / 4) ui.set_color(tuple(v1 + v2 for v1, v2 in zip(c1, (c, c, c)))) a += k o.stroke() img = ctx.get_image() return img, (minx - cs / 2, -min(y) - cs / 2)
def setup(self): self.background_color = "#b1ffb1" self.count = 0 self.a = None self.b = None self.pending_mark_a = None self.prev_mark_a = None self.mark_a = None self.mark_b = None self.line_segment = None self.temp_line = None self.cross_point = None self.invalid_draw = False boundary_path = ui.Path().rounded_rect(0, 0, screen_w - 64, screen_h - 160, 4) boundary_path.line_width = 4 boundary_path.stroke() self.boundary = ShapeNode(boundary_path, position = (screen_w / 2, screen_h / 2 + 48), stroke_color = '#000000') self.add_child(self.boundary) self.ball = Ball(2) self.add_child(self.ball) self.lead_list = [] for x in range(32): self.lead = Lead(x + 1) self.add_child(self.lead) self.lead_list.append(self.lead) text = LabelNode("Drag to create a wall!", position = (screen_w/2, screen_h - 100), font = ('Helvetica Neue', 20), color = "#000000") self.add_child(text)
def star_path(self): path = ui.Path() path.move_to(0, 0) path.add_arc(1, 1, 3, 2, 3) path.line_width = 0.1 return path
def draw_wall(self, wall): if isinstance(wall, Square) is True: surface = self.surface a_x, a_y, a_z = wall.corner_A() b_x, b_y, b_z = wall.corner_B() c_x, c_y, c_z = wall.corner_C() d_x, d_y, d_z = wall.corner_D() a_x, a_y, a_z = self.camera_rotation(a_x, a_y, a_z) b_x, b_y, b_z = self.camera_rotation(b_x, b_y, b_z) c_x, c_y, c_z = self.camera_rotation(c_x, c_y, c_z) d_x, d_y, d_z = self.camera_rotation(d_x, d_y, d_z) a_x, a_y = self.projection(a_x, a_y, a_z) b_x, b_y = self.projection(b_x, b_y, b_z) c_x, c_y = self.projection(c_x, c_y, c_z) d_x, d_y = self.projection(d_x, d_y, d_z) path_s = ui.Path() path_s.move_to(a_x, a_y) path_s.line_to(b_x, b_y) path_s.line_to(c_x, c_y) path_s.line_to(d_x, d_y) path_s.line_to(a_x, a_y) ui.set_color(wall.color) path_s.fill()
def dots(self, index, beats, C0, position): if beats % 1.5 == 0: dot = ui.Path() dot = ui.Path.oval(position + (4 * step), C0 - ((index - 0.6) * step), 0.4 * step, 0.4 * step) dot.stroke() ui.set_color('black') dot.fill()
def touch_began(self, touch): x, y = touch.location self.path = ui.Path() self.path.line_width = 8.0 self.path.line_join_style = ui.LINE_JOIN_ROUND self.path.line_cap_style = ui.LINE_CAP_ROUND self.path.move_to(x, y)
def slur(self, slurred, index, C0, tail_direction, position, note_width): global slurs if slurred: slurs.append((position, C0 - (index * step))) elif not slurs == []: f_x, f_y = slurs[0] thickness = 3 tail_end = -7 * tail_direction * step f_y += tail_end y_pos = (C0 - (index * step)) + tail_end t_b = step * (1 - tail_direction) curve_y = (step * tail_direction * -2) + t_b prev_note_side = f_x + (note_width * step * 2) middle_x = prev_note_side + ((position - prev_note_side) / 2) middle_y = f_y + ((y_pos - f_y) / 2) center_s = 3 * ((middle_x - prev_note_side) / 200) slur = ui.Path() slur.move_to(position, y_pos + t_b) slur.add_quad_curve(middle_x, middle_y + curve_y, position - (step * center_s), y_pos + curve_y) slur.add_quad_curve(prev_note_side, f_y + t_b, prev_note_side + (step * center_s), f_y + curve_y) slur.add_quad_curve(middle_x, middle_y + curve_y + ((step * tail_direction) / thickness), prev_note_side + (step * center_s), f_y + curve_y) slur.add_quad_curve(position, y_pos + t_b, position - (step * center_s), y_pos + curve_y) slur.fill() slur.stroke() slurs = []
def draw_shadow(self, contours): #フォントの影をを描画する path = ui.Path() for points in contours: if len(points) < 3: continue # フォントの座標の高さ(Y値)を床の高さに設定する # フォントの座標をビュー座標に変換する for point in points: point[1] = self.floor.level() f_x, f_y, f_z = self.camera_rotation(point[0], point[1], point[2]) point[0], point[1], point[2] = f_x, f_y, f_z # 最初のglyph座標 p_x, p_y = self.projection(points[0][0], points[0][1], points[0][2]) path.move_to(p_x, p_y) controls = [] # 制御点を格納する # 2番目以降のglyph座標 for i in range(1, len(points)): self.draw_glyph(points[i], controls, path) # 最後のglyph座標 self.draw_glyph(points[0], controls, path) # フォントの色設定と塗り潰し ui.set_color((0.0, 0.0, 0.0, 0.6)) #ui.set_color('black') path.fill()
def flag(self, pos, tail_direction, position, width): for bar in range(0, bars_to_draw): x, y = pos flag = ui.Path() x_offset = step * width * (1 + tail_direction) tail_length = step * -5.5 * tail_direction y_offset = step * 1.5 * bar * tail_direction y_dis = step - (tail_direction * step) y_pos = y + tail_length + y_dis + y_offset rad = step / 2 flag.move_to(x + x_offset, y_pos) flag.add_arc(x + rad + x_offset, y_pos, rad, 3 * tail_direction, 2 * tail_direction, tail_direction < 0) rad = step * 2.5 tail_length = step * -2.5 * tail_direction y_pos = y + tail_length + y_dis + y_offset flag.add_arc(x + x_offset, y_pos, rad, 5 * tail_direction, tail_direction, tail_direction > 0) rad = step * 2.25 tail_length = step * -2.25 * tail_direction y_pos = y + tail_length + y_dis + y_offset flag.add_arc(x + x_offset, y_pos, rad, tail_direction, 4.8 * tail_direction, tail_direction < 0) tail_length = step * -4.5 * tail_direction y_pos = y + tail_length + y_dis + y_offset flag.line_to(x + x_offset, y_pos) ui.set_color("black") flag.close() flag.stroke() flag.fill() run = []