예제 #1
0
 def release(self, e):
     im = self.helper.im.copy()
     draw = ImageDraw.Draw(im)
     if self.tool == self.toolname['pen']:
         for i in range(len(self.helper.coordsList)):
             draw.line(self.helper.coordsList[i],
                       fill=str2hex(self.color),
                       width=self.width)
     elif self.tool == self.toolname['line']:
         if self.type == 2:
             coords = frieze.repeat(900, 120, 1.5, self.sym, (e.x, e.y))
         for i in range(len(coords)):
             draw.line((self.helper.coords[i][0], self.helper.coords[i][1],
                        coords[i][0], coords[i][1]),
                       width=self.width,
                       fill=str2hex(self.color))
     elif self.tool == self.toolname['fill']:
         if self.type == 2:
             coords = frieze.repeat(900, 120, 1.5, self.sym, (e.x, e.y))
         pic = im.load()
         target = pic[e.x, e.y]
         for i in range(len(coords)):
             self.fill(pic, str2hex(self.color), target, coords[i][0],
                       coords[i][1])
     elif self.tool == self.toolname['eraser']:
         for i in range(len(self.helper.coordsList)):
             draw.line(self.helper.coordsList[i],
                       fill=(255, 255, 255, 0),
                       width=self.width)
     self.helper.new_im(im)
     self.draw()
예제 #2
0
    def hover(self, e):
        # free draw
        if self.type==0 and self.tool==self.toolname['curve'] and self.helper.state==1:
            # generate curve coords, erase old and draw new
            self.helper.coordsList = curvecoords(self.helper.x, self.helper.y,
                self.helper.x2, self.helper.y2, e.x, e.y)
            self.cv.delete('temp')
            for coords in self.helper.coordsList:
                    self.cv.create_line(self.helper.coordsList, width=self.width,
                    fill=self.color, tag='temp')
        # wallpaper
        elif self.type==1 and self.tool==self.toolname['curve'] and self.helper.state==1:
            # generate curve coords, erase old and draw new
            self.helper.xa, self.helper.ya = e.x, e.y   # anchor pos
            # all coords corresponding to start pos of curve
            p1coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                        WALL_P_W, WALL_P_H, self.sym, (self.helper.x, self.helper.y))
            # all coords corresponding to end pos of curve
            p2coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                        WALL_P_W, WALL_P_H, self.sym, (self.helper.x2, self.helper.y2))
            # all coords corresponding to anchor pos of curve
            pacoords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                        WALL_P_W, WALL_P_H, self.sym, (self.helper.xa, self.helper.ya))
            self.helper.coordsList = []
            self.cv.delete('temp')
            # draw all curves
            for i in range(len(p1coords)):
                args = p1coords[i] +p2coords[i] + pacoords[i]
                curve = curvecoords(*args)
                self.helper.coordsList.append(curve)
                self.cv.create_line(curve, width=self.width,
                    fill=self.color, tag='temp')

        # frieze
        elif self.type==2 and self.tool==self.toolname['curve'] and self.helper.state==1:
            self.helper.xa, self.helper.ya = e.x, e.y
            # all coords corresponding to end pos of curve
            p1coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                    self.sym, (self.helper.x, self.helper.y))
            # all coords corresponding to end pos of curve
            p2coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                    self.sym, (self.helper.x2, self.helper.y2))
            # all coords corresponding to end pos of curve
            pacoords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                    self.sym, (self.helper.xa, self.helper.ya))
            self.helper.coordsList = []
            self.cv.delete('temp')
            for i in range(len(p1coords)):
                args = p1coords[i] +p2coords[i] + pacoords[i]
                curve = curvecoords(*args)
                self.helper.coordsList.append(curve)
                self.cv.create_line(curve, width=self.width,
                    fill=self.color, tag='temp')
