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_texture_image(self, A_pos, AB_V3, AD_V3, pixels): width = 10 height = 50 # UV補間の考え方で画像を描画する方法 for y in range(0, height): for x in range(0, width): u = x / width v = y / height # a + u(d - a) r_AD_V3 = [u * AD_V3[0], u * AD_V3[1], u * AD_V3[2]] # a + v(b - a) r_AB_V3 = [v * AB_V3[0], v * AB_V3[1], v * AB_V3[2]] # r_V3 = [ A_pos[0] + r_AB_V3[0] + r_AD_V3[0], A_pos[1] + r_AB_V3[1] + r_AD_V3[1], A_pos[2] + r_AB_V3[2] + r_AD_V3[2] ] # 投影 draw_x, draw_y = self.projection(r_V3[0], r_V3[1], r_V3[2]) # 画像のピクセル数値を取得 r = pixels[y][x][0] g = pixels[y][x][1] b = pixels[y][x][2] ui.set_color((r / 255, g / 255, b / 255, 1.0)) ui.fill_rect(draw_x, draw_y, 1, 1)
def draw(self): if self.tracking: ui.set_color('black') ui.fill_rect(0, 0, self.width, self.height) else: base_color = tuple([self.color[i] for i in range(3)]) opacity_increment = 1.0 / (len(self.current_move) + 1) # 0.002 alpha_incremental = 1.0 - self.animate_counter * opacity_increment if self.animate_counter > 0: for i in range(1, self.animate_counter): alpha_actual = max(0, alpha_incremental) self.draw_segment(base_color + (alpha_actual, ), self.current_move[i - 1], self.current_move[i]) alpha_incremental += opacity_increment if len(self.waypoints_hit_this_turn) > 0: (hit_distance, waypoint_index) = self.waypoints_hit_this_turn[0] if self.animate_counter >= hit_distance: sound.play_effect('digital:PowerUp1') self.waypoints[ waypoint_index].background_color = '#6cd655' self.waypoints_hit_this_turn = self.waypoints_hit_this_turn[ 1:] if self.animation_state == 'sploding': splode_alpha = 1.0 - self.splosion_counter * 0.15 splode_radius = self.splosion_counter * 4 splode_color = base_color + (splode_alpha, ) (x, y) = self.current_move[-1] path = ui.Path.oval(x - splode_radius, y - splode_radius, 2 * splode_radius, 2 * splode_radius) ui.set_color(splode_color) path.fill()
def clear_image(self, sender): with ui.ImageContext(self.width, self.height) as setup: self.background = ui.Path() ui.set_color(self.bg_color) ui.fill_rect(0, 0, self.width, self.height) bg = self.background.rect(0, 0, self.width, self.height) self.background = setup self.canvas.image = setup.get_image()
def get_diamond(color): with ui.ImageContext(100, 100) as ctx: ui.set_color(color) with ui.GState(): ui.concat_ctm(ui.Transform.rotation(45/180*math.pi)) a = 0.1 ui.fill_rect((0.5+a)/math.sqrt(2)*100, (a-0.5)/math.sqrt(2)*100, math.sqrt(2)*(0.5-a)*100, math.sqrt(2)*(0.5-a)*100) im = ctx.get_image() return im
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 fill_rect(self, xorg, yorg, width, height, color=(1, 1, 1)): w, h = self.whWorld(width, height) x, y = self.xyWorld(xorg, yorg) print('fill rect xy:%s, wh:%s with:%s' % ((x, y + h), (w, -h), color)) if IMGDRW: with ui.ImageContext(w, -h) as ctx: img = Image.new("RGB", (int(w), int(-h)), color) #img.draw() else: ui.set_color(color) self.path.append_path(ui.Path.rect()) ui.fill_rect(x, y, w, -h) ui.set_color((0, 0, 0))
def main(): images = photos.pick_image(multi=True, original=upload_originals, raw_data=upload_originals) if images is None: return for i, img in enumerate(images): print('Uploading image %i/%i...' % (i + 1, len(images))) if not upload_originals: b = BytesIO() img.save(b, 'JPEG', quality=jpeg_quality) data = b.getvalue() else: data = img r = requests.post('http://how-old.net/Home/Analyze?isTest=False', files={'file': ('someimage.jpg', data)}) d = json.loads(json.loads(r.text)) faces = d.get('Faces') ui_img = ui.Image.from_data(data) scale = result_size / max(ui_img.size) w, h = ui_img.size[0] * scale, ui_img.size[1] * scale with ui.ImageContext(w, h) as ctx: ui_img.draw(0, 0, w, h) for face in faces: rect = [ float(face['faceRectangle'][key]) * scale for key in ['left', 'top', 'width', 'height'] ] caption_rect = (rect[0], rect[1], max(40, rect[2]), 16) ui.set_color((0, 0, 0, 0.5)) ui.Path.rect(*rect).stroke() ui.fill_rect(*caption_rect) attrs = face['attributes'] age = attrs['age'] if age % 1.0 == 0: age = int(age) caption = '%s (%s)' % (age, attrs['gender'][0]) ui.draw_string(caption, caption_rect, color='white') result_img = ctx.get_image() result_img.show() if faces: faces_str = ', '.join([ '%s (%s)' % (face['attributes']['age'], face['attributes']['gender']) for face in faces ]) print('%i face%s: %s' % (len(faces), 's' if len(faces) != 1 else '', faces_str)) else: print('No faces found') print('Done')
def draw(self): self.y = 0 square_size = max(self.width, self.height) N = self.N Nb = self.Nb dx = square_size * 1.0 / (N + 3) 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 range(0, N + 1): for j in range(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 * self.height / Nb), round(dx), round(self.height + 1 / Nb)) #draw V slider for k in range(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.5) * dx), round(k * self.height / Nb), round(dx), round(self.height / Nb + 0.5)) #highlight selection if all([c >= 0 for c in self.current]): # h,s selection ui.set_color(colorsys.hsv_to_rgb(h - 0.1, s, 1 - 0.5 * v)) p = ui.Path.rect(i0 * dx, j0 * (self.height + 10) / Nb, dx, self.height / Nb) p.line_width = 4 p.stroke() # v selection ui.set_color(colorsys.hsv_to_rgb(h, s, 1 - 0.5 * (0.2 + v))) p = ui.Path.rect((N + 1.5) * dx, k0 * (self.height - 10) / Nb, dx, self.height / Nb) p.line_width = 4 p.stroke() self.rgb = colorsys.hsv_to_rgb(self.current[0], self.current[1], self.current[2]) r, g, b = self.rgb self.superview.superview.set_colorView(r, g, b)
def getpic(canvas, arg=False): with ui.ImageContext(*canvas.bounds[2:4]) as ctx: temp = paths[:-maxpath] if arg else paths if base: base.draw() else: ui.set_color(bg) ui.fill_rect(0, 0, *canvas.bounds[2:4]) for s, c, m in temp: ui.set_color(c) if m == 0: s.stroke() if m == 1: s.fill() return ctx.get_image()
def fill(self): self.history = [] self.future = [] with ui.ImageContext(self.width, self.height) as ctx: ui.set_color('black') ui.fill_rect(0, 0, self.width, self.height) # iv = ui.ImageView(frame=self.bounds) # iv.image = ui.Image('playfields/origami.png') # # img = snapshot(iv) # blend_mode = ui.B # ui.set_blend_mode(blend_mode) #iv.image.draw() # img.draw() self.img = ctx.get_image()
def get_histogram(img): if not img.mode.startswith('RGB'): img = img.convert('RGB') hist = img.histogram() max_h = float(max(hist)) height = 180 with ui.ImageContext(430, height) as ctx: a = 1 rgb = [(1, 0, 0, a), (0, 1, 0, a), (0, 0, 1, a)] for i, color in enumerate(rgb): ui.set_color(color) for j, count in enumerate(hist[i*256:i*256+256]): bar_height = count / max_h * (height - 5) ui.fill_rect(2*j, height-bar_height, 2, bar_height) return ctx.get_image()
def draw(self): global base, paths, touchct, maxpath if DEBUG: self.superview['debug'].text = str(len(paths)) if base: base.draw() else: ui.set_color(bg) ui.fill_rect(0, 0, *self.bounds[2:4]) for s, c, m in paths: ui.set_color(c) if m == 0: s.stroke() if m == 1: s.fill() if touchct == 0 and len(paths) >= maxpath: self.rebase(True)
def draw(self): ui.set_color('#494949') # 绘制y轴 ui.fill_rect(self.y_axe_x,self.y_axe_y,self.y_axe_w,self.y_axe_h) for i in range(int((self.y_axe_h-25)/25)): price=str(i*25) price_x=self.y_axe_x-45 price_y=self.height-self.offsey_y-60-i*25 price_w=40 price_h=20 if(i==0): price="free" ui.draw_string(price,(price_x,price_y,price_w,price_h),('<system>',16),alignment=ui.ALIGN_RIGHT) ui.fill_rect(self.y_axe_x-5,price_y+(price_h-2)/2,5,2)
def newblocks(self): with ui.ImageContext(34, 26) as ctx: for x in range(34): for y in range(26): d = self.data.block( (int(x - self.offset.x), int(y + self.offset.y))) #d = self.data.block((8,0)) #d2,d1 = 1,0 ui.set_color((((d % 16) / 15), 1 - ((d // 16) / 15), 1, 1)) #ui.set_color(3/16) ui.fill_rect(x, y, 1, 1) data = ctx.get_image() i = Texture(data) i.filtering_mode = 1 self.tiles.shader.set_uniform("data", i)
def __init__(self, frame): self.frame = frame # create the imageview that actually shows the image you're drawing. self.canvas = ui.ImageView() self.canvas.frame = frame with ui.ImageContext(self.width, self.height) as setup: background = ui.Path() ui.set_color("white") ui.fill_rect(0, 0, self.width, self.height) bg = background.rect(0, 0, self.width, self.height) self.canvas.image = setup.get_image() self.add_subview(self.canvas) self.color = "black" self.brush_size = 8 self.path = None
def newblocks(self): # get new data with ui.ImageContext(34, 26) as ctx: for x in range(34): for y in range(26): d = self.data.block_get( (int(x - self._offset.x), int(y - self._offset.y))) #d = 45 ui.set_color((((d % 16) / 15), 1 - ((d // 16) / 15), 1, 1)) ui.fill_rect(x, 25 - y, 1, 1) data = ctx.get_image() i = Texture(data) i.filtering_mode = 1 self.shader.set_uniform("data", i) #t = test() #run(t)
def main(): images = photos.pick_image(multi=True, original=upload_originals, raw_data= upload_originals) if images is None: return for i, img in enumerate(images): print 'Uploading image %i/%i...' % (i+1, len(images)) if not upload_originals: b = BytesIO() img.save(b, 'JPEG', quality=jpeg_quality) data = b.getvalue() else: data = img r = requests.post('http://how-old.net/Home/Analyze?isTest=False', files={'file': ('someimage.jpg', data)}) d = json.loads(json.loads(r.text)) faces = d.get('Faces') ui_img = ui.Image.from_data(data) scale = result_size / max(ui_img.size) w, h = ui_img.size[0] * scale, ui_img.size[1] * scale with ui.ImageContext(w, h) as ctx: ui_img.draw(0, 0, w, h) for face in faces: rect = [float(face['faceRectangle'][key]) * scale for key in ['left', 'top', 'width', 'height']] caption_rect = (rect[0], rect[1], max(40, rect[2]), 16) ui.set_color((0, 0, 0, 0.5)) ui.Path.rect(*rect).stroke() ui.fill_rect(*caption_rect) attrs = face['attributes'] age = attrs['age'] if age % 1.0 == 0: age = int(age) caption = '%s (%s)' % (age, attrs['gender'][0]) ui.draw_string(caption, caption_rect, color='white') result_img = ctx.get_image() result_img.show() if faces: faces_str = ', '.join(['%s (%s)' % (face['attributes']['age'], face['attributes']['gender']) for face in faces]) print '%i face%s: %s' % (len(faces), 's' if len(faces) != 1 else '', faces_str) else: print 'No faces found' print 'Done'
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return img = appex.get_image() if not img: print('No input image') return if not img.mode.startswith('RGB'): img = img.convert('RGB') hist = img.histogram() max_h = float(max(hist)) height = 240 with ui.ImageContext(512, height) as ctx: a = 0.5 rgb = [(1, 0, 0, a), (0, 1, 0, a), (0, 0, 1, a)] for i, color in enumerate(rgb): ui.set_color(color) for j, count in enumerate(hist[i*256:i*256+256]): bar_height = count / max_h * height ui.fill_rect(2*j, height-bar_height, 2, bar_height) ctx.get_image().show()
def main(): if not appex.is_running_extension(): print 'This script is intended to be run from the sharing extension.' return img = appex.get_image() if not img: print 'No input image' return if not img.mode.startswith('RGB'): img = img.convert('RGB') hist = img.histogram() max_h = float(max(hist)) height = 240 with ui.ImageContext(512, height) as ctx: a = 0.5 rgb = [(1, 0, 0, a), (0, 1, 0, a), (0, 0, 1, a)] for i, color in enumerate(rgb): ui.set_color(color) for j, count in enumerate(hist[i * 256:i * 256 + 256]): bar_height = count / max_h * height ui.fill_rect(2 * j, height - bar_height, 2, bar_height) ctx.get_image().show()
def draw(self): if self.tracking: ui.set_color('black') ui.fill_rect(0, 0, self.width, self.height) else: if self.animate_counter < len(self.current_move): self.animate_counter += max(20, int(len(self.current_move) / 40)) self.animate_counter = min( len(self.current_move) - 1, self.animate_counter) #self.set_needs_display() base_color = tuple([self.color[i] for i in range(3)]) # if len(self.previous_move) > 0: opacity_increment = 1.0 / (len(self.current_move) + 1) # 0.002 alpha_incremental = 1.0 - self.animate_counter * opacity_increment if self.animate_counter > 0: for i in range(1, self.animate_counter): alpha_actual = max(0, alpha_incremental) self.draw_segment(base_color + (alpha_actual, ), self.current_move[i - 1], self.current_move[i]) alpha_incremental += opacity_increment
def __init__(self, frame): if frame[2] > ss[0] or frame[3] > ss[1]: raise Exception("Paper is too big") else: self.frame = frame # create the imageview that actually shows the image you're drawing. self.canvas = ui.ImageView() self.bg_color = popup["Background"] self.canvas.frame = (0, 0, frame[2], frame[3]) with ui.ImageContext(self.width, self.height) as setup: self.background = ui.Path() ui.set_color(self.bg_color) ui.fill_rect(0, 0, self.width, self.height) bg = self.background.rect(0, 0, self.width, self.height) self.background = setup self.canvas.image = setup.get_image() self.add_subview(self.canvas) self.color = "black" self.brush_size = 8 self.path = None
def drawImg(self): with ui.ImageContext(150,40) as ctx: """-----------draw rate--------------""" rate=0 if(self.old==0): rate=abs(self.new-self.old)*100 else: rate=abs(self.new-self.old)/self.old*100 if(self.old==self.new): pass elif(self.old<self.new): ui.set_color("#eb1a1a") ui.fill_rect(0,0,90,40) ui.draw_string("+{0:.0f}%".format(rate),(0,7,90,26),('Arial',26),'white',ui.ALIGN_CENTER) else: ui.set_color("#638e32") ui.fill_rect(0,0,90,40) ui.draw_string("-{0:.0f}%".format(rate),(0,7,90,26),('Arial',26),"#b6e364",ui.ALIGN_CENTER) """-----------draw price--------------""" priceStr=lambda x : "NULL" if x==-1 else "¥ "+str(x) if x>0 else "Free" if(self.new==self.old): ui.set_color("#103142") ui.fill_rect(25,0,100,40) ui.draw_string(priceStr(self.new),(25,10,100,20),('Arial',20),"#b7e6fc",ui.ALIGN_CENTER) else: ui.set_color("#103142") ui.fill_rect(90,0,60,40) ui.draw_string(priceStr(self.new),(90,18,60,18),('Arial',18),"#b7e6fc",ui.ALIGN_CENTER) ui.draw_string(priceStr(self.old),(90,4,60,14),('Arial',14),"#b7e6fc",ui.ALIGN_CENTER) ui.set_color("#8aa8c7") ui.fill_rect(100,12,40,1) self.img=ctx.get_image()
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))
def draw(self): # This will be called whenever the view's content needs to be drawn. # You can use any of the ui module's drawing functions here to render # content into the view's visible rectangle. # Do not call this method directly, instead, if you need your view # to redraw its content, call set_needs_display(). if len(self._actions) < 2 or self._divisor == 0: return y = 10 mi_start = 0 # pseudo code # # get first entry # set start & y at .minute # know name & color & starttime # while next entry # len = this.minute - start # draw previous name, color, len, starttime i = 0 minutes = 0 prev_id = 0 for ta in self._actions: _t = TiTra.Task.FindTaskid(int(ta["id"])) i += 1 if mi_start != 0: h = float(ta["minute"] - mi_start) / self._divisor if prev_id != 0: minutes += ta["minute"] - mi_start #else: # print(f"{mi_start} / {minutes} 0 found") ui.fill_rect(30, y, 20, h) ui.draw_string(time_str, rect=(2, y - 5, 0, 0), font=('<system>', 10)) # ui.draw_string(str(h), rect=(52,y-5,0,0),font=('<system>', 7)) # ui.draw_string(str(round(y)), rect=(5,y+10,0,0),font=('<system>', 7)) # ui.draw_string(str(ta["minute"]), rect=(52,y-5,0,0),font=('<system>', 7)) ui.draw_string(name_str, rect=(52, y + h / 3, 0, 0), font=('<system>', 9)) y = y + h + 2 #_t=TiTra.Task.FindTaskid(i) # _t=TiTra.Task.FindTaskid(random.randint(0,13)) ui.set_color(_t._farbe) time_str = ta["time"] name_str = _t._name mi_start = ta["minute"] prev_id = int(ta["id"]) if i == len(self._actions): ui.draw_string(ta["time"], rect=(2, y - 5, 0, 0), font=('<system>', 10)) if prev_id != 0: minutes += ta["minute"] - mi_start # about 34px wide so position is width -34 ui.draw_string(f"{float(minutes/60):4.1f} h", rect=(self.width - 34, y - 5, 0, 0), font=('<system>', 10))
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) offset = 1.0 - (math.sqrt(Nb - 1) * 1. / math.sqrt(Nb)) # k0 holds the number of field in value slider # at drawing in line 45 k and Nb are scaled by square root # # v = (math.sqrt(k) * 1. / math.sqrt(Nb) # v * math.sqrt(NB) = math.sqrt(k) # v * v * NB = k scv = self.current[2] - offset # remove when debugging is done k0 = round(scv * scv * Nb) #print (f" sel {float(scv):.3} * Nb = {float(scv * Nb):3.3} ^2*Nb= {float(scv * scv * Nb):3.3} k0 = {k0}") # poking around - should do my math # k0 = #draw H/S grid for i in range(0, N): print(f"{i}:{N}") for j in range(0, N): ui.set_color( colorsys.hsv_to_rgb(i * 1.0 / N, j * 1.0 / (N - 1), 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 range(0, Nb): ui.set_color( colorsys.hsv_to_rgb( h, s, offset + (math.sqrt(k) * 1. / math.sqrt(Nb)))) #if self.__debugprint : #print (f"draw {k} = {(math.sqrt(k) * 1. / math.sqrt(Nb)):.3} off {offset:.3}") # 1-(..) would look nicer but is lot of rework in code # v=1.0 should always be in reach -> how can this be certain? # dont need the darker shades, but more od the lighter ones # add offset? # steeper curve? quadratic would maybe be to steep ui.set_blend_mode(ui.BLEND_NORMAL) ui.fill_rect(round((N + 1) * dx), round(k * dxb), round(dx), round(dxb + 0.5)) #self.__debugprint=False #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))) ui.set_color( colorsys.hsv_to_rgb(1 - 0.5 * (1 - h), (1 - 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(1 - 0.5 * (1 - h), (1 - 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))
def draw(self): ''' This will be called whenever the view's content needs to be drawn. You can use any of the ui module's drawing functions here to render content into the view's visible rectangle. Do not call this method directly, instead, if you need your view to redraw its content, call set_needs_display(). ''' #Idea doesnt draw in a spiral with smallest in the center - just alternate to right / to bottom if len(self._actions) < 1: return y = 0 x = 0 vertical = True i = 0 # iterate self._actions[:-1] # means we do it not for last one # then execute the code in loop only for last one for ta in self._actions: _t = TiTra.Task.FindTaskName(ta["title"]) ui.set_color(_t._farbe) hell = sum(ui.parse_color(_t._farbe)[0:3]) text_col = "black" if hell < 3 * 0.67: text_col = "white" i += 1 # print(f"\n{i}: {ta['title']} = {ta['percent']:4.2} % = {ta['area']}") # print("farbe=", _t._farbe, ui.parse_color(_t._farbe), hell) # print( # f"Left w/h ({self.LeftWidth}/{self.LeftHeight}) x/y = ({x}/{y}) vertical = {vertical}" # ) if vertical: if self.LeftWidth == 0: # print("LeftWidth==0 return >> ") return y2 = round(ta["area"] / self.LeftWidth) ui.fill_rect(x, y, self.LeftWidth - 1, y2 - 1) # ui.draw_string(str(y2), rect=(x, y + 2, 0, 0), font=('<system>', 6)) ui.draw_string(str(ta["hour"]) + "h", rect=(x + self.LeftWidth / 2 - 8, y + 2, 0, 0), font=('<system>', 7), color=text_col) ui.draw_string(ta['title'], rect=(x + 3, y + y2 / 2 - 4, 0, 0), font=('<system>', 8), color=text_col) # print(f"x/y2 ({x}/{y2}) rect xywh ({x}/{y}, {self.LeftWidth}/{y2})") self.LeftHeight -= y2 y += y2 vertical = False else: if self.LeftHeight == 0: #print("LeftHeight==0 return >> ") return x2 = round(ta["area"] / self.LeftHeight) ui.fill_rect(x, y, x2 - 1, self.LeftHeight - 1) # ui.draw_string(str(x2), rect=(x + 2, y, 0, 0), font=('<system>', 6)) ui.draw_string(str(ta["hour"]) + "h", rect=(x + x2 / 2 - 8, y + 2, 0, 0), font=('<system>', 7), color=text_col) #print(str(ta["hour"]) + "h",ui.measure_string(str(ta["hour"]) + "h", font=('<system>', 7))) ui.draw_string(ta['title'], rect=(x + 3, y + self.LeftHeight / 2 - 4, 0, 0), font=('<system>', 8), color=text_col) # print(f"x2/y ({x2}/{y}) rect xywh ({x}/{y}, {x2}/{self.LeftHeight})") self.LeftWidth -= x2 x += x2 vertical = True
def draw(self): if self._pt: ui.fill_rect(self._pt[0]-10,self._pt[1]-10,20,20)
# image on image img = ui.Image.named('Test_Lenna') with ui.ImageContext(200,200) as ctx: img.draw(0,0,200,200) ui.set_blend_mode(ui.BLEND_MULTIPLY) img.draw(50,50,100,100) result = ctx.get_image() result.show() # rect on image with ui.ImageContext(200,200) as ctx: img.draw(0,0,200,200) ui.set_blend_mode(ui.BLEND_MULTIPLY) ui.set_color('red') ui.fill_rect(50,50,100,100) result = ctx.get_image() result.show() # image on rect with ui.ImageContext(200,200) as ctx: ui.set_color('red') ui.fill_rect(0,0,200,200) ui.set_blend_mode(ui.BLEND_MULTIPLY) img.draw(50,50,100,100) result = ctx.get_image() result.show() ui.set_blend_mode(ui.BLEND_EXCLUSION)
# coding: utf-8 # https://forum.omz-software.com/topic/2632/help-with-screen-sizes/19 import ui, scene scale = scene.get_screen_scale() with ui.ImageContext(100, 100) as ctx: ui.set_color('white') ui.fill_rect(0, 0, 100, 100) ui.set_color('black') ui.fill_rect(0, 3, 100, 2) ui.set_color('black') ui.fill_rect(0, 7, 100, 1) if scale > 1: ui.set_color('black') ui.fill_rect(0, 10, 100, 1 / scale) img = ctx.get_image() img.show()