Пример #1
0
 def draw_spiral_weave(self, x, y, angle, ds):
     if self.spiral:
         self.spiral_angle += 4.7 * ds * self.freq_scale
     if self.weave:
         self.spiral_angle = angle+math.pi/2
         self.spiral_radius = max(graphics.brush_size,5)*math.sin(self.iteration*self.freq_scale)
     x_add = self.spiral_radius*math.cos(self.spiral_angle)
     y_add = self.spiral_radius*math.sin(self.spiral_angle)
     x1 = x + x_add
     y1 = y + y_add
     x2 = x - x_add
     y2 = y - y_add
     self.last_color_1 = graphics.get_line_color()
     self.last_color_2 = graphics.get_fill_color()
     graphics.set_color(color=self.last_color_1)
     self.draw_point(x1,y1)
     graphics.set_line_width(graphics.brush_size)
     draw.line(x1, y1, self.lastx1, self.lasty1)
     
     graphics.set_color(color=self.last_color_2)
     self.draw_point(x2,y2)
     graphics.set_line_width(graphics.brush_size)
     draw.line(x2, y2, self.lastx2, self.lasty2)
     self.lastx1, self.lasty1 = x1, y1
     self.lastx2, self.lasty2 = x2, y2
Пример #2
0
 def keep_drawing(self, x, y, dx, dy):
     self.x2, self.y2 = x, y
     graphics.set_color(1,1,1,1)
     draw.image(self.canvas_pre,graphics.canvas_x,graphics.canvas_y)
     graphics.set_line_width(graphics.user_line_size)
     graphics.set_color(color=self.line_color)
     draw.line(self.x1, self.y1, self.x2, self.y2)
Пример #3
0
 def draw_shape_rect(self):
     graphics.enable_line_stipple()
     graphics.set_line_width(1.0)
     graphics.set_color(color=graphics.get_line_color())
     draw.rect_outline(
         self.img_x+1, self.img_y+1, self.img_x+abs(self.w)-1, self.img_y+abs(self.h)-1
     )
     graphics.disable_line_stipple()
Пример #4
0
 def stop_drawing(self, x, y):
     if self.dragging and self.selection != None:
         graphics.set_color(1,1,1,1)
         #draw.image(self.selection, self.img_x, self.img_y)
         self.draw_selection_image()
         self.draw_selection_shape()
     else:
         if x != self.mouse_start_x or y != self.mouse_start_y:
             tool.push_undo(self.undo_image)
Пример #5
0
 def keep_drawing(self, x, y, dx, dy):
     self.x2, self.y2 = x, y
     graphics.set_color(1,1,1,1)
     draw.image(self.canvas_pre,graphics.canvas_x,graphics.canvas_y)
     
     if graphics.fill_shapes:
         draw.rect(self.x1, self.y1, self.x2, self.y2, self.fill_colors)
     if graphics.outline_shapes:
         graphics.set_line_width(graphics.user_line_size)
         graphics.set_color(color=self.line_color)
         draw.rect_outline(self.x1, self.y1, self.x2, self.y2)
Пример #6
0
 def keep_drawing(self, x, y, dx, dy):
     graphics.set_color(1,1,1,1)
     self.draw_point(self.lastx,self.lasty)
     self.draw_point(x,y)
     graphics.set_line_width(graphics.brush_size)
     draw.line(x, y, self.lastx, self.lasty)
     graphics.set_color(0.5,0.5,0.5,1)
     graphics.set_line_width(0.8)
     radius = graphics.brush_size*0.8/2
     draw.ellipse_outline(x-radius,y-radius,x+radius,y+radius)
     self.lastx, self.lasty = x, y
Пример #7
0
 def poly_func():
     theta = 0
     y_offset = 0
     if n == 3: y_offset = -5
     if n % 2 == 1: theta = -math.pi/n/2
     poly = draw._concat(draw._iter_ngon(x+w/2,y+h/2+y_offset,(w-10)/2,n,theta))
     graphics.set_color(1,1,1,1)
     draw.polygon(poly)
     graphics.set_color(0,0,0,1)
     graphics.set_line_width(1)
     draw.line_loop(poly)
