<jupyter_start><jupyter_text>Draw a Brick PatternAttempt at programmatically making a brick pattern.All units in mm. ```1``` = ```1 mm```. "Napkin" scratches.![](http://luckofthedraw.fun/.imgs/brick_0003.jpeg)Drawn by hand. ~18mm brick height.![](http://luckofthedraw.fun/.imgs/brick_0001.jpeg) > Standard bricks. The standard co-ordinating size for brickwork is 225 mm x 112.5 mm x 75 mm (length x depth x height). This includes 10 mm mortar joints, and so the standard size for a brick itself is 215 mm x 102.5 mm x 65 mm (length x depth x height).<jupyter_code># Standard brick dimensions.
BrickHeight = 65  # [mm]
BrickLength = 225  # [mm]
BrickDepth = 12.5  # [mm]
BrickRatio = 215 / 65  # [dimensionless]

# Poplar 1x4". Cut
BlockHeight = 89.0  # mm
BlockLength = 2 * BlockHeight  # mm

# Drawing configuration.
# How many rows of bricks to draw on the block.
N_BrickRows = 5  # [dimensionless]

# Dimensions of a 'brick' projected onto the block of wood.
H_Block_Brick = BlockHeight / N_BrickRows  # [mm]
L_Block_Brick = H_Block_Brick * BrickRatio  # [mm]<jupyter_output><empty_output><jupyter_text>Code:<jupyter_code>flip = np.array([[1, 1], [1, 0]])
transform_tuple = (
    np.eye(2),  # Identity matrix, do nothing.
    np.eye(2),  # Do nothing, for debugging.
    flip,  # Flip the matrix, reduces travel time.
)
vertical_brick_lines_tuple = (
    np.arange(L_Block_Brick, BlockLength, L_Block_Brick),# Odd rows.
    np.arange(L_Block_Brick / 2, BlockLength, L_Block_Brick), # Even rows.
)
horizontal_brick_lines = np.linspace(0, BlockHeight, N_BrickRows, endpoint=False)<jupyter_output><empty_output><jupyter_text>Lines parallel to the X-axis.Separates rows of bricks.<jupyter_code>horizontal_brick_lines<jupyter_output><empty_output><jupyter_text>Lines parallel to the Y-axis.<jupyter_code>vertical_brick_lines_tuple
BlockBrick=GCode.Program()
BlockBrick.lines=list()

for idx in [1]:
    # Top horizontal line that defines each 'brick'
    horizontal_brick_line = horizontal_brick_lines[idx]
    row_line_points = np.array(
        [[0, horizontal_brick_line], [BlockLength, horizontal_brick_line]]
    )
    # Transform to perform on the row points.
    transform = transform_tuple[np.mod(idx, 2)]
    
    row_line_points = np.matmul(transform, row_line_points)
    line_ = GCode.Line(
        points=row_line_points,
    )
    
    BlockBrick.lines.append(line_)
    
    # Vertical brick line.
    vertical_brick_lines = vertical_brick_lines_tuple[np.mod(idx, len(vertical_brick_lines_tuple))]
    
    start_point_y = horizontal_brick_lines[idx - 1]
    end_point_y = horizontal_brick_lines[idx]
    
    for idx2, vertical_brick_line in enumerate(vertical_brick_lines):
        transform = transform_tuple[np.mod(idx2, 2)]
        column_line_points = (
            np.array(
                [
                    [vertical_brick_line, start_point_y],
                    [vertical_brick_line, end_point_y],
                ]
            ),
        )
        column_line_points = np.matmul(transform, column_line_points)
        line_ = GCode.Line(column_line_points)
        BlockBrick.lines.append(line_)
BlockBrick.lines
for l in BlockBrick.lines:
    print(l)
    print()
cnc = GRBL.GRBL(port="/dev/cnc_3018")
cnc.reset(home=True)
cnc.home()
cnc.cmd("G21")
cnc.cmd("G90")
cnc.cmd("G28")
cnc.cmd("G0 F120")
cnc.cmd("G1 F120")
cnc.cmd("G92X0Y0Z0")
line=BlockBrick.lines[0]
cnc.run(line)
cnc.status
line=BlockBrick.lines[1]
line
run_status_raw = '<Run|MPos:-170.790,-118.200,-1.000|Bf:14,126|FS:300,150|WCO:-255.900,-136.000,-1.000>'
run_status_=run_status_raw.strip("<>")
run_status = run_status_.split("|")
run_states = ["Idle", "Run", "Hold", "Door", "Home", "Alarm", "Check"]

run_state = run_status[0]

assert(run_state in run_states)
line=BlockBrick.lines[1]
line
cnc.run(line)
for _ in range(360):
    run_status=cnc.status.strip("<>").split("|")
    run_state = run_status[0]
    assert(run_state in run_states)
    if run_state is "Run":
        print(run_state)
    else:
        break
line=BlockBrick.lines[2]
line
cnc.run(line)
for _ in range(360):
    run_status=cnc.status.strip("<>").split("|")
    run_state = run_status[0]
    assert(run_state in run_states)
    if run_state is "Run":
        print(run_state)
    else:
        break
line=BlockBrick.lines[3]
line
cnc.run(line)
for _ in range(360):
    run_status=cnc.status.strip("<>").split("|")
    run_state = run_status[0]
    assert(run_state in run_states)
    if run_state is "Run":
        print(run_state)
    else:
        break<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12571303203159281, 'fraction_numerical': 0.03312856516015796, 'mean_word_length': 3.844845908607864, 'pattern_counts': {'":': 3, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '647101', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1666, 'n_words': 351, 'path': 'Drawing/OldDrawing/Bricks-Copy11.ipynb', 'repo_name': 'jed-frey/python_cnc3018', 'size': '4558'}