コード例 #1
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)
コード例 #2
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 = 16
    b = 13
    d = 5
    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('firebrick'),
                                                         line_width=0.1)

    a = 16
    b = 9
    d = 8
    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('goldenrod'),
                                                         line_width=0.1)

    a = 16
    b = 11
    d = 6
    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('darkgreen'),
                                                         line_width=0.1)
コード例 #3
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'))
コード例 #4
0
def draw(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
    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('skyblue'), line_width=0.1)
    points = create_spiro(a, b, d, 0.5, 4)
    Polygon(ctx).of_points(points).open().stroke(Color('red'), 0.1)
    for p in points:
        Circle(ctx).of_center_radius(p, 0.2).fill(Color(0))
コード例 #5
0
def draw4(ctx, pixel_width, pixel_height, frame_no, frame_count):

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

    blue = Color('blue')
    grey = Color(0.2)
    thickness = 2

    a0 = (50, 200)
    b0 = (100, 200)
    c0 = (100, 50)
    d0 = (200, 50)
    a1 = (200, 50)
    b1 = (300, 50)
    c1 = (350, 220)
    d1 = (450, 200)
    points = [a0, (*b0, *c0, *d0), (*b1, *c1, *d1)]
    Polygon(ctx).of_points(points).open().stroke(blue, thickness)

    show_bezier_points(ctx, (50, 200), (100, 200), (100, 50), (200, 50))
    show_bezier_points(ctx, (200, 50), (300, 50), (350, 220), (450, 200))

    Text(ctx).of('a0', a0).size(20).align_center().align_middle().offset_towards(b0, -20).fill(grey)
    Text(ctx).of('b0', b0).size(20).align_center().align_middle().offset_towards(a0, -20).fill(grey)
    Text(ctx).of('c0', c0).size(20).align_center().align_middle().offset_towards(d0, -20).fill(grey)
    Text(ctx).of('d0/a1', d0).size(20).align_center().align_middle().offset(0, -20).fill(grey)
    Text(ctx).of('b1', b1).size(20).align_center().align_middle().offset_towards(a1, -20).fill(grey)
    Text(ctx).of('c1', c1).size(20).align_center().align_middle().offset_towards(d1, -20).fill(grey)
    Text(ctx).of('d1', d1).size(20).align_center().align_middle().offset_towards(c1, -20).fill(grey)
コード例 #6
0
ファイル: markers.py プロジェクト: martinmcbride/generativepy
def draw3(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)

    ParallelMarker(ctx).of_start_end(
        a,
        b).with_length(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    ParallelMarker(ctx).of_start_end(
        c,
        d).with_length(.5).with_count(2).with_gap(0.15).stroke(Color('blue'),
                                                               line_width=.05)
    ParallelMarker(ctx).of_start_end(a,
                                     c).with_length(.5).stroke(Color('blue'),
                                                               line_width=.05)
    ParallelMarker(ctx).of_start_end(b,
                                     d).with_length(.5).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.5).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'))
コード例 #7
0
def draw(ctx, width, height, frame_no, frame_count):
    setup(ctx, width, height, width=5, background=Color(0.8))

    # Get a polygon path object
    path1 = Polygon(ctx).of_points([(0, 0), (1, 1), (0.5, 2), (0.5, 1)])\
	                    .path()

    # Get a text path object
    path2 = Text(ctx).of("Path text", (0, 0)).font("Times").size(0.2)\
	                 .align_left().align_top().path()

    # Apply the polygon in various places
    with Transform(ctx).translate(0.5, 1):
        Path(ctx).of(path1).stroke(Color('darkgreen'), 0.1)

    with Transform(ctx).translate(1, 2.5):
        Path(ctx).of(path1).fill(Color('blue'))

    with Transform(ctx).translate(2.5, 0.5).scale(2, 2):
        Path(ctx).of(path1).fill(Color('orange')).stroke(Color('black'), 0.05)

    # Apply the text in various places
    with Transform(ctx).translate(0, 0):
        Path(ctx).of(path2).fill(Color('black'))

    with Transform(ctx).translate(2, 3):
        Path(ctx).of(path2).stroke(Color('red'), 0.01)

    with Transform(ctx).translate(2, 4).scale(2, 2):
        Path(ctx).of(path2).fill(Color('yellow')).stroke(Color('black'), 0.01)
コード例 #8
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))

    # x = [i/100 for i in range(1000)]
    # y = [-sintri(i) for i in x]
    # Polygon(ctx).of_points(zip(x, y)).open().stroke(Color('black'), line_width=0.1)
    #
    # x = [i/100 for i in range(1000)]
    # y = [-costri(i) + 2 for i in x]
    # Polygon(ctx).of_points(zip(x, y)).open().stroke(Color('black'), line_width=0.1)
    #
    # x = [i/100 for i in range(1000)]
    # y = [-int(3*i/(2*math.pi)) - 2 for i in x]
    # Polygon(ctx).of_points(zip(x, y)).open().stroke(Color('black'), line_width=0.1)

    a = 16
    b = 10
    d = 7
    Polygon(ctx).of_points(create_spiro_triangle(a, b, d)).fill(
        Color('gold'), fill_rule=EVEN_ODD).stroke(Color('darkblue'),
                                                  line_width=0.1)
