def __init__(self):
        self.screen = pygame.display.set_mode((800, 600))
        pygame.display.set_caption("Painter")
        self.clock = pygame.time.Clock()

        self.brush = Brush(self.screen)
        self.menu = Menu(self.screen)

        self.menu.set_brush(self.brush)  # 设置笔刷
Exemplo n.º 2
0
def make_brush(item, mol=1):
    brush = Brush(item['trunk']['lam'],
                  mol=mol,
                  starting_position=item['start'],
                  direction=item['direction'],
                  base_id=item.get('base_id'),
                  graft_type=item.get('graft_type', 1))
    for branch in item['branches']:
        brush.create_branch(branch['site'], branch['lam'])
    return brush
Exemplo n.º 3
0
 def __init__(self,
              title,
              bristles_type,
              platform_material,
              handle_len,
              purchase_year,
              purchase_month,
              purchase_day,
              expiration_date=90):
     Brush.__init__(self, title, bristles_type, platform_material)
     self.handle_len = handle_len
     self.purchase_year = purchase_year
     self.purchase_month = purchase_month
     self.purchase_day = purchase_day
     self.expiration_date = expiration_date
Exemplo n.º 4
0
class Painter():
    def __init__(self):
        self.screen = pygame.display.set_mode((680, 480), 0, 32)
        self.time_passed = pygame.time.Clock()
        self.brush = Brush(self.screen)

    def run(self):
        self.screen.fill((255, 255, 255))
        a = BrushColor()
        a.brushBox(self.screen, [56, 88, 96], 1, 1)
        while True:
            self.time_passed.tick(30)
            for event in pygame.event.get():
                if event.type == QUIT:
                    exit()
                elif event.type == KEYDOWN:
                    pass
                elif event.type == MOUSEMOTION:
                    self.brush.draw(event.pos)
                elif event.type == MOUSEBUTTONDOWN:
                    self.brush.start_draw(event.pos)
                elif event.type == MOUSEBUTTONUP:
                    self.brush.end_draw()

            pygame.display.update()
class Painter:
    def __init__(self):
        self.screen = pygame.display.set_mode((800, 600))
        pygame.display.set_caption("Painter")
        self.clock = pygame.time.Clock()

        self.brush = Brush(self.screen)
        self.menu = Menu(self.screen)

        self.menu.set_brush(self.brush)  # 设置笔刷

    def run(self):
        self.screen.fill((255, 255, 255))
        while True:
            self.clock.tick(30)
            for event in pygame.event.get():
                if event.type == QUIT:
                    return
                elif event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        self.screen.fill((255, 255, 255))  # 用填充清屏
                elif event.type == MOUSEBUTTONDOWN:
                    if event.pos[0] <= 74 and self.menu.click_button(event.pos):
                        # 若没有点击菜单,则画画
                        pass
                    else:
                        self.brush.start_draw(event.pos)  # drawing->true
                elif event.type == MOUSEMOTION:
                    self.brush.draw(event.pos)
                elif event.type == MOUSEBUTTONUP:
                    self.brush.end_draw()  # drawing->false

            self.menu.draw()
            pygame.display.update()
Exemplo n.º 6
0
    def draw_points(self, layer_number, style, points):
        # Corrective constants to match characteristics of OpenCanvas 1.1 brushes
        pressure_correction_weight = 1.0
        brush_size_weight = 0.7
        brush_velocity = 0.03

        print "Drawing on layer ", layer_number
        self.select_layer(layer_number)

        layer = self.get_current_layer()

        brush_style = BrushInfo(brushdata)

        # Set color
        rgb = map(lambda c: float(c) / 255.0, style['color'])
        brush_style.set_color_rgb(rgb)

        # Set size adjustments and calculate pressure curve
        size = style['size']
        pressure_correct = style['pressure_correct']
        x_points = (0.000000, 0.237952, 0.500000, 0.765060, 1.000000)
        y_points = map(
            lambda x: (x**pressure_correct) * pressure_correction_weight -
            pressure_correction_weight / 2.0, x_points)
        pressure_curve = zip(x_points, y_points)
        brush_style.set_setting(
            'radius_logarithmic',
            [math.log(size * brush_size_weight), {
                'pressure': pressure_curve
            }])

        brush = Brush(brush_style)

        stroke = Stroke()
        stroke.start_recording(brush)
        tdelta = 0
        lx, ly, lp = points[0]
        for point in points:
            lx = (lx + point[0]) / 2
            ly = (ly + point[1]) / 2
            lp = float(point[2]) / 1024.0  # Pressure
            stroke.record_event(tdelta, lx, ly, lp, 0, 0)
            tdelta += brush_velocity
        stroke.stop_recording()

        # Render stroke and save undo information
        snapshot_before = layer.save_snapshot()
        stroke.render(layer._surface)
        self.do(command.Stroke(self, stroke, snapshot_before))