예제 #3
0
 def press(self, e):
     if self.type == 2:
         self.helper.coords = frieze.repeat(900, 120, 1.5, self.sym,
                                            (e.x, e.y))
         if self.tool in [0, 1, 2, 4]:
             self.helper.coordsList = self.helper.coords
     self.width = self.widthS.get()
예제 #4
0
    def move(self, e):
        if self.type == 2:
            if self.tool == self.toolname['pen']:
                coords = frieze.repeat(900, 120, 1.5, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],
                                        self.helper.coords[i][1],
                                        coords[i][0],
                                        coords[i][1],
                                        width=self.width,
                                        fill=self.color,
                                        tag='temp')
                    self.helper.coordsList[i] += coords[i]

                self.helper.coords = coords
            elif self.tool == self.toolname['line']:
                self.cv.delete('temp')
                coords = frieze.repeat(900, 120, 1.5, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],
                                        self.helper.coords[i][1],
                                        coords[i][0],
                                        coords[i][1],
                                        width=self.width,
                                        fill=self.color,
                                        tag='temp')
            elif self.tool == self.toolname['eraser']:
                coords = frieze.repeat(900, 120, 1.5, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],
                                        self.helper.coords[i][1],
                                        coords[i][0],
                                        coords[i][1],
                                        width=self.width,
                                        fill='white',
                                        tag='temp')
                    self.helper.coordsList[i] += coords[i]

                self.helper.coords = coords
예제 #5
0
 def grid(self):
     if self.type==1:
         coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                     WALL_P_W, WALL_P_H, self.sym, (0,0))
         for i in range(len(coords)):
             self.cv.create_rectangle(coords[i][0], coords[i][1],
                     coords[i][0]+WALL_P_W, coords[i][1]+WALL_P_H, outline='red')
     elif self.type==2:
         coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                     self.sym, (0,0))
         if self.sym ==3:
             for i in range(len(coords)):
                 self.cv.create_rectangle(coords[i][0], coords[i][1],
                         coords[i][0]+self.cvh*FRIEZE_R*0.5, self.cvh, outline='red')
         else:
             for i in range(len(coords)):
                 self.cv.create_rectangle(coords[i][0], coords[i][1],
                         coords[i][0]+self.cvh*FRIEZE_R, self.cvh, outline='red')
예제 #6
0
    def press(self,e):
        if self.type ==0:   # free draw
            self.helper.x =e.x; self.helper.y=e.y # save current mouse pos
            self.helper.coords = [(e.x, e.y)]   # current is first point in line

        elif self.type ==1: # wallpaper
            self.helper.x =e.x; self.helper.y=e.y
            # save points corresponding to current in every cell
            self.helper.coords = wallpaper_patterns.repeat_wallpaper(self.cvw,self.cvh,
                    WALL_P_W, WALL_P_H, self.sym, (e.x, e.y))
            if self.tool in [0,1,4]: # except fill and curve
                self.helper.coordsList = self.helper.coords

        elif self.type == 2:    # frieze
            self.helper.x =e.x; self.helper.y=e.y
            # save points corresponding to current in every cell
            self.helper.coords = frieze.repeat(self.cvw,self.cvh, FRIEZE_R,
                                    self.sym, (e.x, e.y))
            if self.tool in [0,1,4]: # except fill and curve
                self.helper.coordsList = self.helper.coords
        self.width = self.widthS.get()
