def draw(mycanvas): #ceci est la fonction qui gere l'ecran global bits left = 80 top = 30 canvas.draw_line((0,30+top),(500,30+top),4,'Blue') cl2 = 'Yellow' canvas.draw_text("ENTREES",(left-30,25+top),24,cl2) canvas.draw_text("SORTIES",(left+250,25+top),24,cl2) canvas.draw_circle((left, 50+top), 10, 2, 'Blue', color(str(bits['A']))) canvas.draw_circle((left+250, 50+top), 10, 2, 'Blue', color(str(bits['A']))) canvas.draw_text("A: "+str(bits['A']),(left+15,58+top),24,cl2) canvas.draw_text("L: "+str(bits['A']),(left+265,58+top),24,cl2) canvas.draw_line((0,290+top),(100,290+top),3,'Red') #canvas.draw_line((150,290+top),(300,290+top),3,'Blue') canvas.draw_line((500,290+top),(150,290+top),3,'Blue') canvas.draw_circle((420, 290+top), 30, 2, 'Blue', color(str(bits['A']))) canvas.draw_text("A",(115,270+top),24,cl2) canvas.draw_text("L",(410,240+top),24,cl2) if bits['A'] == 0: canvas.draw_line((100,290+top),(150,270+top),3,'Orange') else: canvas.draw_line((100,290+top),(150,290+top),3,'Orange') """
def backward(distance): sleep(DELAY) global pos to = (pos[0] - sin(heading) * distance, pos[1] - cos(heading) * distance) if pen_is_down: draw_line(pos[0], pos[1], to[0], to[1]) pos = to
def rstrokedline(start_x, start_y, end_x, end_y): line_width = random.random() * 0.25 + 0.25 canvas.set_line_width(line_width) r, g, b = palette.lightest a = random.random() * 0.25 + 0.05 canvas.set_stroke_color(r, g, b, a) canvas.draw_line(start_x, start_y, end_x, end_y)
def draw(cvs): global y, angle canvas.draw_line((0,0),(500,500),4,'Red') canvas.draw_image(img,(100,100),(200,200),(160,y),(40,40),angle) y = y +0.1 angle = angle + 1
def backward(self, distance): sleep(DELAY) to = (self.pos[0] - sin(self.heading) * distance, self.pos[1] - cos(self.heading) * distance) if self.pen_is_down: set_line_width(self.pen_width) set_stroke_color(self.r_color, self.g_color, self.b_color) draw_line(self.pos[0], self.pos[1], to[0], to[1]) self.pos = to
def dessine(mot,p,e): global to_find for i in range(len(mot)): if mot[i] in to_find: canvas.draw_line((i+1)*e+(i)*p,60,(i+1)*(e+p),60) else: a = (i+1)*e+(i)*p b = (i+1)*(e+p) canvas.draw_text( (a+b)/2 , 50 , mot[i])
def drawHand(width, length, angle): rads = radians(angle) endX = int(cos(angle) * length) + centerX endY = int(sin(angle) * length) + centerY canvas.save_gstate() canvas.set_stroke_color(0.0, 0.0, 0.0, 0.6) canvas.set_line_width(width) canvas.draw_line(centerX, centerY, endX, endY) canvas.restore_gstate()
def draw_tree(x, y, trunk_thickness, leaf_h, tree_w, trunk_h): canvas.begin_path() canvas.move_to(x - tree_w / 2, y + trunk_h) canvas.add_line(x + tree_w / 2, y + trunk_h) canvas.add_line(x, y + trunk_h + leaf_h) canvas.close_path() canvas.set_fill_color(0.25, 0.50, 0.00) canvas.fill_path() canvas.set_stroke_color(0.50, 0.25, 0.00) canvas.set_line_width(trunk_thickness) canvas.draw_line(x, y + trunk_h, x, y)
def draw_grid(min_x, max_x, min_y, max_y): w, h = canvas.get_size() scale_x = w / (max_x - min_x) scale_y = h / (max_y - min_y) min_x, max_x = round(min_x), round(max_x) min_y, max_y = round(min_y), round(max_y) canvas.begin_updates() canvas.set_line_width(1) canvas.set_stroke_color(0.7, 0.7, 0.7) #Draw vertical grid lines: x = min_x while x <= max_x: if x != 0: draw_x = round(w / 2 + x * scale_x) + 0.5 canvas.draw_line(draw_x, 0, draw_x, h) x += 0.5 #Draw horizontal grid lines: y = min_y while y <= max_y: if y != 0: draw_y = round(h/2 + y * scale_y) + 0.5 canvas.draw_line(0, draw_y, w, draw_y) y += 0.5 #Draw x and y axis: canvas.set_stroke_color(0, 0, 0) canvas.draw_line(0, h/2, w, h/2) canvas.draw_line(w/2, 0, w/2, h) canvas.end_updates()
def plot_spectra(self): # calculate scale and axis label steps: scale_x = (688.0 - 2 * self.x_offset) / (self.x_max - self.x_min) scale_y = (688.0 - 2 * self.y_offset) / (self.y_max - self.y_min) step_x = scale_x * (self.x_max - self.x_min) / 10 step_y = scale_y * (self.y_max - self.y_min) / 10 # Draw x and y axix: canvas.set_stroke_color(0, 0, 0) # x-axis canvas.draw_line(self.x_offset, self.y_offset, 688, self.y_offset) # y-axis canvas.draw_line(self.x_offset, self.y_offset, self.x_offset, 688) # label and mark the axes.. for i in range(11): canvas.set_fill_color(0, 0, 0) # x-axis... label = self.x_axis_format.format(self.x_min + i * (self.x_max - self.x_min) / 10) canvas.draw_text(label, self.x_offset + step_x * i, 0, font_name='Helvetica', font_size=16) canvas.draw_line(self.x_offset + step_x * i, self.y_offset - 5, self.x_offset + step_x * i, self.y_offset) # y-axis... label = self.y_axis_format.format(self.y_min + i * (self.y_max - self.y_min) / 10) canvas.draw_text(label, 0, self.y_offset + step_y * i, font_name='Helvetica', font_size=16) canvas.draw_line(self.x_offset - 5, self.y_offset + step_y * i, self.x_offset, self.y_offset + step_y * i) # draw each dataset... for j in range(len(self.x_set)): temp_x = [] temp_y = [] temp_colour = [] temp_x = self.x_set[j] temp_y = self.y_set[j] canvas.set_stroke_color(*self.spectrum_colour[j]) canvas.set_line_width(2) canvas.move_to(self.x_offset + scale_x * (temp_x[0] - self.x_min), self.y_offset + scale_y * (temp_y[0] - self.y_min)) for i in range(len(temp_x)): draw_x = self.x_offset + scale_x * (temp_x[i] - self.x_min) draw_y = self.y_offset + scale_y * (temp_y[i] - self.y_min) if (self.style[j] == '-'): canvas.add_line(draw_x, draw_y) if (self.style[j] == 'o'): canvas.add_ellipse(draw_x - 3, draw_y - 3, 6, 6) canvas.draw_path()
def draw(cnvs): global x_min,y_min,x_max,y_max, x, y #print len(y) #canvas.fill_rect(0,0,W,H) last = (0,H/2) axex = 0 if y == None: return for i in range(len(y)): ab = x[i][0] #print ab ordon = float(y[i]) x1 = ((ab - x_min) / (x_max - x_min))* W y1 = H - ((ordon - y_min) / (y_max - y_min))* H axex = (( - x_min) / (x_max - x_min))*W axey = H - ((- y_min) / (y_max - y_min))* H canvas.draw_line((0,axey), (W,axey), 1, 'White') canvas.draw_line((axex,0), (axex,H), 3, 'White') #y1 = -5*x1 #canvas.draw_circle((x1,y1), 2, 2, 'Blue', 'Yellow') #canvas.draw_text(str(ab)+" "+str(ordon),(x1,y1),12,'Red') if i>0: canvas.draw_line((x1,y1), last, 2, 'Yellow') last = (x1,y1)
def render(self): self.time += 1 canvas.clear() canvas.draw_image(images[self.fond.name], self.fond.center, self.fond.size, (470, 150), self.fond.size2, 0) canvas.draw_image( images[self.ball.info.name], self.ball.info.center, self.ball.info.size, self.ball.pos, self.ball.info.size2, self.ball.angle, ) canvas.draw_line((500, 146), (400, 146), 3, "Red") canvas.draw_text("Score: " + str(self.ball.get_score()), (370, 46), 30, "Orange") c = self.get_kb() if c == "38": self.ball.shooting = True self.ball.shoot() if c == None: self.ball.shooting = False self.ball.update()
def draw(mycanvas): # ceci est la fonction qui gere l'ecran global bits left = 80 top = 30 canvas.draw_line((0, 30 + top), (500, 30 + top), 4, "Blue") cl2 = "Yellow" canvas.draw_text("ENTREES", (left - 30, 25 + top), 24, cl2) canvas.draw_text("SORTIES", (left + 250, 25 + top), 24, cl2) canvas.draw_circle((left, 50 + top), 10, 2, "Blue", color(str(bits["A"]))) canvas.draw_circle((left, 73 + top), 10, 2, "Blue", color(str(bits["B"]))) canvas.draw_circle((left, 96 + top), 10, 2, "Blue", color(str(bits["C"]))) equ = process(inp.get_text()) canvas.draw_circle((left + 250, 50 + top), 10, 2, "Blue", color(equ)) canvas.draw_text("A: " + str(bits["A"]), (left + 15, 58 + top), 24, cl2) canvas.draw_text("B: " + str(bits["B"]), (left + 15, 80 + top), 24, cl2) canvas.draw_text("C: " + str(bits["C"]), (left + 15, 102 + top), 24, cl2) canvas.draw_text(inp.get_text(), (left + 265, 58 + top), 24, cl2) """
def draw(): global bits, out canvas.fill_rect(0, 0, 500, 500) left = 80 top = 30 canvas.draw_line((0, 30 + top), (500, 30 + top), 4, "Blue") cl2 = "Yellow" canvas.draw_text("ENTREES", (left - 30, 25 + top), 24, cl2) canvas.draw_text("SORTIES", (left + 250, 25 + top), 24, cl2) canvas.draw_circle((left, 50 + top), 10, 2, "Blue", color(str(bits["A"]))) canvas.draw_circle((left, 73 + top), 10, 2, "Blue", color(str(bits["B"]))) canvas.draw_circle((left, 96 + top), 10, 2, "Blue", color(str(bits["C"]))) canvas.draw_circle((left + 170, 50 + top), 10, 2, "Blue", color(out)) canvas.draw_text("A: " + str(bits["A"]), (left + 15, 58 + top), 24, cl2) canvas.draw_text("B: " + str(bits["B"]), (left + 15, 80 + top), 24, cl2) canvas.draw_text("C: " + str(bits["C"]), (left + 15, 102 + top), 24, cl2) canvas.draw_text(inp.get_text(), (left + 185, 58 + top), 24, cl2) """
def render(): global count, timer,a,b, points, lining canvas.clear() c = get_kb() if c == '37': #canvas.draw_text(250,250,"<-") lining = False if c == '39': #canvas.draw_text(250,250,"<-") lining = True ms = get_mouse() if len(ms) > 0: if not (ms in points): points.append(ms) count += 1 for p in points: canvas.draw_circle(p[0],p[1],2) if lining: for i in range(len(points)-1): canvas.draw_line(points[i+1][0],points[i+1][1], points[i][0],points[i][1])
canvas.set_size(width, height) canvas.set_fill_color(*palette.darkest) canvas.fill_rect(0, 0, width, height) canvas.set_fill_color(*random.choice(palette.colors)) canvas.set_stroke_color(*palette.lightest) start_x, start_y = (width / 2.0, height / 2.0) lollipop_points = [] for x in xrange(64): end_x, end_y = (random.random() * (width * 0.8) + (width * 0.1), random.random() * (height * 0.8) + (height * 0.1)) lollipop_points.append((end_x, end_y)) canvas.set_line_width(random.random() * 0.75 + 0.25) canvas.draw_line(start_x, start_y, end_x, end_y) size = random.random() * (width * 0.10) canvas.fill_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size) canvas.set_line_width(1.25) canvas.draw_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size) for x in xrange(64): end_x, end_y = lollipop_points[x] size = random.random() * (width * 0.10) canvas.fill_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size) canvas.set_line_width(1.25) canvas.draw_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size) canvas.end_updates()
def draw_triangle(x, y, size, num_remaining): r, g, b = random.choice(palette) canvas.set_fill_color(r, g, b, random.random() * 0.75 + 0.25) r, g, b = random.choice(palette) canvas.set_stroke_color(r, g, b, random.random() * 0.5 + 0.5) canvas.set_line_width(random.random() * 2.5 + 0.5) step = math.sqrt(size**2 - (size / 2.0)**2) canvas.move_to(x - step, y - (size / 2.0)) canvas.add_line(x, y + size) canvas.add_line(x + step, y - (size / 2.0)) canvas.add_line(x - step, y - (size / 2.0)) canvas.fill_path() canvas.draw_line(x - step, y - (size / 2.0), x, y + size) canvas.draw_line(x, y + size, x + step, y - (size / 2.0)) canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0)) canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x, y - (size / 2.0)) canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0)) canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0))
def draw_line(x1, y1, x2, y2): canvas.draw_line(x1, y1, x2, y2)
def draw_line(x1, y1, x2, y2): canvas.set_line_width(3) canvas.draw_line(x1, y1, x2, y2)
def rstrokedline(start_x, start_y, end_x, end_y): line_width = random.random() * 0.75 + 0.25 canvas.set_line_width(line_width) a = random.random() * 0.25 + 0.05 canvas.set_stroke_color(1.0, 1.0, 1.0, a) canvas.draw_line(start_x, start_y, end_x, end_y)
canvas.set_fill_color(0.4, 0, 0) canvas.fill_ellipse(0, 0, w, h) canvas.set_fill_color(0.8, 0, 0) canvas.fill_ellipse(20, 20, w - 40, h - 40) #canvas.draw_text("Computer Generated Art", 65, 440, font_size=33) originX = w / 2 originY = h / 2 for i in range(1, 300, 5): x1 = originX y1 = originY x2 = 100 + i y2 = 0 canvas.draw_line(x1, y1, x2, y2) for i in range(1, 500, 5): x1 = originX y1 = originY x2 = i y2 = canvas.get_size()[0] canvas.draw_line(x1, y1, x2, y2) canvas.set_fill_color(0, 0.7, 0) for i in range(40, 460, 20): x = i + 5 y = originY - 5 canvas.fill_rect(x, y, 10, 10)
def draw_grid(): console.clear() canvas.set_size(size_x, size_y) canvas.begin_updates() canvas.set_line_width(1) canvas.set_stroke_color(0.7, 0.7, 0.7) #Draw vertical grid lines: x = grid while x <= max(abs(min_x), abs(max_x)): cx = t_c_x(x) if cx > 0 and cx < size_x: canvas.draw_line(cx, 0, cx, size_y) cx = t_c_x(-x) if cx > 0 and cx < size_x: canvas.draw_line(cx, 0, cx, size_y) x += grid y = grid while y <= max(abs(min_y), abs(max_y)): cy = t_c_y(y) if cy > 0 and cy < size_y: canvas.draw_line(0, cy, size_x, cy) cy = t_c_y(-y) if cy > 0 and cy < size_y: canvas.draw_line(0, cy, size_x, cy) y += grid canvas.set_stroke_color(0, 0, 0) cx = t_c_x(0) if cx > 0 and cx < size_x: canvas.draw_line(cx, 0, cx, size_y) cy = t_c_y(0) if cy > 0 and cy < size_y: canvas.draw_line(0, cy, size_x, cy) canvas.end_updates()
def render(self): #global errors, mot, to_find, msg , end_game canvas.clear() if self.msg <> None: canvas.draw_text(200,250,self.msg) if self.end_game: canvas.add_button(26*18,0,18,18,"@") c = self.get_mouse() if c <> None: #une lettre est cliquee mouse_handler #canvas.draw_text(200,250,c) self.mouse_handler(c) w = 18 for i in range(26): canvas.add_button(i*w,0,18,18,chr(65+i)) n = len(self.mot) p = (500 * 2) / ( 3*n + 1 ) e = p / 2 for i in range(len(self.mot)): if self.mot[i] in self.to_find: canvas.draw_line((i+1)*e+(i)*p,80,(i+1)*(e+p),80) else: a = (i+1)*e+(i)*p b = (i+1)*(e+p) canvas.draw_text((a+b)/2 - e/2 , 70, self.mot[i]) if (self.errors > 1): canvas.draw_line(100,400,200,400) if (self.errors >= 2): canvas.draw_line(100,400,200,400) if (self.errors >= 3): canvas.draw_line(150,400,150,150) if (self.errors >= 4): canvas.draw_line(150,150,300,150) if (self.errors >= 5): canvas.draw_line(225,150,150,230) if (self.errors >= 6): canvas.draw_line(300,150,300,180) if (self.errors >= 7): canvas.draw_circle(300,200,20) if (self.errors >= 8): canvas.draw_line(300,220,300,300) if (self.errors >= 9): canvas.draw_line(300,300,330,360) if (self.errors >= 10): canvas.draw_line(300,300,270,360) if (self.errors >= 11): canvas.draw_line(300,240,330,300) if (self.errors >= 12): canvas.draw_line(300,240,270,300)
def draw(): #ceci est la fonction qui gere l'ecran global bits canvas.fill_rect(0,0,500,500) left = 80 top = 30 canvas.draw_line((0,30+top),(500,30+top),4,'Blue') cl2 = 'Yellow' canvas.draw_text("ENTREES",(left-30,25+top),24,cl2) canvas.draw_text("SORTIES",(left+250,25+top),24,cl2) if (bits['A']+bits['B'] >= 1): equ = 1 else: equ = 0 canvas.draw_circle((left, 50+top), 10, 2, 'Blue', color(str(bits['A']))) canvas.draw_circle((left, 80+top), 10, 2, 'Blue', color(str(bits['B']))) canvas.draw_circle((left+250, 50+top), 10, 2, 'Blue', color(str(equ))) canvas.draw_text("A: "+str(bits['A']),(left+15,58+top),24,cl2) canvas.draw_text("B: "+str(bits['B']),(left+15,88+top),24,cl2) canvas.draw_text("L: "+str(equ),(left+265,58+top),24,cl2) canvas.draw_line((0,290+top),(100,290+top),3,'Red') canvas.draw_line((150,350+top),(200,350+top),3,'Blue') canvas.draw_line((50,350+top),(100,350+top),3,'Red') canvas.draw_line((50,350+top),(50,290+top),3,'Red') canvas.draw_line((200,350+top),(200,290+top),3,'Blue') canvas.draw_line((500,290+top),(150,290+top),3,'Blue') canvas.draw_circle((420, 290+top), 30, 2, 'Blue', color(str(equ))) canvas.draw_text("A",(115,270+top),24,cl2) canvas.draw_text("B",(115,320+top),24,cl2) canvas.draw_text("L",(410,240+top),24,cl2) if bits['A'] == 0: canvas.draw_line((100,290+top),(150,270+top),3,'Orange') else: canvas.draw_line((100,290+top),(150,290+top),3,'Orange') if bits['B'] == 0: canvas.draw_line((100,350+top),(150,330+top),3,'Orange') else: canvas.draw_line((100,350+top),(150,350+top),3,'Orange') """
def draw_line(self, x1, y1, x2, y2): return canvas.draw_line(*self.xyWorld(x1, y1), *self.xyWorld(x2, y2))
# https://gist.github.com/omz/5087533 import canvas canvas.set_size(512, 512) from_point = (10, 10) cp1 = (40, 200) #control point 1 cp2 = (350, 50) #control point 2 to_point = (300, 300) # Draw the actual curve: canvas.begin_path() canvas.move_to(from_point[0], from_point[1]) canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1]) canvas.set_line_width(2) canvas.draw_path() # Draw the red dots and lines to illustrate what's happening: canvas.set_stroke_color(1, 0, 0) canvas.set_fill_color(1, 0, 0) # Draw straight lines between the control points and the end points: canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1]) canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1]) # Draw red squares on all the points: canvas.fill_rect(from_point[0]-4, from_point[1]-4, 8, 8) canvas.fill_rect(to_point[0]-4, to_point[1]-4, 8, 8) canvas.fill_rect(cp1[0]-4, cp1[1]-4, 8, 8) canvas.fill_rect(cp2[0]-4, cp2[1]-4, 8, 8)
def process(): global errors if (errors >= 1): canvas.draw_line(100,400,200,400) if (errors >= 2): canvas.draw_line(100,400,200,400) if (errors >= 3): canvas.draw_line(150,400,150,150) if (errors >= 4): canvas.draw_line(150,150,300,150) if (errors >= 5): canvas.draw_line(225,150,150,230) if (errors >= 6): canvas.draw_line(300,150,300,180) if (errors >= 7): canvas.draw_circle(300,200,20) if (errors >= 8): canvas.draw_line(300,220,300,300) if (errors >= 9): canvas.draw_line(300,300,330,360) if (errors >= 10): canvas.draw_line(300,300,270,360) if (errors >= 11): canvas.draw_line(300,240,330,300) if (errors >= 12): canvas.draw_line(300,240,270,300)
def draw_triangle(x, y, size, num_remaining): if num_remaining > 0: canvas.set_fill_color(*shade_of(random.choice(palette.colors))) canvas.set_stroke_color(*shade_of(random.choice(palette.colors))) canvas.set_line_width(random.random() * 0.5 + 0.5) step = math.sqrt(size**2 - (size / 2.0)**2) canvas.move_to(x - step, y - (size / 2.0)) canvas.add_line(x, y + size) canvas.add_line(x + step, y - (size / 2.0)) canvas.add_line(x - step, y - (size / 2.0)) canvas.fill_path() canvas.draw_line(x - step, y - (size / 2.0), x, y + size) canvas.draw_line(x, y + size, x + step, y - (size / 2.0)) canvas.draw_line(x + step, y - (size / 2.0), x - step, y - (size / 2.0)) canvas.draw_line(x, y, x - (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x, y, x, y - (size / 2.0)) canvas.draw_line(x - (step / 2.0), y + (size / 4.0), x + (step / 2.0), y + (size / 4.0)) canvas.draw_line(x + (step / 2.0), y + (size / 4.0), x, y - (size / 2.0)) canvas.draw_line(x, y - (size / 2.0), x - (step / 2.0), y + (size / 4.0)) draw_triangle(random.random() * width, random.random() * height, random.random() * triangle_side, num_remaining - 1)
canvas.begin_updates() canvas.set_size(width, height) canvas.set_fill_color(*palette['darkest']) canvas.fill_rect(0, 0, width, height) canvas.set_fill_color(*random.choice(palette['palette'])) canvas.set_stroke_color(*palette['lightest']) start_x, start_y = (width / 2.0, height / 2.0) lollipop_points = [] for x in xrange(64): end_x, end_y = (random.random() * (width * 0.8) + (width * 0.1), random.random() * (height * 0.8) + (height * 0.1)) lollipop_points.append((end_x, end_y)) canvas.set_line_width(random.random() * 0.75 + 0.25) canvas.draw_line(start_x, start_y, end_x, end_y) for x in xrange(64): end_x, end_y = lollipop_points[x] size = random.random() * 128.0 + 32.0 canvas.fill_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size) canvas.set_line_width(1.25) canvas.draw_ellipse(end_x - (size / 2.0), end_y - (size / 2.0), size, size) size = random.random() * 128.0 + 32.0 canvas.fill_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size) canvas.set_line_width(1.25) canvas.draw_ellipse(start_x - (size / 2.0), start_y - (size / 2.0), size, size) canvas.end_updates()
def draw(): global bits, out canvas.fill_rect(0,0,500,500) left = 80 top = 30 canvas.draw_line((0,30+top),(500,30+top),4,'Blue') cl2 = 'Yellow' canvas.draw_text("ENTREES",(left-30,25+top),24,cl2) canvas.draw_text("SORTIES",(left+250,25+top),24,cl2) canvas.draw_circle((left, 50+top), 10, 2, 'Blue', color(str(bits['A']))) canvas.draw_circle((left, 73+top), 10, 2, 'Blue', color(str(bits['B']))) canvas.draw_circle((left, 96+top), 10, 2, 'Blue', color(str(bits['C']))) canvas.draw_circle((left+170, 50+top), 10, 2, 'Blue', color(out)) canvas.draw_text("A: "+str(bits['A']),(left+15,58+top),24,cl2) canvas.draw_text("B: "+str(bits['B']),(left+15,80+top),24,cl2) canvas.draw_text("C: "+str(bits['C']),(left+15,102+top),24,cl2) canvas.draw_text(inp.get_text(),(left+185,58+top),24,cl2) """ A FAIRE: Dessiner avec draw_circle et draw_line les interrupteurs et les faire basculer et eteindre quand les entrees changent """ #dessin des fils canvas.draw_line((0,290+top),(100,290+top),3,'Blue') canvas.draw_line((150,290+top),(200,290+top),3,'Blue') canvas.draw_line((200,230+top),(200,350+top),3,'Blue') canvas.draw_line((200,230+top),(250,230+top),3,'Blue') canvas.draw_line((200,350+top),(250,350+top),3,'Blue') canvas.draw_line((300,230+top),(350,230+top),3,'Red') canvas.draw_line((300,350+top),(350,350+top),3,'Red') canvas.draw_line((350,230+top),(350,350+top),3,'Red') canvas.draw_line((500,290+top),(350,290+top),3,'Red') canvas.draw_circle((420, 290+top), 30, 2, 'Blue', color(out)) canvas.draw_text("A",(115,270+top),24,cl2) canvas.draw_text("B",(267,210+top),24,cl2) canvas.draw_text("C",(267,330+top),24,cl2) #dessin des interrupteurs if bits['C'] == 0: canvas.draw_line((250,350+top),(300,350+top),3,'Orange') else: canvas.draw_line((250,350+top),(300,330+top),3,'Orange')
def line(x1, y1, x2, y2): canvas.draw_line(t_c_x(x1), t_c_y(y1), t_c_x(x2), t_c_y(y2))
import canvas canvas.set_size(512, 512) from_point = (10, 10) cp1 = (40, 200) #control point 1 cp2 = (350, 50) #control point 2 to_point = (300, 300) # Draw the actual curve: canvas.begin_path() canvas.move_to(from_point[0], from_point[1]) canvas.add_curve(cp1[0], cp1[1], cp2[0], cp2[1], to_point[0], to_point[1]) canvas.set_line_width(2) canvas.draw_path() # Draw the red dots and lines to illustrate what's happening: canvas.set_stroke_color(1, 0, 0) canvas.set_fill_color(1, 0, 0) # Draw straight lines between the control points and the end points: canvas.draw_line(from_point[0], from_point[1], cp1[0], cp1[1]) canvas.draw_line(to_point[0], to_point[1], cp2[0], cp2[1]) # Draw red squares on all the points: canvas.fill_rect(from_point[0] - 4, from_point[1] - 4, 8, 8) canvas.fill_rect(to_point[0] - 4, to_point[1] - 4, 8, 8) canvas.fill_rect(cp1[0] - 4, cp1[1] - 4, 8, 8) canvas.fill_rect(cp2[0] - 4, cp2[1] - 4, 8, 8)
def paint(self, width, height): # start with unit diagonal self.unit_diagonal(self.view_tm) # rotate object self.rotx(self.xinc, self.rotx_tm) self.am4x4(self.view_tm, self.rotx_tm, self.view_tm) self.roty(self.yinc, self.roty_tm) self.am4x4(self.view_tm, self.roty_tm, self.view_tm) self.rotz(self.zinc, self.rotz_tm) self.am4x4(self.view_tm, self.rotz_tm, self.view_tm) # scale self.scaleit(self.scale, self.scale, self.scale, self.scale_tm) self.am4x4(self.view_tm, self.scale_tm, self.view_tm) # move coordinates to origin self.trans(-self.xe, -self.ye, -self.ze, self.trans_tm) self.am4x4(self.view_tm, self.trans_tm, self.view_tm) # rotate -90 deg. about x axis self.rotx(1.5708, self.rotx_tm) self.am4x4(self.view_tm, self.rotx_tm, self.view_tm) # rotate -theta about y axis theta = math.atan2(-(self.xe - self.xt), -(self.ye - self.yt)) self.roty(-theta, self.roty_tm) self.am4x4(self.view_tm, self.roty_tm, self.view_tm) # rotate -phi around x axis phi = math.atan2((self.ze - self.zt), math.sqrt((self.xe - self.xt) * (self.xe - self.xt) + (self.ye - self.yt) * (self.ye - self.yt))) self.rotx(-phi, self.rotx_tm) self.am4x4(self.view_tm, self.rotx_tm, self.view_tm) # change rh to lh coordinates self.scaleit(1, -1, -1, self.scale_tm) self.am4x4(self.view_tm, self.scale_tm, self.view_tm) # add perspective if self.persp: self.perspect(self.s, self.d, self.persp_tm) self.am4x4(self.view_tm, self.persp_tm, self.view_tm) # transform the view self.am20x4(self.view_tm, self.view) # draw the view in width/height orgx = width / 2 orgy = height / 2 if self.persp: for i in range(self.vertnum): self.view[i][0] = (orgx * self.view[i][0] / self.view[i][2]) + orgx self.view[i][1] = (orgy * self.view[i][1] / self.view[i][2]) + orgy canvas.begin_updates() canvas.set_size(width, height) canvas.set_stroke_color(0, 1, 0) for i in range(self.facenum): for j in range(self.edgenum[i] - 1): canvas.draw_line(self.view[self.face[i][j]][0], self.view[self.face[i][j]][1], self.view[self.face[i][j + 1]][0], self.view[self.face[i][j + 1]][1]) canvas.draw_line(self.view[self.face[i][j + 1]][0], self.view[self.face[i][j + 1]][1], self.view[self.face[i][0]][0], self.view[self.face[i][0]][1]) canvas.set_fill_color(0, 1, 0) self.frames += 1 canvas.draw_text( 'Object: ' + self.name + ' Frames: ' + str(self.frames) + ' Angle: ' + str(self.yinc), 10, 10) canvas.end_updates()