Пример #8
0
 def finalize_selection(self):
     if self.selection != None:
         graphics.set_color(1,1,1,1)
         draw.image(self.canvas_pre,0,0)
         if not self.copy:
             self.draw_selection_mask(
                 self.original_x, self.original_y,
                 self.original_x+abs(self.w), self.original_y+abs(self.h)
             )
         self.draw_selection_image()
         self.canvas_pre = graphics.get_snapshot()
         self.undo_image = graphics.get_canvas()
Пример #9
0
 def keep_drawing(self, x, y, dx, dy):
     ds = math.sqrt(dx*dx+dy*dy)
     self.iteration += ds
     if self.calligraphy:
         self.draw_calligraphy(x,y,ds)
     elif self.variable:
         self.draw_variable(x,y,ds)
     else:
         self.last_color_1 = graphics.get_line_color()
         graphics.set_color(color=self.last_color_1)
         self.draw_point(x,y)
         graphics.set_line_width(graphics.brush_size)
         draw.line(x, y, self.lastx, self.lasty)
     self.lastx, self.lasty = x, y
Пример #10
0
 def draw_calligraphy(self, x, y, ds):
     brush_mult = max(1.5-min(ds/20.0,1.2),0)
     brush_mult = (self.last_brush_mult+brush_mult)/2
     self.last_brush_mult = brush_mult
     radius = max(graphics.brush_size,3) * brush_mult
     x_add = radius*self.x_mult
     y_add = radius*self.y_mult
     x1 = x + x_add
     y1 = y + y_add
     x2 = x - x_add
     y2 = y - y_add
     graphics.set_color(*graphics.get_line_color())
     draw.quad((x1,y1,self.lastx1,self.lasty1,self.lastx2,self.lasty2,x2,y2))
     self.lastx1, self.lasty1 = x1, y1
     self.lastx2, self.lasty2 = x2, y2
Пример #11
0
 def keep_drawing(self, x, y, dx, dy):
     self.rx, self.ry = x, y
     radius = math.sqrt(
         (self.rx - self.x)*(self.rx - self.x)+(self.ry - self.y)*(self.ry - self.y)
     )
     theta = math.atan2(self.ry-self.y, self.rx-self.x)
     graphics.set_color(1,1,1,1)
     draw.image(self.canvas_pre,graphics.canvas_x,graphics.canvas_y)
     if graphics.fill_shapes:
             #graphics.set_color(color=self.fill_color)
             draw.ngon(self.x,self.y,radius,self.sides,theta, self.fill_colors)
     if graphics.outline_shapes:
         graphics.set_line_width(graphics.user_line_size)
         graphics.set_color(color=self.line_color)
         draw.ngon_outline(self.x, self.y, radius, self.sides, theta)
Пример #12
0
 def draw_shape_ellipse(self):
     graphics.enable_line_stipple()
     graphics.set_line_width(1.0)
     #graphics.set_color(0,0,0,1)
     graphics.set_color(color=graphics.get_line_color())
     old_line_size = graphics.user_line_size
     def temp1():
         graphics.user_line_size = 1.0
     def temp2():
         graphics.user_line_size = old_line_size
     graphics.call_twice(temp1)
     draw.ellipse_outline(
         self.img_x+1, self.img_y+1, self.img_x+abs(self.w)-1, self.img_y+abs(self.h)-1
     )
     graphics.disable_line_stipple()
     graphics.call_twice(temp2)
Пример #13
0
 def start_drawing(self, x, y):
     self.lastx, self.lasty = x, y
     self.lastx1, self.lasty1 = x, y
     self.lastx2, self.lasty2 = x, y
     self.iteration = 0
     if self.calligraphy:
         self.x_mult = math.cos(math.pi/4)
         self.y_mult = math.sin(math.pi/4)
         self.last_brush_mult = 1.5
     elif self.variable:
         self.last_brush_mult = 0.0
     else:
         self.last_color_1 = graphics.get_line_color()
         graphics.set_color(color=self.last_color_1)
         graphics.set_line_width(graphics.brush_size)
         if graphics.brush_size > 1: draw.points((x,y))