Exemplo n.º 7
0
    def __init__(self):
        super().__init__()
        camera.orthographic = True
        camera.fov = 100
        window.color = color.white
        self.cursor = Cursor(model=Circle(mode='line'))

        self.canvas_width = 1920
        self.canvas_height = 1080

        # create layer for displaying brush stroke while drawing
        t = time.time()
        self.temp_image = Image.new('RGBA',
                                    (self.canvas_width, self.canvas_height),
                                    (0, 0, 0, 0))
        self.temp_layer = Entity(parent=self,
                                 model='quad',
                                 z=-.1,
                                 color=(1, 1, 1, 1))
        self.temp_texture = Texture(self.temp_image)
        self.temp_layer.texture = self.temp_texture

        self.bg_layer = Layer(self.canvas_width,
                              self.canvas_height,
                              color.white,
                              z=10,
                              enabled=False)
        self.combined_layer = Layer(self.canvas_width,
                                    self.canvas_height,
                                    z=-10,
                                    enabled=False)
        self.combined_layer.outline.color = color.magenta
        print('temp layer:', time.time() - t)

        self.layers = list()
        self.layer_index = -1
        self.layer_index_label = Text(position=window.left, text='-1')
        self.layer_menu = LayerMenu(otoblop=self)
        self.add_layer()

        self.cover = Entity(parent=self.current_layer, z=-1)
        Entity(parent=self.cover,
               model='quad',
               color=color.dark_gray,
               origin_y=-.5,
               y=.5,
               scale=10)
        Entity(parent=self.cover,
               model='quad',
               color=color.dark_gray,
               origin_y=.5,
               y=-.5,
               scale=10)
        Entity(parent=self.cover,
               model='quad',
               color=color.dark_gray,
               origin_x=-.5,
               x=.5,
               scale=10)
        Entity(parent=self.cover,
               model='quad',
               color=color.dark_gray,
               origin_x=.5,
               x=-.5,
               scale=10)
        self.cover.world_parent = self

        # instantiate tools
        self.brush = Brush(parent=self)
        # self.move_tool = MoveTool(parent=self)
        self.eyedropper = Eyedropper(parent=self)
        # self.tools = (self.brush, self.move_tool)
        self.active_tool = self.brush

        self.color_menu = ColorMenu()
        self.palette = Palette(self.brush)

        self.info_text = Text(position=window.top_left,
                              text=dedent('''
                x:   reduce brush size
                d:   increase brush size
                r:   round brush
                p:   paint brush
                1-9: brush opacity
                '''),
                              color=color.black)

        def enable_brush():
            self.brush.enabled = True

        def disable_brush():
            self.brush.enabled = False

        self.move_cursor = Cursor(enabled=False)
        Text(parent=self.move_cursor, text='move', enabled=False)
Exemplo n.º 8
0
 def __init__(self):
     self.screen = pygame.display.set_mode((680, 480), 0, 32)
     self.time_passed = pygame.time.Clock()
     self.brush = Brush(self.screen)
Exemplo n.º 9
0
import json
import dicttoxml
from brush import Brush
from xml.etree.ElementTree import Element, tostring

# Create some object
brushes = Brush("Colgate", "medium", "plastic")
# Convert to json and save to file
file_out_json = open('brush.json', 'w')
brushes_json = json.dump(brushes.__dict__, file_out_json, indent=4)
file_out_json.close()
# Convert to xml using an external module dicttoxml from https://pypi.python.org/pypi site
brushes_xml = dicttoxml.dicttoxml(brushes.__dict__, attr_type=False)
file_out_xml = open('brush.xml', 'wb')
file_out_xml.write(brushes_xml)
file_out_xml.close()

# Convert to xml using language features


def dict_to_xml(tag, d):
    elem = Element(tag)
    for key, val in d.items():
        child = Element(key)
        child.text = str(val)
        elem.append(child)
    return elem


file_out_xml_2 = open('brush_1.xml', 'wb')
file_out_xml_2.write(tostring(dict_to_xml('brush', brushes.__dict__)))