コード例 #1
0
def draw2(ctx, pixel_width, pixel_height, frame_no, frame_count):

    width = 32
    setup(ctx, pixel_width, pixel_height, width=width, startx=-width/2, starty=-width/2, background=Color(1))

    a = 14
    b = 6
    d = 4
    angle = 1

    Origin = (0, 0)
    A = (-a, 0)
    B = ((a-b)*math.cos(angle), (a-b)*math.sin(angle))
    x = (a - b) * math.cos(angle) + d * math.cos((a - b) / b * angle)
    y = (a - b) * math.sin(angle) - d * math.sin((a - b) / b * angle)
    D = (x, y)

    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('skyblue'), line_width=0.1)
    Polygon(ctx).of_points(create_spiro(a, b, d, 0.01, angle)).open().stroke(Color('red'), line_width=0.1)

    Circle(ctx).of_center_radius(Origin, a).stroke(Color('darkgreen'), line_width=0.1)
    Circle(ctx).of_center_radius(Origin, 0.3).fill(Color('darkgreen'))
    Line(ctx).of_start_end(Origin, A).stroke(Color('darkgreen'), line_width=0.1)
    Text(ctx).of('a', (A[0]/2, A[1])).size(1.5).offset(0, -0.5).fill(Color('darkgreen'))
    Circle(ctx).of_center_radius(B, b).stroke(Color('blue'), line_width=0.1)
    Circle(ctx).of_center_radius(B, 0.3).fill(Color('blue'))
    Text(ctx).of('b', (B[0], B[1]+b/2)).size(1.5).offset(0.5, 0).fill(Color('blue'))
    Line(ctx).of_start_end(B, (B[0], B[1]+b)).stroke(Color('blue'), line_width=0.1)
    Circle(ctx).of_center_radius(D, 0.3).fill(Color('black'))
    Line(ctx).of_start_end(B, D).stroke(Color('black'), line_width=0.1)
    Text(ctx).of('d', ((B[0]+D[0])/2, (B[1]+D[1])/2)).size(1.5).offset(0.5, 0.5).fill(Color('black'))
コード例 #2
0
def show_bezier_points(ctx, a, b, c, d):
    blue = Color('blue')
    red = Color('red')
    grey = Color(0.2)
    thickness = 2
    Bezier(ctx).of_abcd(a, b, c, d).stroke(blue, thickness)
    Line(ctx).of_start_end(a, b).stroke(grey, thickness, dash=[5])
    Line(ctx).of_start_end(c, d).stroke(grey, thickness, dash=[5])
    Circle(ctx).of_center_radius(a, 5).fill(red)
    Circle(ctx).of_center_radius(b, 5).fill(red)
    Circle(ctx).of_center_radius(c, 5).fill(red)
    Circle(ctx).of_center_radius(d, 5).fill(red)
コード例 #3
0
def draw2(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_height, background=Color(0.8))

    black = Color(0)

    Line(ctx).of_start_end((50, 50), (450, 50)).stroke(black, 20, cap=SQUARE)
    Line(ctx).of_start_end((50, 100), (450, 100)).stroke(black, 20, cap=BUTT)
    Line(ctx).of_start_end((50, 150), (450, 150)).stroke(black, 20, cap=ROUND)

    Line(ctx).of_start_end((50, 250), (450, 250)).stroke(black,
                                                         20,
                                                         cap=SQUARE,
                                                         dash=[30])
    Line(ctx).of_start_end((50, 300), (450, 300)).stroke(black,
                                                         20,
                                                         cap=BUTT,
                                                         dash=[30])
    Line(ctx).of_start_end((50, 350), (450, 350)).stroke(black,
                                                         20,
                                                         cap=ROUND,
                                                         dash=[30])

    Line(ctx).of_start_end((50, 450), (450, 450)).stroke(black,
                                                         20,
                                                         cap=BUTT,
                                                         dash=[30, 40])
    Line(ctx).of_start_end((50, 500), (450, 500)).stroke(black,
                                                         20,
                                                         cap=BUTT,
                                                         dash=[30, 10, 20, 10])
