import vsketch


class TenPrintSketch(vsketch.SketchClass):
    cell = vsketch.Param(10.0, 4.0, 30.0)  # size of one cell, in mm
    chance = vsketch.Param(0.5, 0.0, 1.0)  # chance of "/" instead of "\"

    def draw(self, vsk: vsketch.Vsketch) -> None:
        vsk.size("a4", landscape=True)
        vsk.scale("mm")

        cols = int(250 // self.cell)
        rows = int(170 // self.cell)
        for row in range(rows):
            for col in range(cols):
                x = col * self.cell
                y = row * self.cell
                if vsk.random(1) < self.chance:
                    vsk.line(x, y + self.cell, x + self.cell, y)  # /
                else:
                    vsk.line(x, y, x + self.cell, y + self.cell)  # \

    def finalize(self, vsk: vsketch.Vsketch) -> None:
        vsk.vpype("linemerge linesimplify reloop linesort")


if __name__ == "__main__":
    TenPrintSketch.display()