예제 #7
0
    def release(self, e):
        # make a copy of current image (to facilitate undo)
        im = self.helper.im.copy()
        # make PIL draw instance to draw the lines
        draw = ImageDraw.Draw(im)
        if self.type==0:    # free draw
            if self.tool == self.toolname['pen']:
                draw.line(self.helper.coords, fill=str2hex(self.color)
                , width=self.width)

            elif self.tool == self.toolname['line']:
                draw.line((self.helper.x, self.helper.y, e.x, e.y),
                fill=str2hex(self.color), width=self.width)

            elif self.tool == self.toolname['curve']:
                # in state 0, at release, the end pos is saved
                if self.helper.state==0 and (self.helper.x, self.helper.y)!=(e.x,e.y):
                    self.helper.x2, self.helper.y2 = e.x,e.y
                    self.helper.state=1
                # in state 1, at release, the curve is drawn
                elif self.helper.state==1:
                    draw.line(self.helper.coordsList,fill=str2hex(self.color),
                            width=self.width)
                    self.helper.state=0

            elif self.tool == self.toolname['eraser']:
                draw.line(self.helper.coords, fill=(255,255,255,0)
                , width=self.width)

            elif self.tool == self.toolname['fill']:
                pic = im.load() # load image to memory
                self.fill(pic, str2hex(self.color), pic[e.x, e.y], e.x, e.y)

        if self.type==1:    # wallpaper
            if self.tool == self.toolname['pen']:
                for i in range(len(self.helper.coordsList)):
                    draw.line(self.helper.coordsList[i], fill=str2hex(self.color)
                    , width=self.width)
            elif self.tool == self.toolname['line']:
                coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                        WALL_P_W, WALL_P_H, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    draw.line((self.helper.coords[i][0],self.helper.coords[i][1],
                                            coords[i][0],coords[i][1]), width=self.width,
                                            fill=str2hex(self.color))

            elif self.tool == self.toolname['curve']:
                # in state 0, at release, the end pos is saved
                if self.helper.state==0 and (self.helper.x, self.helper.y)!=(e.x,e.y):
                    self.helper.x2, self.helper.y2 = e.x,e.y
                    self.helper.state=1
                # in state 1, at release, lines drawn
                elif self.helper.state==1:
                    for i in range(len(self.helper.coordsList)):
                        draw.line(self.helper.coordsList[i], fill=str2hex(self.color), width=self.width)
                    self.helper.state=0

            elif self.tool == self.toolname['fill']:
                # generate all coords then fill at each
                coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                            WALL_P_W, WALL_P_H, self.sym, (e.x, e.y))
                pic = im.load()
                target = pic[e.x, e.y]
                for i in range(len(coords)):
                    self.fill(pic, str2hex(self.color), target,
                                coords[i][0], coords[i][1])
            elif self.tool == self.toolname['eraser']:
                for i in range(len(self.helper.coordsList)):
                    draw.line(self.helper.coordsList[i], fill=(255,255,255,0), width=self.width)


        if self.type==2:
            if self.tool == self.toolname['pen']:
                for i in range(len(self.helper.coordsList)):
                    draw.line(self.helper.coordsList[i], fill=str2hex(self.color)
                    , width=self.width)

            elif self.tool == self.toolname['line']:
                coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                        self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    draw.line((self.helper.coords[i][0],self.helper.coords[i][1],
                                            coords[i][0],coords[i][1]), width=self.width,
                                            fill=str2hex(self.color))

            elif self.tool == self.toolname['curve']:
                # in state 0, at release, the end pos is saved
                if self.helper.state==0 and (self.helper.x, self.helper.y)!=(e.x,e.y):
                    self.helper.x2, self.helper.y2 = e.x,e.y
                    self.helper.state=1
                # in state 1, lines drawn
                elif self.helper.state==1:
                    for i in range(len(self.helper.coordsList)):
                        draw.line(self.helper.coordsList[i], fill=str2hex(self.color), width=self.width)
                    self.helper.state=0

            elif self.tool == self.toolname['fill']:
                coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                        self.sym, (e.x, e.y))
                pic = im.load()
                target = pic[e.x, e.y]
                for i in range(len(coords)):
                    self.fill(pic, str2hex(self.color), target,
                                coords[i][0], coords[i][1])

            elif self.tool == self.toolname['eraser']:
                for i in range(len(self.helper.coordsList)):
                    draw.line(self.helper.coordsList[i], fill=(255,255,255,0), width=self.width)

        self.helper.new_im(im)
        self.draw()