コード例 #4
0
ファイル: markers.py プロジェクト: martinmcbride/generativepy
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_height, width=10, background=Color(0.8))

    a = (1, 2)
    b = (7, 2)
    c = (3, 8)
    d = (9, 8)
    e = (5, 2)
    f = (5, 8)

    Polygon(ctx).of_points([a, b, d, c]).stroke(Color('blue'), line_width=.05)
    Line(ctx).of_start_end(e, f).stroke(Color('blue'), line_width=.05)

    AngleMarker(ctx).of_points(
        b, a,
        c).with_radius(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(a, b, d).with_radius(.5).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(
        c, d,
        b).with_radius(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(a, c, d).with_radius(.5).stroke(Color('blue'),
                                                               line_width=.05)
    AngleMarker(ctx).of_points(
        e, f, d).with_radius(.5).as_right_angle().stroke(Color('blue'),
                                                         line_width=.05)

    Text(ctx).of('a', a).size(1).offset_towards(d, -0.5).fill(Color('red'))
    Text(ctx).of('b', b).size(1).offset_towards(c, -0.9).fill(Color('red'))
    Text(ctx).of('c', c).size(1).offset_towards(b, -0.9).fill(Color('red'))
    Text(ctx).of('d', d).size(1).offset_towards(a, -0.5).fill(Color('red'))
    Text(ctx).of('e', e).size(1).offset_towards(f, -0.3).fill(Color('red'))
    Text(ctx).of('f', f).size(1).offset_towards(e, -0.9).fill(Color('red'))
コード例 #5
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):

    setup(ctx, pixel_width, pixel_height, background=Color(0.4))

    gradient = LinearGradient().of_points(
        (150, 150), (350, 250)).with_start_end(Color('yellow'),
                                               Color('red')).build()
    Rectangle(ctx).of_corner_size((0, 0), 500, 400).fill(gradient)

    Line(ctx).of_start_end((150, 150), (350, 250)).stroke(Color(0), 2, [5, 5])
    Line(ctx).of_start_end((150, 150),
                           (250, -50)).as_line().stroke(Color(0), 2, [5, 5])
    Line(ctx).of_start_end((350, 250),
                           (450, 50)).as_line().stroke(Color(0), 2, [5, 5])
    Circle(ctx).of_center_radius((150, 150), 5).fill(Color(0))
    Circle(ctx).of_center_radius((350, 250), 5).fill(Color(0))
コード例 #6
0
def draw3(ctx, pixel_width, pixel_height, frame_no, frame_count):

    width = 32
    setup(ctx, pixel_width, pixel_height, width=width, startx=-width/2, starty=-width/2, background=Color(1))

    a = 14
    b = 6
    d = 4
    angle = (frame_no/frame_count)*2*math.pi*b/math.gcd(a, b)
    print(angle)

    Origin = (0, 0)
    A = (-a, 0)
    B = ((a-b)*math.cos(angle), (a-b)*math.sin(angle))
    x = (a - b) * math.cos(angle) + d * math.cos((a - b) / b * angle)
    y = (a - b) * math.sin(angle) - d * math.sin((a - b) / b * angle)
    D = (x, y)

    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('skyblue'), line_width=0.2)
    Polygon(ctx).of_points(create_spiro(a, b, d, 0.01, angle)).open().stroke(Color('red'), line_width=0.2)

    Circle(ctx).of_center_radius(Origin, a).stroke(Color('darkgreen'), line_width=0.2)
    Circle(ctx).of_center_radius(B, b).stroke(Color('blue'), line_width=0.2)
    Circle(ctx).of_center_radius(B, 0.3).fill(Color('blue'))
    Circle(ctx).of_center_radius(D, 0.3).fill(Color('black'))
    Line(ctx).of_start_end(B, D).stroke(Color('black'), line_width=0.2)
コード例 #7
0
def draw2(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_width, background=Color(0.8))

    black = Color(0)

    Line(ctx).of_start_end((100, 50), (200, 50)).stroke(black, 20)
    Line(ctx).of_start_end((200, 50), (100, 200)).stroke(black, 20)
    Line(ctx).of_start_end((100, 200), (50, 200)).stroke(black, 20)
    Line(ctx).of_start_end((50, 200), (100, 50)).stroke(black, 20)

    Line(ctx).of_start_end((300, 50), (400, 50)).add()
    Line(ctx).of_end((300, 200)).extend_path().add()
    Line(ctx).of_end((250, 200)).extend_path().stroke(black, 20)

    Line(ctx).of_start_end((500, 50), (600, 50)).add()
    Line(ctx).of_end((500, 200)).extend_path().add()
    Line(ctx).of_end((450, 200)).extend_path(close=True).stroke(black, 20)
