Exemple #1
0
def chessboard_demo(slide):
    # Create a chess board

    board = slide.box(width=500, height=500)
    board.set_style("black", elsie.TextStyle(color="black", size=50))

    colors = [COLOR2, COLOR1]
    tiles = {}
    for i in range(8):
        row = board.box(height="fill", width="100%", horizontal=True)
        for j in range(8):
            b = row.box(width="fill", height="100%")
            b.rect(bg_color=colors[(i + j) % 2])
            tiles[(j, i)] = b.overlay(z_level=1)
    board.rect(color=COLOR1, stroke_width=3)

    # Create the arrow
    points = [
        tiles[(3, 4)].mid_point(),
        tiles[(3, 2)].mid_point(),
        tiles[(4, 2)].mid_point(),
    ]

    arrow = elsie.Arrow(30)
    slide.box(show="1-3").line(points,
                               color="white",
                               stroke_width=15,
                               end_arrow=arrow)

    tiles[(3, 4)].box(show="1").text("♞", "black")
    tiles[(3, 3)].box(show="2").text("♞", "black")
    tiles[(3, 2)].box(show="3").text("♞", "black")
    tiles[(4, 2)].box(show="4").text("♞", "black")
Exemple #2
0
def text_box_in_code_demo(slide):
    slide.set_style("small", elsie.TextStyle(size=10))
    slide.box().text("Words inside code block")
    slide.box(height=80)

    c = slide.box().code(
        "c",
        """#include <stdio.h>

/* Hello world program */

    int ~#MAIN{main}() {
    printf(~small{"Hello world!\\n"});
    return ~#RETURN_VALUE{0};
}""",
        use_styles=True,
    )  # <--- use_styles=True is important to enable styling in code block

    p2 = c.inline_box("#RETURN_VALUE").p("50%", "100%")

    c.inline_box("#MAIN", z_level=-1, p_x=-2).rect(bg_color="#FBB",
                                                   color="black")

    arrow = elsie.Arrow(10)
    slide.line([p2.add(0, 40), p2], stroke_width=3, end_arrow=arrow)

    c.line_box(4).box(x="100%", height="100%").text("← Inline highlight",
                                                    "small")
    c.line_box(5).box(x="100%", height="100%").text("← Font style changed",
                                                    "small")
    c.line_box(6).box(x="100%", height="100%").text("← Pointing to a word",
                                                    "small")
Exemple #3
0
def line_highlighting(slide):
    slide.box().text("Line Highlighting")
    slide.box(height=30)

    code = slide.box().code(
        "c",
        """#include <stdio.h>

/* Hello world program */

int main() {
    printf("Hello world!\\n");
    return 0;
}""",
    )

    # 'line_box' creates box around a specified line of a text (the 1st argument)
    # Lines are counter from 0
    # We are using z_level to put highlights behind the text
    code.line_box(4, show="1-3", z_level=-1).rect(bg_color="#D0D0FF")
    code.line_box(5, show="2-3", z_level=-1).rect(bg_color="#D0D0FF")
    # Another way how to put box behind text is to 'below' parameter
    code.line_box(6, show="3", below=code).rect(bg_color="#D0D0FF")

    # The same as previous three, but we are stroking border and
    # not filling the rectangle
    code.line_box(4, n_lines=4, show="4").rect(color="blue")

    # Creating a "commenting label"
    label = slide.box(x=100, y=400, width=200, height=130, show="5")
    label.rect(bg_color="green", rx=10, ry=10)
    label.text("Comment for\na line", elsie.TextStyle(color="white"))

    # Here we creates the triangle heading to a line,
    # method 'p' returns a position relatively to the box
    label.polygon(
        [
            label.p("99%", "40%"),
            label.p("99%", "60%"),
            code.line_box(4).p(0, "50%"),
        ],
        bg_color="green",
    )

    # Now we are creating an arrow head for the orange line
    arrow = elsie.Arrow(10)
    p1 = code.line_box(0).p("100%", "50%")
    p2 = code.line_box(5).p("100%", "50%")
    slide.box(show="6").line(
        [p1, p1.add(40, 0), p2.add(40, 0), p2],
        stroke_width=3,
        color="orange",
        end_arrow=arrow,
    )