コード例 #9
0
def draw4(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))

    colors = [
        Color('magenta', 0.7),
        Color('red', 0.7),
        Color('blue', 0.7),
        Color('gold', 0.7),
    ]

    for i, color in enumerate(colors):
        a = 16
        b = 10
        d = 7
        with Transform(ctx).rotate(i * math.pi / 6):
            Polygon(ctx).of_points(create_spiro_triangle(a, b, d)).fill(
                color, fill_rule=EVEN_ODD)
コード例 #10
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'))
コード例 #11
0
def draw(ctx, width, height, frame_no, frame_count):
    setup(ctx, width, height, width=5, background=Color(0.8))

    # Bezier objects can only be stroked as they do not contain an area.
    Bezier(ctx).of_abcd((1, 1.5), (3, 0.5), (2, 2.5), (4, 1.5)).stroke(Color('darkgreen'), 0.1)

    # Create a polygon with a bezier side
    Polygon(ctx).of_points([(1, 4.5), (1, 2.5), (2, 3, 3, 4, 4, 2.5), (4, 4.5)]).fill(Color('red')).stroke(Color('blue'), 0.05)
コード例 #12
0
 def plot_easing_function(ctx, x, y, fn):
     tw = Tween(0).ease(-100, 100, fn)
     poly = [(i, tw[i]) for i in range(100)]
     ctx.save()
     ctx.translate(x, y)
     Square(ctx).of_corner_size((0, -100), 100).stroke(Color(0.5), 2)
     Polygon(ctx).of_points(poly).open().stroke(Color('red'), 2)
     ctx.restore()
コード例 #13
0
def draw3(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')
    thickness = 4
    points = [(100, 250), (100, 50), (200, 100, 300, 200, 400, 50), (400, 250)]
    Polygon(ctx).of_points(points).fill(red).stroke(blue, thickness)
コード例 #14
0
        def draw(ctx, width, height, frame_no, frame_count):
            setup(ctx, width, height, width=500, background=Color(0.8))

            # The polygon function is a convenience function that adds a polygon as a new path.
            # You can fill or stroke it as you wish.
            polygon(ctx, ((100, 100), (150, 50), (200, 150), (200, 200)))
            ctx.set_source_rgba(*Color(1, 0, 0))
            ctx.fill()

            Polygon(ctx).of_points([(300, 100), (300, 150), (400, 200), (450, 100)]).open().stroke(Color('orange'), 10)
コード例 #15
0
def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
    setup(ctx, pixel_width, pixel_width, background=Color(0.8))

    black = Color(0)
    red = Color('red')

    Polygon(ctx).of_points([
        (150, 50),
        (100, 250),
        (250, 150),
        (50, 150),
        (200, 250),
    ]).fill(red).stroke(black, 5)

    Polygon(ctx).of_points([
        (450, 50),
        (400, 250),
        (550, 150),
        (350, 150),
        (500, 250),
    ]).fill(red, fill_rule=EVEN_ODD).stroke(black, 5)
コード例 #16
0
        def draw(ctx, pixel_width, pixel_height, frame_no, frame_count):
            setup(ctx,
                  pixel_width,
                  pixel_height,
                  width=5,
                  background=Color(0.8))

            # Get a polygon path object
            path1 = Polygon(ctx).of_points([(0, 0), (1, 1), (0.5, 2),
                                            (0.5, 1)]).path()

            # Get a text path object
            path2 = Text(ctx).of("Path text", (0, 0)).font(
                "Times", weight=FONT_WEIGHT_BOLD).size(
                    0.2).align_left().align_top().path()

            # Apply the polygon in various places
            ctx.save()
            ctx.translate(0.5, 1)
            Path(ctx).of(path1).stroke(Color('darkgreen'), 0.1)
            ctx.restore()

            ctx.save()
            ctx.translate(1, 2.5)
            Path(ctx).of(path1).fill(Color('blue'))
            ctx.restore()

            ctx.save()
            ctx.translate(2.5, 0.5)
            ctx.scale(2, 2)
            Path(ctx).of(path1).fill(Color('orange')).stroke(
                Color('black'), 0.05)
            ctx.restore()

            # Apply the text in various places
            ctx.save()
            ctx.translate(0, 0)
            Path(ctx).of(path2).fill(Color('black'))
            ctx.restore()

            ctx.save()
            ctx.translate(2, 3)
            Path(ctx).of(path2).stroke(Color('red'), 0.01)
            ctx.restore()

            ctx.save()
            ctx.translate(2, 4)
            ctx.scale(2, 2)
            Path(ctx).of(path2).fill(Color('yellow')).stroke(
                Color('black'), 0.01)
            ctx.restore()
コード例 #17
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)
コード例 #18
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 = 16
    b = 9
    d = 6
    Polygon(ctx).of_points(create_spiro_square(a, b, d)).fill(
        Color('lime'),
        fill_rule=EVEN_ODD)  #.stroke(Color('darkblue'), line_width=0.1)

    a = 17
    b = 11
    d = 10
    Polygon(ctx).of_points(create_spiro_square(a, b, d)).fill(
        Color('darkgreen', 0.4),
        fill_rule=EVEN_ODD)  #.stroke(Color('ligh'), line_width=0.1)
コード例 #19
0
def draw(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
    Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(Color('red'),
                                                         line_width=0.1)
コード例 #20
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))

    for i in range(6):
        a = 13
        b = 7
        d = 5
        with Transform(ctx).rotate(0.05 * i):
            Polygon(ctx).of_points(create_spiro(a, b, d)).stroke(
                Color('dodgerblue').with_l_factor(1.1**i), line_width=0.1)
コード例 #21
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)