Beispiel #1
0
 def stop(self):
     if self.drawing:
         self.drawing = False
         pyglet.clock.unschedule(self.paint)
         self.should_init = True
         graphics.call_thrice(self.draw_fill)
         graphics.call_much_later(self.init)
         self.pixels, self.pixel_colors = self.pixels_old, self.pixel_colors_old
Beispiel #2
0
 def paint(self, dt=0):
     if not self.drawing or len(self.to_check) < 1:
         self.stop()
         return
     start_time = time.clock()
     while len(self.to_check) > 0 and time.clock()-start_time < 1.0/40.0:
         for x, y, ox, oy in self.to_check:
             if x > 0 and y > 0 and x < self.canvas_pre.width and y < self.canvas_pre.height:
                 if self.checked_pixels[x][y] == 0:
                     pos = self.get_pixel_array_pos(x,y)
                     r = self.pixel_data[pos]/255.0
                     g = self.pixel_data[pos+1]/255.0
                     b = self.pixel_data[pos+2]/255.0
                     #a = self.pixel_data[pos+3]/255.0
                     self.checked_pixels[x][y] = 1
                     difference =  abs(r-self.original_color[0])
                     difference += abs(g-self.original_color[1])
                     difference += abs(b-self.original_color[2])
                     if difference < self.threshold:
                         if self.point_test(x,y):
                             self.pixels.extend((x+graphics.canvas_x,y+graphics.canvas_y))
                             self.pixel_colors.extend(self.color_function(x, y))
                         if x-1 != ox: self.new_pixels.append((x-1,y,x,y))
                         if x+1 != ox: self.new_pixels.append((x+1,y,x,y))
                         if y-1 != oy: self.new_pixels.append((x,y-1,x,y))
                         if y+1 != oy: self.new_pixels.append((x,y+1,x,y))
         self.to_check = self.new_pixels
         self.new_pixels = []
     if len(self.to_check) < 1:
         pyglet.clock.unschedule(self.paint)
         self.should_init = True
         self.drawing = False
         graphics.call_thrice(self.draw_fill)
         graphics.call_much_later(self.init)
         self.pixels, self.pixel_colors = self.pixels_old, self.pixel_colors_old
     else:
         self.draw_fill()