Exemple #4
0
def text_box_demo(slide):
    b = slide.box().text("~#A{Demo} for ~#B{highlighting} a part of a line")

    # Now we select part of text accoring style
    # You can select any style (e.g. "emph")
    # But you can also use "dummy style" that starts with "#"
    # Such style does not have to be declared and it serves
    # only purpose of selecting part of the text
    b.text_box("#A", z_level=-1, show="2").rect(bg_color=COLOR2)

    b2 = b.text_box("#B", z_level=-1, show="3", padding=-3).rect(color=COLOR2)
    arrow = elsie.Arrow(10)
    b2.line([b2.p("50%", "160%"), b2.p("50%", "100%")],
            stroke_width=3, color=COLOR2, end_arrow=arrow)
Exemple #5
0
def path_demo(slide):
    slide.box(x=150, y=150).text("Path demo")

    root = slide.box(x=250, y="[50%]", width=100, height=50).rect(color=COLOR1, bg_color="#EEE", rx=5, ry=5).text(
        "Root")
    child1 = slide.box(x=650, y="[20%]", width=100, height=50).rect(color=COLOR1, bg_color="#EEE", rx=5, ry=5).text(
        "Child1")
    child2 = slide.box(x=650, y="[80%]", width=100, height=50).rect(color=COLOR1, bg_color="#EEE", rx=5, ry=5).text(
        "Child2")

    arrow = elsie.Arrow(10)

    # Path root -> child1
    r1 = root.p("100%", "50%")
    c1 = child1.p("0%", "50%")

    # See SVG <path> documentation for commands explanation
    # In short: M = move to, L = line to, C/S = bezier curve, Q/T = quadratic
    slide.path([("M", r1), ("C", r1.add(300, 0), c1.add(-300, 0), c1)], end_arrow=arrow, stroke_width=2, color=COLOR1)

    # Path root -> child2
    c2 = child2.p("0%", "50%")
    slide.path([("M", r1), ("Q", c2.add(-100, 0), c2)], end_arrow=arrow, stroke_width=2, color=COLOR1,
               stroke_dasharray="10")

    # Path chiled1 -> child1
    c1t = child1.p("50%", "0%")
    c1r = child1.p("100%", "50%")
    slide.path([("M", c1t), ("C", c1t.add(0, -100), c1r.add(100, 0), c1r)], end_arrow=arrow, stroke_width=2,
               color=COLOR1)

    # c3 = child2.p("50%", "50%")
    # slide.path([("M", c3.add(0, -100)),
    #            ("C", c3.add(100, -100), c3.add(100, -0), c3.add(0, 100)),
    #            ("C", c3.add(-150, -100), c3.add(-100, -10), c3.add(0, -100))], bg_color="#909090", color=None)#

    slide.path([("M", (650, 350)), ("L", (750, 350))], stroke_width=4, color="green")
    slide.path([("M", (600, 450)), ("L", (700, 250)), ("L", (800, 450))], stroke_width=4, color="red")
    slide.path([("M", (600, 450)), ("Q", (700, 250), (800, 450))], bg_color="blue", color=None)