コード例 #8
0
        def draw(ctx, width, height, frame_no, frame_count):
            setup(ctx, width, height, width=6, background=Color(0.8))

            for i in range(9):
                angle = 2*math.pi*i/9
                a = (1.5 + 1.5*(i%3), 1.5 + 1.5*(i//3))
                b = (a[0] + math.cos(angle), a[1] + math.sin(angle))
                Line(ctx).of_start_end(a, b).as_line().stroke(Color('fuchsia'), 0.05)
                Circle(ctx).of_center_radius(a, .1).fill(Color(0))
コード例 #9
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):

    setup(ctx, pixel_width, pixel_height, background=Color(0.8))

    blue = Color('blue')
    red = Color('red')
    green = Color('green')
    thickness = 4

    Text(ctx).of('F', (40, 100)).size(100).fill(blue)
    Line(ctx).of_start_end((100, 20), (100, 110)).stroke(green, thickness)

    with Transform(ctx).scale(-1, 1, (100, 0)):
        Text(ctx).of('F', (40, 100)).size(100).fill(red)

    Text(ctx).of('W', (240, 100)).size(100).fill(blue)
    Line(ctx).of_start_end((240, 70), (340, 70)).stroke(green, thickness)

    with Transform(ctx).scale(1, -1, (0, 60)):
        Text(ctx).of('W', (240, 100)).size(100).fill(red.with_a(0.6))
コード例 #10
0
def draw(ctx, width, height, frame_no, frame_count):
    setup(ctx, width, height, width=5, background=Color(0.8))

    # The line function is a convenience function that adds a line as a new path.
    # You can fill or stroke it as you wish.
    line(ctx, (1, 1), (2, 3))
    ctx.set_source_rgba(*Color(1, 0, 0))
    ctx.set_line_width(0.1)
    ctx.stroke()

    # Line objects can only be stroked as they do not contain an area.
    Line(ctx).of_start_end((3, 1), (4, 4)).stroke(Color('fuchsia'), 0.2)
コード例 #11
0
        def draw(ctx, width, height, frame_no, frame_count):
            setup(ctx, width, height, width=300, background=Color(1))

            # Fill then stroke a rectangle
            ctx.save()
            ctx.translate(0, 0)
            Rectangle(ctx).of_corner_size((20, 20), 60, 60).fill(Color('red')).stroke(Color('blue'), 10)
            ctx.restore()

            # Stroke then fill a rectangle
            ctx.save()
            ctx.translate(100, 0)
            Rectangle(ctx).of_corner_size((20, 20), 60, 60).stroke(Color('blue'), 10).fill(Color('red'))
            ctx.restore()

            # Path with two rectangles
            ctx.save()
            ctx.translate(200, 0)
            Rectangle(ctx).of_corner_size((20, 20), 60, 60).add()
            Rectangle(ctx).of_corner_size((30, 30), 60, 60).as_sub_path().fill(Color('red')).stroke(Color('blue'), 5)
            ctx.restore()

            # Path from several lines
            ctx.save()
            ctx.translate(0, 100)
            Line(ctx).of_start_end((20, 20), (60, 30)).add()
            Line(ctx).of_end((60, 60)).extend_path().add()
            Line(ctx).of_end((30, 50)).extend_path().fill(Color('red')).stroke(Color('blue'), 5)
            ctx.restore()

            # Path from several lines, closed
            ctx.save()
            ctx.translate(100, 100)
            Line(ctx).of_start_end((20, 20), (60, 30)).add()
            Line(ctx).of_end((60, 60)).extend_path().add()
            Line(ctx).of_end((30, 50)).extend_path(close=True).fill(Color('red')).stroke(Color('blue'), 5)
            ctx.restore()

            # roundrect open
            ctx.save()
            ctx.translate(0, 200)
            Circle(ctx).of_center_radius((20, 20), 10).as_arc(math.pi, math.pi * 3 / 2).add()
            Circle(ctx).of_center_radius((60, 20), 10).as_arc(math.pi * 3 / 2, 0).extend_path().add()
            Circle(ctx).of_center_radius((60, 60), 10).as_arc(0, math.pi / 2).extend_path().add()
            Circle(ctx).of_center_radius((20, 60), 10).as_arc(math.pi / 2, math.pi).extend_path().fill(
                Color('red')).stroke(Color('blue'), 5)
            ctx.restore()

            # roundrect closed
            ctx.save()
            ctx.translate(100, 200)
            Circle(ctx).of_center_radius((20, 20), 10).as_arc(math.pi, math.pi * 3 / 2).add()
            Circle(ctx).of_center_radius((60, 20), 10).as_arc(math.pi * 3 / 2, 0).extend_path().add()
            Circle(ctx).of_center_radius((60, 60), 10).as_arc(0, math.pi / 2).extend_path().add()
            Circle(ctx).of_center_radius((20, 60), 10).as_arc(math.pi / 2, math.pi).extend_path(close=True).fill(
                Color('red')).stroke(Color('blue'), 5)
            ctx.restore()
コード例 #12
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):

    setup(ctx, pixel_width, pixel_height, background=Color(0.8))

    red = Color('red')
    green = Color('green')
    blue = Color('blue')
    thickness = 2

    Line(ctx).of_start_end((150, 150), (50, 50)).stroke(red, thickness)
    Line(ctx).of_start_end((300, 150),
                           (200, 50)).as_ray().stroke(red, thickness)
    Line(ctx).of_start_end((450, 150),
                           (350, 50)).as_line().stroke(red, thickness)

    Triangle(ctx).of_corners((50, 200), (150, 200),
                             (125, 300)).stroke(green, thickness)
    Square(ctx).of_corner_size((200, 200), 100).stroke(green, thickness)
    Rectangle(ctx).of_corner_size((350, 200), 100, 75).stroke(green, thickness)

    Polygon(ctx).of_points([(50, 350), (250, 400), (250, 500),
                            (50, 375)]).stroke(blue, thickness)
    Polygon(ctx).of_points([(300, 350), (500, 400), (500, 500),
                            (300, 375)]).open().stroke(blue, thickness)
