-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_disk.py
70 lines (46 loc) · 1.67 KB
/
create_disk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import argparse
from pathlib import Path
from create_blueprint.blueprint import Blueprint
from create_blueprint.shape_id import ShapeId
ZERO_BIT_COLOR = "222222"
ONE_BIT_COLOR = "EEEEEE"
def main():
parser = argparse.ArgumentParser(
"create_disk",
description="Creates blueprint with rectangle with painted bits from specified file.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("file", type=Path)
parser.add_argument("-w", "--stripe-width", type=int)
parser.add_argument(
"-b",
"--blueprints-path",
help="path to a directory in which blueprints will be stored",
type=Path,
default="./blueprints/",
)
args = parser.parse_args()
(args.blueprints_path / args.file.name).mkdir(parents=True, exist_ok=True)
blueprint = Blueprint()
blueprint.name = args.file.name
blueprint.create_solid(ShapeId.Concrete, -1, 0, 0, color="D02525")
bit_offset = 0
bit_rows = []
for byte in args.file.read_bytes():
for _ in range(8):
bit = byte & 1
byte >>= 1
block_color = ONE_BIT_COLOR if bit else ZERO_BIT_COLOR
x = bit_offset
z = 0
if args.stripe_width is not None:
x = bit_offset % args.stripe_width
z = bit_offset // args.stripe_width
blueprint.create_solid(ShapeId.Concrete, x, 0, z, color=block_color)
if x == 0:
bit_rows.append("")
bit_rows[-1] += str(bit)
bit_offset += 1
blueprint.save(args.blueprints_path / args.file.name)
print(*bit_rows[::-1], sep="\n")
main()