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 draw_face(self, diameter, border, font_size): with ui.ImageContext(diameter, diameter) as ctx: ui.set_color('white') circle = ui.Path.oval(border / 2, border / 2, diameter - border, diameter - border) circle.line_width = border - 1 circle.fill() ui.set_color('silver') with ui.GState(): ui.set_shadow((0, 0, 0, 0.35), 0, 1, 5.0) circle.stroke() angle = (-pi / 2) + (pi * 2) / 12.0 for i in range(1, 13): number = str(i) x = diameter / 2 + cos(angle) * (diameter / 2 - font_size * 1.2) y = diameter / 2 + sin(angle) * (diameter / 2 - font_size * 1.2) font = ('HelveticaNeue-UltraLight', font_size) w, h = ui.measure_string(number, font=font) rect = (x - 50, y - h / 2, 100, h) ui.draw_string(number, rect=rect, font=font, alignment=ui.ALIGN_CENTER) angle += (pi * 2.0) / 12.0 return ctx.get_image()
def draw(self): global nodeDelegate try: i = self.iX i = self.superview.states except AttributeError: #views not fuly stabilized return flexLabel = self.superview['current_flex'] flexLabel.text = self.superview.thisFlex ui.set_color('black') inner = ui.Path.rect(self.iX,self.iY,self.iW,self.iH) inner.stroke() for key in self.superview.states.keys(): if key in 'RLTB': thisType = (5,5) headW = -6 headH = -2 else: thisType = (2,2) headW = -6 headH = -12 solidLine = self.superview.states[key] if key in 'LRTB': #sense is reversed solidLine = not solidLine if solidLine: ui_draw_arrow(self.coords[key][0],self.coords[key][1],pointType=thisType, headWidth=headW, headHeight=headH) else: ui_draw_arrow(self.coords[key][0],self.coords[key][1],pointType=thisType,lineDash=(4,4), headWidth=headW, headHeight=headH)
def draw_hand(self, width, length, color): with ui.ImageContext(width, length) as ctx: # Leave a few pixels transparent round_rect = ui.Path.rounded_rect(2, 2, width-4, length-2, (width-4)*0.5) ui.set_color(color) round_rect.fill() return ctx.get_image()
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 = []
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): '1' #Setup path of window shape path = ui.Path.rect(0, 0, self.width-10, self.height-10) #Draw background ui.set_color((0.95,0.95,0.95,0.5)) path.fill() '2' #Setup mask by creating image from PIL import ImageDraw i = Image.new('RGBA',(520,290), (255,255,255,0)) draw = ImageDraw.Draw(i) draw.rectangle((self.width-10, 0, self.width, self.height),fill=(0,0,0,255)) draw.rectangle((0, self.height-10, self.width, self.height),fill=(0,0,0,255)) #Convert to UI, apply the mask, and draw shadow! i = pil_to_ui(i) i.clip_to_mask() ui.set_color((1,1,1,1)) ui.set_shadow("black",-2,-2,10) path.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 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 draw(self): oval = ui.Path.oval(0,0, self.width, self.height) rect = ui.Path.rect(0,0, self.width, self.height) #rect.append_path(oval) ui.Path.add_clip(oval) ui.set_color('white') oval.fill()
def draw(self): # do a draw, just to see how it works r = ui.Rect(*self.bounds).inset(20, 20) s = ui.Path.rect(*r) s.line_width = 10 ui.set_color('blue') s.stroke()
def draw_label(self): owner = self.owner ui.set_color('purple') s = str('{:.0%}'.format(owner.value)) lb_rect = ui.Rect(*owner.cv) lb_rect.center(owner.center) ui.draw_string(s, lb_rect , font=('Arial Rounded MT Bold', 22), color='black', alignment=ui.ALIGN_CENTER, line_break_mode=ui.LB_TRUNCATE_TAIL)
def drawRandomPath(path): center = ui.Point(canvasWidth / 2, canvasHeight / 2) path.move_to(center.x, center.y) drawLoop = random.randint(3, 40) #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()
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 set_ui_color(self, color, light_inner, light_length, brightness=60000): # (光源光量 * cosθ) / 距離の二乗 value = (-1 * brightness * light_inner) / light_length # print(value) # 反射率 RGB r_ref, g_ref, b_ref = (1.0, 1.0, 1.0) if color == 'white': r_ref, g_ref, b_ref = (1.0, 1.0, 1.0) elif color == 'blue': r_ref, g_ref, b_ref = (0.05, 0.05, 1.0) elif color == 'green': r_ref, g_ref, b_ref = (0.05, 1.0, 0.05) elif color == 'red': r_ref, g_ref, b_ref = (1.0, 0.05, 0.05) elif color == 'yellow': r_ref, g_ref, b_ref = (1.0, 1.0, 0.1) elif color == 'black': # ui.set_color('black') r_ref, g_ref, b_ref = (0.0, 0.0, 0.0) elif color == 'orange': # ui.set_color((value, value-0.2, 0.2, 1.0)) r_ref, g_ref, b_ref = (1.0, 0.8, 0.1) ui.set_color((r_ref * value, g_ref * value, b_ref * value, 1.0))
def draw(self): ui.set_color('black') upper = int(self.width // 2 - 50) lower = int(self.width // 4 - 25) for x, size in zip(range(upper, -1, -lower), range(lower, 501, upper)): if x == 0: x += 20 size -= 40 rect = ui.Path.rect(x, x, size, size) rect.line_width = 10 rect.stroke() def strokeLine(fx, fy, tx, ty): line = ui.Path() line.move_to(fx, fy) line.line_to(tx, ty) line.line_width = 5 line.stroke() strokeLine(self.width / 2, 20, self.width / 2, upper) strokeLine(self.width / 2, self.height - 20, self.width / 2, upper + lower) strokeLine(20, self.height / 2, upper, self.height / 2) strokeLine(self.width - 20, self.height / 2, upper + lower, self.height / 2)
def draw(self): # just to see the path when testing... s = ui.Path.oval(*self.cir_rect) with ui.GState(): ui.set_color(css_clr_to_rgba('lime', .4)) s.line_width = 1 s.stroke()
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(self): global currentval x, y, w, h = self.frame path = ui.Path.rect(0, 0, currentval * w, h) ui.set_color((1.0, 0.4, 0.4, 1.0)) path.fill()
def build_pin(path): my_ui_image = ui.Image.named(path) dx, dy = 28, 86 v = ui.View(frame=(0, 0, dx, dx), corner_radius=dx / 2) iv = ui.ImageView(frame=(0, 0, dx, dx)) iv.image = my_ui_image v.add_subview(iv) with ui.ImageContext(dx, dx) as ctx: v.draw_snapshot() # if circular cropped my_ui_image = ctx.get_image() # image with pin and its foot, coloured circle replaced by the photo) with ui.ImageContext(dx, dy) as ctx: foot = ui.Path.oval(dx / 2 - 2, dy / 2 - 1, 4, 2) ui.set_color((0, 0, 0, 1)) foot.fill() pin = ui.Path.rounded_rect(dx / 2 - 1, dx / 2, 2, dy / 2 - dx / 2, 1) ui.set_color((0.6, 0.6, 0.6, 1)) pin.fill() my_ui_image.draw(0, 0, dx, dx) my_ui_image = ctx.get_image() # circular image without foot not pin #d = 28 #v = ui.View(frame=(0,0,d,d),corner_radius=d/2) #iv = ui.ImageView(frame=(0,0,d,d)) #v.add_subview(iv) #iv.image = my_ui_image #with ui.ImageContext(d,d) as ctx: # v.draw_snapshot() # if circular cropped # my_ui_image = ctx.get_image() return my_ui_image
def draw(self): self.scr_height = self.height self.scr_width = self.width path = ui.Path.rect(0, 0, self.scr_width, self.scr_height) ui.set_color(self.color) path.fill() self.img.draw(self.x_off,self.y_off,self.img_width*self.ratio/self.scr_cor,self.img_height*self.ratio/self.scr_cor)
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 draw(self): r = ui.Rect(*self.bounds).inset(1, 1) s = ui.Path.oval(*r) s.line_width = 2 ui.set_color('silver') s.fill() ui.set_color('black') s.stroke() ui.set_color('white') r = ui.Rect(*self.bounds).inset(3, 3) s = ui.Path.oval(*r) s.line_width = 1 s.stroke() if self.selected: ui.set_color('red') ui.set_shadow('black', 0, 0, 15) r = ui.Rect(*self.bounds).inset(18, 18) s = ui.Path.oval(*r) s.fill() else: ui.set_color('darkgray') ui.set_shadow('black', 0, 0, 15) r = ui.Rect(*self.bounds).inset(18, 18) s = ui.Path.oval(*r) s.fill()
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 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 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 draw(self): if self.image: self.img_width, self.img_height = self.image.size path = ui.Path.rect(0, 0, self.width, self.height) ui.set_color('white') path.fill() self.image.draw(0,self.button_height,self.img_width*self.ratio/self.scr_scale,self.img_height*self.ratio/self.scr_scale)
def draw(self): r = ui.Rect(*self.bounds).inset(*self.circle_inset) oval = ui.Path.oval(r.x, r.y, r.width, r.height) c = ui.parse_color(self.circle_color) nc = (c[0], c[1], c[2], self.circle_alpha) # color with alpha pattern = '9' * len(self.text) text_rect = ui.Rect(0, 0, r.width * .8, r.height * .6) text_rect.center(r.center()) fs = self.get_max_fontsize(text_rect, pattern, self.font_name, self.inset_rect) with ui.GState(): ui.set_color(nc) oval.fill() ui.draw_string(self.text, rect=text_rect, font=(self.font_name, fs), color=self.text_color, alignment=ui.ALIGN_CENTER, line_break_mode=ui.LB_TRUNCATE_TAIL) j = ui.Path.rect(*text_rect) ui.set_color((0, 0, 0, .5)) j.fill()
def make_key_images(): r1=100 r2=200 ang1=-pi/12 ang2=pi/12 key_img=[] with ui.ImageContext(110,110) as ctx: p=ui.Path() s1=sin(ang1) c1=cos(ang1) s2=sin(ang2) c2=cos(ang2) x0=55-0.5*(r1+r2) y0=55+0.0 p.move_to(x0+c2*r1,y0+s2*r1) p.add_arc(x0,y0,r1,ang2,ang1,False) p.add_arc(x0,y0,r2,ang1,ang2,True) p.close() for fill_color in [(1,1,1),(0.8,0.8,0.8),(0,0,0),(0.3, 0.3,0.3)]: ui.set_color(fill_color) p.fill() ui.set_color((0.5,0.5,0.5)) p.stroke() key_img.append(ctx.get_image()) return key_img
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 draw(self): n = int(self.width / (self.dm + self.dw + self.height) + 1) ui.set_color(self.dcolor) for i in range(n): for j in range(int(self.height)): ui.fill_rect(i * (self.dm + self.dw + self.height) + j, self.height - j, self.dw, 1)
def draw(self): x = y = 0 radius = 5 for page, view in self.pages.items(): w, h = [i for i in ui.measure_string(page, 0, self.tabfont)] dw, dh = [i + self.tabpad * 2 for i in (w, h)] if not isinstance(view, list): view.y += y + dh path1 = ui.Path.rounded_rect(x, y, dw, dh, radius) path2 = ui.Path.rect(x, y + dh - radius, dw, radius) view = [view, path1, path2] self.pages[page] = view view, path1, path2 = view if view == self.selpage: ui.set_color(0.89) else: ui.set_color(0.82) path1.fill() path2.fill() dy = y + dh/2. - h/2. ui.draw_string(page, (x, dy, dw, dh), self.tabfont, self.tabfg, ui.ALIGN_CENTER) x += dw
def draw(self): ''' draw a treatment for a selected date ''' if not self.sel_obj: return btn = self.sel_obj # only execute the code below, if the selected date is the # same year and monthb if self.selected_date: if btn.date.year != self.selected_date.year or\ btn.date.month != self.selected_date.month: return r = ui.Rect(*btn.day_lb.bounds).inset(0, 0) if r.width < r.height: r.height = r.width else: r.width = r.height r.center(btn.center) s = ui.Path.oval(*r) ui.set_color(self.date_selection_color) s.fill()
def draw(self): r = ui.Rect(10, 10, 200, 200) s = ui.Path.oval(*r) ui.set_color('deeppink') s.fill() draw_arc(r.inset(10, 10))
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 make_frame(t): with ui.ImageContext(W, H, 1) as ctx: for i in range(ncircles): angle = 2*np.pi*(1.0*i/ncircles+t/duration) center = W*( 0.5 + polar2cart(0.1,angle)[0]), W*( 0.5 + polar2cart(0.1,angle)[1]) r = W*(1.0-1.0*i/ncircles) ui.set_color((i%2, i%2, i%2)) ui.Path.oval(center[0]-r, center[1]-r, r*2, r*2).fill() return ui2pil(ctx.get_image())
def draw_line(cwidth, cheight): with ui.ImageContext(cwidth, cheight) as ctx: ui.set_color('black') p = ui.Path() p.line_width = cheight p.move_to(0, 0) p.line_to(cwidth, 0) p.stroke() return ctx.get_image()
def draw(self): # This will be called whenever the view's content needs to be drawn. if hasattr(self, 'maxValue') and hasattr(self, 'currentValue'): lenght=int((self.width*self.currentValue)/self.maxValue) else: lenght=0 rect = ui.Path.rect(0, 0, lenght, self.height) ui.set_color(self.tint_color) rect.fill()
def draw(self): # Set drawing attributes ui.set_color(self._color) ui.set_shadow(*self._shadow) # Calculations scale_x = self.width / self._pathsize[0] scale_y = self.height / self._pathsize[0] # Scale the path new_path = ui2.path_helpers.scale_path(self._path, (scale_x, scale_y)) new_path.fill()
def draw(self): if not self.bgview_image: #if no bgview.image exists... self.image = None #...delete path self.paths = [] self.path = None if self.path: #draw current path ui.set_color(self.color) self.path.stroke() if self.image: self.image.draw(0,0,self.width,self.height) #draw path image (complete path) self.set_needs_display()
def create_image_from_history(self): path = ui.Path.rect(*self.frame) with ui.ImageContext(self.width, self.height) as ctx: for pixel in self.used_pixels: ui.set_color(pixel.color) pixel_path = ui.Path.rect(*pixel) pixel_path.line_width = 0.5 pixel_path.fill() pixel_path.stroke() img = ctx.get_image() return img
def path_width(self): with ui.ImageContext(self.button_width, self.button_height) as ctx: ui.set_color(self.colors[self.color_nr]) path = ui.Path() path.line_width = self.path_widths[self.path_w_nr] path.line_join_style = ui.LINE_JOIN_ROUND path.line_cap_style = ui.LINE_CAP_ROUND path.move_to(20,self.button_height/2) path.line_to(107,self.button_height/2) path.stroke() image = ctx.get_image() self.scv_btn_path_width.background_image = image
def delete_path(self): path_count = len(self.paths) if path_count > 0: self.paths.pop() path_count -= 1 self.image = None width, height = self.width, self.height #screen size with ui.ImageContext(width, height) as ctx: for i in xrange(0, path_count): ui.set_color(self.color) self.paths[i].stroke() self.image = ctx.get_image() self.set_needs_display()
def draw(self): '''draw a green box around kb frame, padded by 10 pixels''' kb=self.get_keyboard_frame() # print kb kb_self=self.convert_rect(kb,None,self) # print kb_self ui.set_color((0,1,0,0.5)) ui.fill_rect(kb_self[0]-10,kb_self[1]-10, kb_self[2]+20,kb_self[3]+20) self.t3.text=('orientation {}\n' 'kbframe {}\n' 'kbframe fixed {}\n ' 'kbframe in V {}\n').format(self.get_orientation(),ui.get_keyboard_frame(),kb,kb_self)
def touch_ended(self, touch): self.paths.append(self.path) width, height = self.width, self.height #screen size old_img = self.image with ui.ImageContext(width, height) as ctx: if old_img: old_img.draw(0,0,self.width,self.height) if self.path: ui.set_color(self.color) self.path.stroke() self.image = ctx.get_image() self.path = None self.layout() self.set_needs_display()
def touch_ended(self, touch): width, height = self.width, self.height #screen size self.paths.append((self.path, (width, height), self.color)) old_img = self.image with ui.ImageContext(width, height) as ctx: if old_img: old_img.draw(0,0,width,height) # previous paths if self.path: ui.set_color(self.color) self.path.stroke() self.image = ctx.get_image() # add path to image self.path = None self.layout() self.set_needs_display()
def create_grid_image(self): s = self.width/self.row if self.row > self.column else self.height/self.column path = ui.Path.rect(0, 0, *self.frame[2:]) with ui.ImageContext(*self.frame[2:]) as ctx: ui.set_color((0, 0, 0, 0)) path.fill() path.line_width = 2 for y in xrange(self.column): for x in xrange(self.row): pixel = Pixel(x*s, y*s, s, s) path.append_path(ui.Path.rect(*pixel)) self.pixels.append(pixel) ui.set_color('gray') path.stroke() return ctx.get_image()
def delete_path(self): path_count = len(self.paths) if path_count > 0: self.paths.pop() path_count -= 1 self.image = None for i in range(0, path_count): old_img = self.image width, height = self.paths[i][1] with ui.ImageContext(width, height) as ctx: if old_img: old_img.draw(0,0,width,height) ui.set_color(self.paths[i][2]) self.paths[i][0].stroke() self.image = ctx.get_image() self.set_needs_display()
def pencil(self, pixel): if pixel.colors[-1] != self.current_color: if self.current_color != (0, 0, 0, 0): pixel.colors.append(self.current_color) self.pixel_path.append(pixel) old_img = self.image_view.image path = ui.Path.rect(*pixel) with ui.ImageContext(self.width, self.height) as ctx: if old_img: old_img.draw() ui.set_color(self.current_color) pixel_path = ui.Path.rect(*pixel) pixel_path.line_width = 0.5 pixel_path.fill() pixel_path.stroke() self.set_image(ctx.get_image())
def draw(self): ui.set_color((.7,.5,.5)) if not self.vert: path=ui.Path.rounded_rect((self.barvalue-self.barwidth/2.)*self.width,0,self.barwidth*self.width,self.height,self.height*0.1) else: path=ui.Path.rounded_rect(0,(self.barvalue-self.barwidth/2.)*self.height,self.width, self.barwidth*self.height,self.width*0.1) path.fill() ui.set_color((0.5,.5,.5)) path.stroke() ui.set_color((0.5,0,0)) if len(self.touches)==1: ui.set_color((0.7,0.7,0)) path.fill() elif len(self.touches)==2: ui.set_color((0.7,0.0,0.7)) path.fill()
def draw(self): self.buttonsize = int(self.height / CELLS_PER_ROW) self.startx = int(self.width / 2 - self.height / 2) buttonsize = self.buttonsize for x in range(CELLS_PER_ROW): for y in range(CELLS_PER_ROW): frame = (self.startx+x*buttonsize, y*buttonsize, buttonsize, buttonsize) p = ui.Path.rect(*frame) ui.set_color(self.load[x, y]) p.fill() path=self.Djk2UI(self.pathCalc()) ui.set_color('blue') ui.set_shadow('black', 2, 2, 5) path.stroke()
def draw(self): self.buttonsize = int(self.height/16) self.startx=int((self.width/2-self.height/2)) buttonsize=self.buttonsize for x in range(16): for y in range(16): frame=(self.startx+x*buttonsize,y*buttonsize,buttonsize,buttonsize) p=ui.Path.rect(*frame) ui.set_color(self.load[x,y]) p.fill() path=self.Djk2UI(self.pathCalc()) ui.set_color((0,0,1)) ui.set_shadow((0,0,0),2,2,5) path.stroke()
def draw(self): # redraw button def darken(color): return tuple([0.5*x for x in color]) #set up button size to fit. padding=10 textsize=ui.measure_string(string=self.title,max_width=0,font=self.font,alignment=ui.ALIGN_CENTER) #draw border ui.set_color(self.border_color) path = ui.Path.rounded_rect(0, 0, self.width, self.height,self.corner_radius) path.line_width=self.border_width path.stroke() #fill button, depending on touch state if self.touched: if self.doing_longtouch: ui.set_color('blue') else: ui.set_color('grey') else : ui.set_color(self.bg_color) path.fill() # fill corner darker, if has children if self.flow.subviews: corner = ui.Path() corner.move_to(self.width-1.5*self.corner_radius,0) corner.line_to(self.width,0) corner.line_to(self.width,1.5*self.corner_radius) corner.line_to(self.width-1.5*self.corner_radius,0) ui.set_color(darken(darken(self.bg_color))) corner.stroke() corner.fill() # draw title, center vertically, horiz rect=list(self.bounds) rect[1]=(rect[3]-textsize[1])/2 #vert center rect[2]=max(rect[2],textsize[0]+10) ui.draw_string(self.title, rect=tuple(rect), font=self.font, color=self.tint_color, alignment=ui.ALIGN_CENTER, line_break_mode=ui.LB_WORD_WRAP) if textsize[0]>self.bounds[2]: self.width=textsize[0]+10
def button_img(self,size,color='red'): '''create breakpoint stopsign image''' w,h=size d=min(w,h) x0=0 with ui.ImageContext(w,h) as ctx: pth=ui.Path() pth.move_to(x0,d/4.) pth.line_to(x0+d/4.,0) pth.line_to(x0+3*d/4.,0) pth.line_to(x0+d,d/4.0) pth.line_to(x0+d,3.*d/4.0) pth.line_to(x0+3*d/4,d) pth.line_to(x0+d/4,d) pth.line_to(x0,3*d/4.0) ui.set_color(color) pth.fill() return ctx.get_image()
def pencil(self, pixel): if not pixel.used or pixel.color != self.current_color: pixel.used = True pixel.color = self.current_color old_img = self.image_view.image path = ui.Path.rect(*pixel) with ui.ImageContext(self.width, self.height) as ctx: if old_img: old_img.draw() ui.set_color(self.current_color) pixel_path = ui.Path.rect(*pixel) pixel_path.line_width = 0.5 pixel_path.fill() pixel_path.stroke() self.used_pixels.append(pixel) img = ctx.get_image() self.image_view.image = img self.superview['preview'].image = img
def draw(self): if not self.data_source.items: return topNodesFrame = self.data_source.items[0]['node']['frame'] topNodeCentroid = self.centroid(topNodesFrame) # need to account for orgins of parents. need to walk down the tree for item in self.data_source.items: title = item['title'] node = item['node'] level = node['level'] frame = node['frame'] uuid = node['uuid'] try: parent = node['parent'] except KeyError: print "Keyerror on node['parent']\n" print item sys.exit(1) isSelected = item['selected'] isHidden = item['hidden'] offset = [0,0] ctr = 0 while parent != 'ROOT_UUID': # work back through lineage until no more offsets. ctr +=1 if ctr > 30: sys.exit(1) parentFrame,grandParent = walker.frameByUUID[parent] offset = [offset[0] + parentFrame[0], offset[1] +parentFrame[1]] parent = grandParent try: xframe = [frame[0] + offset[0], frame[1] + offset[1], frame[2], frame[3]] except TypeError: print "Type error in collect" print "frame", xframe, "offset", offset if not isHidden and level: scaledFrame = [x*self.ratio for x in xframe] path = ui.Path.rect(*scaledFrame) ui.set_color((depthColors[level]) + (0.5,)) path.fill() ui.set_color(0.5) path.line_width = 5 if isSelected else 2 path.stroke()
def draw(self): ui.set_color((1,0,0)) drawpts=[p for p in self.pts] if self.currpt: drawpts+=[self.currpt] if drawpts: pth=ui.Path() pth.move_to(*drawpts[0]) p0=drawpts[0] for p in drawpts[1:]: if p: pth.line_to(*p) L=(ui.Point(*p)-ui.Point(*p0)) P0=ui.Point(*p0) p0=p H=P0+L/2 ui.draw_string('%3.2f'%abs(L*float(self.scale.text)),(H.x,H.y,0,0),color='red') pth.stroke() ui.Path.oval(drawpts[-1][0]-5,drawpts[-1][1]-5,10,10).fill()
def draw(self): square_size=min(self.width,self.height) N=self.N Nb=self.Nb dx=square_size*1.0/(N+2) dxb=N*dx/Nb h,s,v=self.current i0,j0,k0=(round(c*N) for c in self.current) k0=round(self.current[2]*Nb) #draw H/S grid for i in xrange(0,N): for j in xrange(0,N): ui.set_color(colorsys.hsv_to_rgb(i*1.0/N,j*1.0/N,v)) ui.set_blend_mode(ui.BLEND_NORMAL) ui.fill_rect(round(i*dx),round(j*dx),round(dx),round(dx)) #draw V slider for k in xrange(0,Nb): ui.set_color(colorsys.hsv_to_rgb(h,s,k*1./Nb)) ui.set_blend_mode(ui.BLEND_NORMAL) ui.fill_rect(round((N+1)*dx),round(k*dxb),round(dx),round(dxb+0.5)) #highlight selection if all([c>=0 for c in self.current]): ui.set_color(colorsys.hsv_to_rgb(h,s,1-0.5*(1-v))) p=ui.Path.rect(i0*dx,j0*dx,dx,dx) p.line_width=4 p.stroke() ui.set_color(colorsys.hsv_to_rgb(h,s,1-0.5*(1-v))) p=ui.Path.rect((N+1)*dx,k0*dxb,dx,dxb) p.line_width=4 p.stroke() #preview ui.set_color(colorsys.hsv_to_rgb(h,s,v)) ui.fill_rect(0,(N+1)*dx,6*dx,dx) r,g,b=colorsys.hsv_to_rgb(h,s,v) clip=lambda x:min(max(x,0),1) rp,gp,bp=colorsys.hsv_to_rgb(1-h,1,clip((0.5-v)*100)) ui.draw_string( ('{:02x}'*3).format(int(r*255),int(g*255),int(b*255)), (0,(N+1)*dx,6*dx,dx),alignment=ui.ALIGN_CENTER,color=(rp,gp,bp))