コード例 #13
0
        def draw(ctx, width, height, frame_no, frame_count):
            setup(ctx, width, height, background=Color(0.8))
            red = Color('red')
            thickness = 3

            ## Draw lines with ticks and paraticks
            a = (50, 50)
            b = (50, 150)
            Line(ctx).of_start_end(a, b).stroke(red, thickness)
            TickMarker(ctx).of_start_end(a, b).with_length(12).stroke(
                red, thickness)

            a = (100, 50)
            b = (150, 150)
            Line(ctx).of_start_end(a, b).stroke(red, thickness)
            TickMarker(ctx).of_start_end(
                a, b).with_length(12).with_count(2).with_gap(6).stroke(
                    red, thickness)

            a = (250, 50)
            b = (200, 150)
            Line(ctx).of_start_end(a, b).stroke(red, thickness)
            TickMarker(ctx).of_start_end(
                a, b).with_length(12).with_count(3).with_gap(6).stroke(
                    red, thickness)

            a = (350, 50)
            b = (350, 150)
            Line(ctx).of_start_end(a, b).stroke(red, thickness)
            ParallelMarker(ctx).of_start_end(a, b).with_length(12).stroke(
                red, thickness)

            a = (400, 50)
            b = (450, 150)
            Line(ctx).of_start_end(a, b).stroke(red, thickness)
            ParallelMarker(ctx).of_start_end(
                a, b).with_length(12).with_count(2).with_gap(6).stroke(
                    red, thickness)

            a = (550, 150)
            b = (500, 50)
            Line(ctx).of_start_end(a, b).stroke(red, thickness)
            ParallelMarker(ctx).of_start_end(
                a, b).with_length(12).with_count(3).with_gap(6).stroke(
                    red, thickness)

            ## Draw lines with angles
            a = (50, 250)
            b = (50, 450)
            c = (150, 450)
            Polygon(ctx).of_points((a, b, c)).open().stroke(red, thickness)
            AngleMarker(ctx).of_points(
                a, b, c).with_radius(24).with_gap(6).as_right_angle().stroke(
                    red, thickness)

            a = (250, 250)
            b = (200, 450)
            c = (300, 450)
            Polygon(ctx).of_points((a, b, c)).open().stroke(red, thickness)
            AngleMarker(ctx).of_points(
                a, b, c).with_count(3).with_radius(24).with_gap(6).stroke(
                    red, thickness)

            a = (300, 250)
            b = (400, 300)
            c = (500, 300)
            Polygon(ctx).of_points((a, b, c)).open().stroke(red, thickness)
            AngleMarker(ctx).of_points(c, b,
                                       a).with_radius(24).with_gap(6).stroke(
                                           red, thickness)

            a = (300, 350)
            b = (400, 400)
            c = (500, 400)
            Polygon(ctx).of_points((a, b, c)).open().stroke(red, thickness)
            AngleMarker(ctx).of_points(
                a, b, c).with_count(2).with_radius(24).with_gap(6).stroke(
                    red, thickness)