# Let's Tessellate!

### Introduction

From Wikipedia:

A tessellation of a flat surface is the tiling of a plane using one or more geometric shapes, called tiles, with no overlaps and no gaps.

A fairly well known tessellation is shown below:

The rhombi are tiled in a fashion that results in no overlaps or gaps, and simulates interchanging columns of cubes.

Your task is to write a program that tessellates rhombi the same way the image does above. The input for the program will be dimensions of the tessellation: height x width, where width is the amount of columns and height is the amount of rows.

A single cube that is 1 x 1 (3 tiles of rhombi) is represented exactly as so:

    _____
/\      \
/  \      \
/    \ _____\
\    /      /
\  /      /
\/_____ /


So if the input/dimensions are 3 x 2, this should be the output:

    _____
/\      \
/  \      \
/    \ _____\ _____
\    /      /\      \
\  /      /  \      \
\/_____ /    \ _____\
/\      \    /      /
/  \      \  /      /
/    \ _____\/_____ /
\    /      /\      \
\  /      /  \      \
\/_____ /    \ _____\
/\      \    /      /
/  \      \  /      /
/    \ _____\/_____ /
\    /      /\      \
\  /      /  \      \
\/_____ /    \ _____\
\    /      /
\  /      /
\/_____ /


As you can see, there are 3 rows (height), and 2 columns (width). The columns are interchanging up and down. Your program should do this too and start higher. For example, 3 x 3 would be:

    _____               _____
/\      \           /\      \
/  \      \         /  \      \
/    \ _____\ _____ /    \ _____\
\    /      /\      \    /      /
\  /      /  \      \  /      /
\/_____ /    \ _____\/_____ /
/\      \    /      /\      \
/  \      \  /      /  \      \
/    \ _____\/_____ /    \ _____\
\    /      /\      \    /      /
\  /      /  \      \  /      /
\/_____ /    \ _____\/_____ /
/\      \    /      /\      \
/  \      \  /      /  \      \
/    \ _____\/_____ /    \ _____\
\    /      /\      \    /      /
\  /      /  \      \  /      /
\/_____ /    \ _____\/_____ /
\    /      /
\  /      /
\/_____ /


### Rules

• The result must be outputted, input may be taken in whatever way you like but must correspond to height and width
• Trailing newlines are allowed
• The tessellation columns always start from above then alternate up and down
• Sides of tessellations must be shared and tessellations must be correctly placed in between the other columns with no gaps
• Your submission may be a function or a full program
• Your program must print exactly the output above given the same input; in other words the output must follow the same format for cubes/tessellations

### Assumptions

• You can assume that the input will always be greater than 1 x 1, so you don't need cases where a zero is inputted

### Scoring

This is , so the shortest code in bytes wins. Standard loopholes are prohibited as well.

## JavaScript (ES6), 243 bytes

f=
(h,w)=>[...Array(h*6+4)].map((_,i)=>[...Array(w*9+3)].map((_,j)=>i&&(i+j+3)%6==0&&j%9<(i>3?6:3)&&(i>3|j<w*9)&&(j>2|i<h*6)?'/':i&&(i-j+2)%6==0&&j%9<(i>h*6?j<w*9?3:0:6)?'\\':i%3==0&&j>2&&(i*3+j+14)%18%(!i|i>h*6?18:12)<4?'_':' ').join).join

<div oninput=o.textContent=+h.value&&+w.value?f(h.value,w.value):''><input id=h type=number min=1><input id=w type=number min=1><pre id=o>

Directly calculates all the desired characters. For /:

i&&                         Not on first row of output
(i+j+3)%6==0&&              Backward diagonals
j%9<                        Not on top (right) diamond of hexagons or
(i>3?6:3)&&             empty spaces on top half row
(i>3|j<w*9)&&               Not on top right corner of output
(j>2|i<h*6)                 Not on bottom left corner of output


For \:

i&&                         Not on first row of output
(i-j+2)%6==0&&              Forward diagonals
j%9<                        Not on bottom (right) diamond of hexagons or
(i>h*6?                 empty spaces on bottom half row or
j<w*9?3:0:6)        bottom right corner of output


For _:

i%3==0&&                    Every third line
j>2&&                       Not on left two columns
(i*3+j+14)%18%              Every 18 characters
(!i|i>h*6?18:12)<4      One or two groups