Exemple #6
0
def shape_demo(slide):
    slide.box(x=650, y=350, width=50, height=50).ellipse(bg_color="green")
    slide.box(x=720, y=350, width=150, height=50).ellipse(bg_color="purple",
                                                          color="yellow",
                                                          stroke_width=10)
    slide.box(x=900, y=350, width=50, height=100).ellipse(bg_color="blue")

    slide.box(x=100, y=100, width=200, height=200).rect(color="green")
    slide.box(x=120, y=120, width=160, height=160).rect(bg_color="green")

    slide.box(x=320, y=100, width=200, height=200).rect(color="blue",
                                                        rx=20,
                                                        ry=20)
    slide.box(x=340, y=120, width=160, height=160).rect(bg_color="blue",
                                                        rx=20,
                                                        ry=20)

    slide.polygon([(540, 300), (740, 300), (640, 100)], color="red")
    slide.polygon([(570, 280), (710, 280), (640, 140)], bg_color="red")

    slide.line([(760, 100), (940, 100), (760, 300), (960, 300)],
               color="orange",
               stroke_width=5)

    slide.line([(100, 500), (200, 500)], color="black", stroke_width=1)
    slide.line([(100, 550), (200, 550)], color="black", stroke_width=5)
    slide.line([(100, 600), (200, 600)], color="black", stroke_width=10)

    arrow1 = elsie.Arrow(10, stroke_width=1)
    slide.line(
        [(300, 500), (400, 500)],
        color="black",
        stroke_width=1,
        start_arrow=arrow1,
        end_arrow=arrow1,
    )
    arrow2 = elsie.Arrow(20, stroke_width=5)
    slide.line(
        [(300, 550), (400, 550)],
        color="black",
        stroke_width=5,
        start_arrow=arrow2,
        end_arrow=arrow2,
    )
    arrow3 = elsie.Arrow(30, stroke_width=10)
    slide.line(
        [(300, 600), (400, 600)],
        color="black",
        stroke_width=10,
        start_arrow=arrow3,
        end_arrow=arrow3,
    )

    arrow1 = elsie.Arrow(10)
    slide.line(
        [(500, 500), (600, 500)],
        color="black",
        stroke_width=1,
        start_arrow=arrow1,
        end_arrow=arrow1,
    )
    arrow2 = elsie.Arrow(20)
    slide.line(
        [(500, 550), (600, 550)],
        color="black",
        stroke_width=5,
        start_arrow=arrow2,
        end_arrow=arrow2,
    )
    arrow3 = elsie.Arrow(30)
    slide.line(
        [(500, 600), (600, 600)],
        color="black",
        stroke_width=10,
        start_arrow=arrow3,
        end_arrow=arrow3,
    )

    arrow1 = elsie.Arrow(10, inner=0.5)
    slide.line(
        [(700, 500), (800, 500)],
        color="black",
        stroke_width=1,
        start_arrow=arrow1,
        end_arrow=arrow1,
    )
    arrow2 = elsie.Arrow(20, inner=0.5)
    slide.line(
        [(700, 550), (800, 550)],
        color="black",
        stroke_width=5,
        start_arrow=arrow2,
        end_arrow=arrow2,
    )
    arrow3 = elsie.Arrow(30, inner=0.5)
    slide.line(
        [(700, 600), (800, 600)],
        color="black",
        stroke_width=10,
        start_arrow=arrow3,
        end_arrow=arrow3,
    )

    arrow1 = elsie.Arrow(10, inner=2.0)
    slide.line(
        [(900, 500), (1000, 500)],
        color="black",
        stroke_width=1,
        start_arrow=arrow1,
        end_arrow=arrow1,
    )
    arrow2 = elsie.Arrow(20, inner=2.0)
    slide.line(
        [(900, 550), (1000, 550)],
        color="black",
        stroke_width=5,
        start_arrow=arrow2,
        end_arrow=arrow2,
    )
    arrow3 = elsie.Arrow(30, inner=2.0)
    slide.line(
        [(900, 600), (1000, 600)],
        color="black",
        stroke_width=10,
        start_arrow=arrow3,
        end_arrow=arrow3,
    )

    # Dashes

    # dash(10) space(10) ...
    slide.line([(100, 350), (500, 350)],
               stroke_width=10,
               stroke_dasharray="10")

    # dash(10) space(20) ...
    slide.line([(100, 380), (500, 380)],
               stroke_width=10,
               stroke_dasharray="10 20")

    # dash(20) space(10) dash(2) space(10) ...
    slide.line([(100, 410), (500, 410)],
               stroke_width=10,
               stroke_dasharray="20 10 2 10")

    # dashed rectangle
    slide.box(x=550, y=350, width=50, height=50).rect(stroke_width=5,
                                                      stroke_dasharray="2",
                                                      color="black",
                                                      rx=5,
                                                      ry=5)