Пример #14
0
 def draw_variable(self, x, y, ds):
     brush_mult = max(1.5-min(ds/20.0,1.2),0)
     brush_mult = (self.last_brush_mult+brush_mult)/2.0
     radius = max(graphics.brush_size,3)
     angle = math.atan2(y-self.lasty,x-self.lastx)+math.pi/2.0
     x_add1 = radius*math.cos(angle)*brush_mult*0.96
     y_add1 = radius*math.sin(angle)*brush_mult*0.96
     x_add2 = radius*math.cos(angle)*self.last_brush_mult*0.96
     y_add2 = radius*math.sin(angle)*self.last_brush_mult*0.96
     graphics.set_color(*graphics.get_line_color())
     self.draw_point(x,y,brush_mult*2.0)
     graphics.set_line_width(1.0)
     draw.quad((x+x_add1,           y+y_add1,
                         self.lastx+x_add2,  self.lasty+y_add2,
                         self.lastx-x_add2,  self.lasty-y_add2,
                         x-x_add1,           y-y_add1))
     self.last_brush_mult = brush_mult
Пример #15
0
 def draw_other(self, x, y, angle, ds):
     graphics.set_color(color=self.last_color_1)
     self.state_flip += ds
     if self.state_flip > graphics.brush_size*2:
         self.state_flip = 0
         self.dot_on = not self.dot_on
         if not self.dot_on:
             self.last_color_1 = graphics.get_line_color()
     if self.dot_on or not self.dotted:
         if self.state_flip == 0:
             self.draw_point(self.lastx1, self.lasty1)
         self.draw_point(x,y)
         graphics.set_line_width(graphics.brush_size)
         draw.line(x, y, self.lastx1, self.lasty1)
     if self.arrow_end:
         self.arrow_angle = self.arrow_angle*0.5 + angle*0.5
     self.lastx1, self.lasty1 = x, y
Пример #16
0
 def explode_1(self, dt=0):
     self.explode_iter += dt*400
     x = graphics.canvas_x+(graphics.width-graphics.canvas_x)/2
     y = graphics.canvas_y+(graphics.height-graphics.canvas_y)/2
     graphics.set_color(1,1,1,1)
     draw.ellipse(x-self.explode_iter,y-self.explode_iter,x+self.explode_iter,y+self.explode_iter)
     
     for i in xrange(int(self.explode_iter)/10):
         radius = random.random() * self.explode_iter
         angle = random.random() * math.pi * 2
         px = x + math.cos(angle) * radius
         py = y + math.sin(angle) * radius
         point_radius = 5 + random.randint(0,10)
         graphics.set_color(color=random.choice(graphics.rainbow_colors[0:3]))
         draw.ellipse(px-point_radius,py-point_radius,px+point_radius,py+point_radius)
     
     max_radius = math.sqrt((graphics.width-graphics.canvas_x)*(graphics.width-graphics.canvas_x)/4 + \
                             (graphics.height-graphics.canvas_y)*(graphics.height-graphics.canvas_y)/4)
     if self.explode_iter > max_radius or self.explode_type != 1:
         draw.clear(1,1,1,1)
         pyglet.clock.unschedule(self.explode_1)
Пример #17
0
 def keep_drawing(self, x, y, dx, dy):
     x = min(max(x, graphics.canvas_x), graphics.width)
     y = min(max(y, graphics.canvas_y), graphics.height)
     graphics.set_color(1,1,1,1)
     draw.image(self.canvas_pre,0,0)
     if self.dragging:
         self.x1 = x - self.mouse_offset_x
         self.y1 = y - self.mouse_offset_y
         self.x2, self.y2 = self.x1 + self.w, self.y1 + self.h
         self.img_x = min(self.x1, self.x2)
         self.img_y = min(self.y1, self.y2)
         graphics.set_color(1,1,1,1)
         if not self.copy:
             self.draw_selection_mask(
                 self.original_x, self.original_y,
                 self.original_x+abs(self.w), self.original_y+abs(self.h)
             )
         self.draw_selection_image()
     else:
         self.x2, self.y2 = x, y
         self.w = self.x2 - self.x1
         self.h = self.y2 - self.y1
         self.img_x, self.img_y = min(self.x1, self.x2), min(self.y1, self.y2)
         self.draw_selection_shape()