# Befunge, 277 269 bytes

&6*4+00p&:55+*3+10p2%20pv@
6+5:g03%*54:::<<0+55p03:<<v%*54++55:\p04:**+3g03g00\g01+*3!g02\-*84g+3+!\%
48*+,1+:10g!#^_\$,1+:00g-|>30g:2+6%\3-!+3+g48*-\:2\20g3*+10g\*30g2**40g!*+
/\      \
/  \      \
/    \ _____\
\    /      /
\  /      /
\/_____ /
_____


Try it online!

This question looked deceptively easy, but the edge cases turned out to be more complicated than I had originally anticipated. The best approach I could come up with was to handle the odd and even columns as separate renderings, and then just merge the results.

So for each x,y coordinate that has to be output, we first need to determine what character should be rendered for an odd column, by mapping the x,y output coordinates to u,v coordinates in the cube diagram as follows:

u = x%20
v = (y+5)%6 + (y==0)


The addition of (y==0) is to handle the special case of the first line. But we also need to make sure we aren't rendering the last few lines at the bottom of the column, and the last few characters on the end of each row. This is achieved by multiplying output character with the expression:

(y > h-3) && (x > w-3*!(columns%2))


The !(columns%2) in the width calculation is because the amount we need to trim off the end is dependent on whether the total column count is even or odd.

We then do a second calculation to determine what character should be rendered for an even column, mapping the u,v coordinates as follows:

u = (x+10)%20
v = (y+2)%6 + (y==3)


This is the same basic calculation as used for the odd columns, but offset slightly. And as before, we need to make sure we don't render some of the characters on the boundaries - this time the first few lines at the top of the column, as well as some characters at the beginning and end of each row. The expression we multiply in this case is:

(y > 2) && (x > 2) && (x < w-3*(columns%2))


Having calculated these two potential output characters, the final value used is:

char1 + (char2 * !char1) + 32


In other words, if char1 is zero we need to output char2, otherwise we output char1. If both are non-zero, we're just going to output char1, but that's fine because they'd both be the same value anyway. Also note that these character values are offset by 32 (hence the addition of 32) so that zero will always end up as a space.

## Batch, 590 bytes

@echo off
set c=call:c
set b=\      \
set f=%b:\=/%
set s=
set u=_____
set w=%2
%c%"   " " %u%" "%s%%s%"
%c%"  " "/%b%" "%s%    "
%c%" " "/  %b%" "%s%  "
%c%"" "/    \ %u%\" " %u% "
for /l %%i in (1,1,%1)do %c%"\" "    %f%" "%b%"&%c%" \" "  %f%" "  %b%"&%c%"  \" "/%u% /" "    \ %u%\"&if %%i lss %1 %c%"  /" "%b%" "    %f%"&%c%" /" "  %b%" "  %f%"&%c%"/" "    \ %u%\" "/%u% /"
%c%"   " "" "%s%\    %f%"
%c%"  " "" "  %s%\  %f%"
%c%" " "" "    %s%\/%u% /"
exit/b
:c
set o=%~1
for /l %%j in (%w%,-2,1)do call set o=%%o%%%~2&if %%j gtr 1 call set o=%%o%%%~3
echo(%o%


The :c subroutine takes three parameters; %3 is the difference between 1 and 2 columns, %2 is the difference between 2 and 3 columns, %1 is the extra prefix for the first column, so one column is %1%2, two columns is %1%2%3, three columns is %1%2%3%2, four columns is %1%2%3%2%3 etc.

# Python 2, 329326 319 bytes

h,w=input()
a,R=[' '*10]*3,range
b='  /\      \  # /  \      \ #/    \ _____\#\    /      /# \  /      / #  \/_____ /  '.split('#')
c=['    _____    ']+b*h
e,o=c+a,a+c
k=len(e)
f=e[:]
o[3]=o[3][:10]
for x in R(1,w):
for y in R(k):f[y]+=((e[y][3:],e[y])[y in R(4)],(o[y][3:],o[y])[y in R(k-3,k)])[x%2]
print'\n'.join(f)


Try it online!

Actually 21 24 31 bytes shorter than my previous incorrect post. Creates lists for the odd and even columns then concatenates them for each column in the width.