예제 #8
0
    def move(self, e):
        if self.type == 0:
            if self.tool == self.toolname['pen']:
                # draw line from last position to current
                self.cv.create_line(self.helper.x,self.helper.y,
                 e.x,e.y,width=self.width,
                fill=self.color, tag='temp')
                # save current & add to sequence of coords
                self.helper.x =e.x; self.helper.y=e.y
                self.helper.coords.append((e.x, e.y))
            elif self.tool == self.toolname['line']:
                # draw line from initial pos to current
                self.cv.delete('temp')
                self.cv.create_line(self.helper.x,self.helper.y, e.x,e.y,width=self.width,
                fill=self.color, tag='temp')
            elif self.tool == self.toolname['curve'] and self.helper.state==0:
                # draw line from initial pos to current (for guidance only)
                self.cv.delete('temp')
                self.cv.create_line(self.helper.x,self.helper.y, e.x,e.y,width=self.width,
                fill=self.color, tag='temp')
            elif self.tool == self.toolname['eraser']:
                # draw line (white transparent line)
                self.cv.create_line(self.helper.x,self.helper.y,
                 e.x,e.y,width=self.width,
                fill='#ffffff', tag='temp')
                self.helper.x =e.x; self.helper.y=e.y
                self.helper.coords.append((e.x, e.y))

        if self.type == 1:  # wallpaper
        # generate all coords & draw line
            if self.tool == self.toolname['pen']:
                coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                        WALL_P_W, WALL_P_H, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],self.helper.coords[i][1],
                                        coords[i][0],coords[i][1], width=self.width,
                                        fill=self.color, tag='temp')
                    self.helper.coordsList[i] += coords[i]
                self.helper.coords = coords

            elif self.tool == self.toolname['line']:
                self.cv.delete('temp')
                coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                            WALL_P_W, WALL_P_H, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],self.helper.coords[i][1],
                                        coords[i][0],coords[i][1], width=self.width,
                                        fill=self.color, tag='temp')

            elif self.tool == self.toolname['curve'] and self.helper.state==0:
                self.cv.delete('temp')
                self.cv.create_line(self.helper.x,self.helper.y, e.x,e.y,width=self.width,
                fill=self.color, tag='temp')

            elif self.tool == self.toolname['eraser']:
                coords = wallpaper_patterns.repeat_wallpaper(self.cvw, self.cvh,
                        WALL_P_W, WALL_P_H, self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],self.helper.coords[i][1],
                                        coords[i][0],coords[i][1], width=self.width,
                                        fill='white', tag='temp')
                    self.helper.coordsList[i] += coords[i]

                self.helper.coords = coords

        if self.type == 2:  # frieze
        # generate all coords and draw lines
            if self.tool == self.toolname['pen']:
                coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                        self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],self.helper.coords[i][1],
                                        coords[i][0],coords[i][1], width=self.width,
                                        fill=self.color, tag='temp')
                    self.helper.coordsList[i] += coords[i]

                self.helper.coords = coords

            elif self.tool == self.toolname['line']:
                self.cv.delete('temp')
                coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                        self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],self.helper.coords[i][1],
                                        coords[i][0],coords[i][1], width=self.width,
                                        fill=self.color, tag='temp')

            elif self.tool == self.toolname['curve'] and self.helper.state==0:
                self.cv.delete('temp')
                self.cv.create_line(self.helper.x,self.helper.y, e.x,e.y,width=self.width,
                fill=self.color, tag='temp')

            elif self.tool == self.toolname['eraser']:
                coords = frieze.repeat(self.cvw, self.cvh, FRIEZE_R,
                                        self.sym, (e.x, e.y))
                for i in range(len(coords)):
                    self.cv.create_line(self.helper.coords[i][0],self.helper.coords[i][1],
                                        coords[i][0],coords[i][1], width=self.width,
                                        fill='white', tag='temp')
                    self.helper.coordsList[i] += coords[i]

                self.helper.coords = coords