Пример #18
0
 def draw_railroad_dna(self, x, y, angle, ds):
     self.spiral_angle = angle+math.pi/2
     if self.railroad:
         self.spiral_radius = max(graphics.brush_size*2,10)
     else:
         self.spiral_radius = max(graphics.brush_size*2,10)
         self.spiral_radius *= math.sin(self.iteration*self.freq_scale)
     x_add = self.spiral_radius*math.cos(self.spiral_angle)
     y_add = self.spiral_radius*math.sin(self.spiral_angle)
     x1 = x + x_add
     y1 = y + y_add
     x2 = x - x_add
     y2 = y - y_add
     self.last_color_1 = graphics.get_line_color()
     self.last_color_2 = graphics.get_line_color()
     graphics.set_color(color=self.last_color_1)
     self.draw_point(x1,y1,0.6)
     graphics.set_line_width(graphics.brush_size*0.6)
     draw.line(x1, y1, self.lastx1, self.lasty1)
     graphics.set_color(color=self.last_color_2)
     self.draw_point(x2,y2,0.6)
     graphics.set_line_width(graphics.brush_size*0.6)
     draw.line(x2, y2, self.lastx2, self.lasty2)
     self.state_flip += ds
     if self.railroad:
         x_add *= 1.3
         y_add *= 1.3
     if self.state_flip > graphics.brush_size * 2:
         rx1 = x + x_add
         ry1 = y + y_add
         rx2 = x - x_add
         ry2 = y - y_add
         self.state_flip = 0
         if self.railroad:
             draw.line(rx1,ry1,rx2,ry2)
         else:
             graphics.set_color(color=random.choice(graphics.rainbow_colors))
             draw.line(x,y,rx1,ry1)
             graphics.set_color(color=random.choice(graphics.rainbow_colors))
             draw.line(x,y,rx2,ry2)
     self.lastx1, self.lasty1 = x1, y1
     self.lastx2, self.lasty2 = x2, y2
Пример #19
0
 def draw_selection_image(self):
     if self.selection == None:
         return
     self.img_x, self.img_y = min(self.x1, self.x2), min(self.y1, self.y2)
     graphics.set_color(1,1,1,1)
     self.draw_selection_mask(self.x1,self.y1,self.x2,self.y2)
     
     graphics.init_stencil_mode()
     
     graphics.set_color(1,1,1,1)
     draw.rect(self.x1,self.y1,self.x2,self.y2)
     graphics.set_color(0,0,0,1)
     self.draw_selection_mask(self.x1,self.y1,self.x2,self.y2)
     
     graphics.stop_drawing_stencil()
     
     graphics.set_color(1,1,1,1)
     draw.image(self.selection, self.img_x, self.img_y)
     
     graphics.reset_stencil_mode()
Пример #20
0
 def stop_drawing(self, x, y):
     if self.railroad or self.dna: return
     if self.spiral or self.weave:
         x1 = x + self.spiral_radius*math.cos(self.spiral_angle)
         y1 = y + self.spiral_radius*math.sin(self.spiral_angle)
         x2 = x - self.spiral_radius*math.cos(self.spiral_angle)
         y2 = y - self.spiral_radius*math.sin(self.spiral_angle)
         graphics.set_color(color=self.last_color_1)
         self.draw_point(x1,y1)
         graphics.set_color(color=self.last_color_2)
         self.draw_point(x2,y2)
     else:
         graphics.set_color(color=self.last_color_1)
         self.draw_point(x,y)
         if self.arrow_end:
             draw.ngon(x, y, max(graphics.brush_size*3, 5), 3, self.arrow_angle)
Пример #21
0
    def keep_drawing(self, x, y, dx, dy):
        self.x2, self.y2 = x, y
        graphics.set_color(1, 1, 1, 1)
        draw.image(self.canvas_pre, graphics.canvas_x, graphics.canvas_y)

        if (
            graphics.fill_shapes
            and abs(self.x2 - self.x1) >= graphics.user_line_size
            and abs(self.y2 - self.y1) >= graphics.user_line_size
        ):
            graphics.set_color(color=self.fill_color)
            draw.ellipse(self.x1, self.y1, self.x2, self.y2)
        if graphics.outline_shapes:
            graphics.set_line_width(graphics.user_line_size)
            graphics.set_color(color=self.line_color)
            draw.ellipse_outline(self.x1, self.y1, self.x2, self.y2)
Пример #22
0
 def doodle(self, dt=0):
     if self.fire:
         bs_scaled = int(1.5 + (graphics.brush_size - 1) * 0.2)
         spread = 10 * bs_scaled
         graphics.set_color(*graphics.get_line_color())
         for i in xrange(0, spread*6, max(spread/10, 1)):
             xscale = min(1.0, 0.3+0.7*i/(spread))
             xscale = min(xscale, 0.2+0.8*(spread*6-i)/(spread*6))
             fx = self.x + random.randint(-spread, spread)*xscale
             fy = self.y + -spread + i
             size = (5.0-5.0*(i/float(spread*6))) * bs_scaled // 2
             draw.ellipse(fx-size, fy-size, fx+size, fy+size)
             #draw.points((fx, fy))
         graphics.set_color(*graphics.get_fill_color())
         for i in xrange(0, spread*2, max(spread/10, 1)):
             xscale = min(0.3 + 0.7*i/spread, 1)
             fx = self.x + random.randint(-spread, spread)*xscale
             fy = self.y + -spread + i
             size = (5.0-5.0*(i/float(spread*4))) * bs_scaled // 2
             draw.ellipse(fx-size, fy-size, fx+size, fy+size)
             #draw.points((fx, fy))
     else:
         graphics.set_line_width(graphics.brush_size/2)
         colors = []
         points = [self.make_point() for i in xrange(self.dots_per_frame)]
         if not self.hollow and not self.variable_size:
             draw.points(
                 sum(points,[]),
                 draw._concat([self.get_color() for i in xrange(self.dots_per_frame)])
             )
         else:
             for i in xrange(len(points)):
                 x, y = points[i]
                 if self.variable_size:
                     rad = max(
                         random.random()*graphics.brush_size/2.0 + graphics.brush_size/2.0, 4
                     )
                 else: rad = graphics.brush_size/2.0
                 graphics.set_color(*self.get_color())    
                 if random.random() < self.chance:
                     if self.hollow:
                         graphics.set_line_width(graphics.brush_size*0.2)
                         draw.ellipse_outline(x-rad,y-rad,x+rad,y+rad)
                     else: draw.ellipse(x-rad,y-rad,x+rad,y+rad)
Пример #23
0
	def draw(self):
		# TODO show a caret, maybe use a real TextLayout
		graphics.set_color(1,1,1,1)
		draw.image(self.canvas_pre,graphics.canvas_x,graphics.canvas_y)
		draw.label(self.label)
Пример #24
0
 def stop_drawing(self, x, y):
     if self.calligraphy or self.variable: return
     graphics.set_color(color=self.last_color_1)
     self.draw_point(x,y)
Пример #25
0
 def unselect(self):
     graphics.set_color(1,1,1,1)
     draw.image(self.canvas_pre,0,0)
     graphics.set_color(1,1,1,1)
Пример #26
0
 def keep_drawing(self, x, y, dx, dy):
     graphics.set_color(color=graphics.get_line_color())
     if self.scribble: x, y = self.scramble_coords(x, y)
     draw.line(self.x, self.y, x, y)
     self.x, self.y = x, y
Пример #27
0
 def stop_drawing(self, x, y):
     graphics.set_color(1,1,1,1)
     self.draw_point(x,y)