Skip to content

Instantly share code, notes, and snippets.

@janpipek
Last active January 21, 2021 13:46
Show Gist options
  • Save janpipek/e38922223b4080cb964388f7e113662f to your computer and use it in GitHub Desktop.
Save janpipek/e38922223b4080cb964388f7e113662f to your computer and use it in GitHub Desktop.
Home bookshelf design
import matplotlib.pyplot as plt
import numpy as np
from draw import *
from data import *
fig, ax = plt.subplots(figsize=(20, 12))
nonwallcolor = "#c0c0c0"
block(ax, DOORX, DOORY, DOORDX, DOORDY, facecolor="grey")
block(ax, -10000, -10000, 10000, 20000, facecolor=nonwallcolor)
block(ax, -10000, -10000, 20000, 10000, facecolor=nonwallcolor)
block(ax, -10000, CEILING, 20000, 10000, facecolor=nonwallcolor)
block(ax, TOTAL_WIDTH, -10000, 10000, 20000, facecolor=nonwallcolor)
block(ax, TOTAL_WIDTH, -10000, 10000, 20000, facecolor=nonwallcolor)
draw(ax, XMIN1, YMIN1, TOTAL_HEIGHT1, WIDTHS1, HEIGHTS1)
draw(ax, XMIN2, YMIN2, TOTAL_HEIGHT2, WIDTHS2, HEIGHTS2)
draw(ax, XMIN3, YMIN3, TOTAL_HEIGHT3, WIDTHS3, HEIGHTS3)
circle(ax, 320, 180)
circle(ax, 400, 180)
circle(ax, 3140, 180)
circle(ax, 3140, 1230)
circle(ax, 0, 1230)
ax.set_xlim(-50, 5500)
ax.set_ylim(-50, 3000);
kwargs = dict(horizontalalignment="center", fontsize=20)
ax.text(XMIN1 + TOTAL_WIDTH1 / 2, TOTAL_HEIGHT1 + 300, f"{TOTAL_HEIGHT1} x {TOTAL_WIDTH1}", **kwargs)
ax.text(XMIN2 + TOTAL_WIDTH2 / 2, TOTAL_HEIGHT1 + 300, f"{TOTAL_HEIGHT2} x {TOTAL_WIDTH2}", **kwargs)
ax.text(XMIN3 + TOTAL_WIDTH3 / 2, TOTAL_HEIGHT1 + 300, f"{TOTAL_HEIGHT3} x {TOTAL_WIDTH3}", **kwargs);
fig.tight_layout()
fig.savefig("bookshelf.pdf")
DOORX = 3230
DOORDX = 886
DOORY = 0
DOORDY = 1985
THICKNESS = 18
CEILING = 2560
TOTAL_WIDTH = DOORX + DOORDX + 1210
W1 = 499
W2 = 338
W3 = 161
CD = 125 + 30 + THICKNESS
DVD = 190 + 30 + THICKNESS
BOOK1 = 220 + 30 + THICKNESS
BOOK2 = 300 + 30 + THICKNESS
PATTERN1 = [BOOK1 + 10, DVD, BOOK1, DVD, BOOK1 + 20, BOOK1 + 20, BOOK1, BOOK1]
PATTERN2 = [BOOK2, 288, 270, BOOK2, BOOK1, 360, CD]
PATTERN3 = [BOOK1 - 10, BOOK1 - 10, BOOK1, BOOK2, BOOK1, BOOK1 - 10, BOOK1, BOOK1 + 20]
PATTERN4 = [BOOK2] + [BOOK1, W3] * 4
PATTERN5 = [BOOK1 + 20, BOOK1 + 10, CD, CD, CD, 630, DVD, DVD]
PATTERN6 = PATTERN3[:]
PATTERN7 = PATTERN2[:]
PATTERN8 = PATTERN1[:]
WIDTHS1 = [
W1,
W2,
W1,
W3,
W1,
W2,
W1,
W2
]
HEIGHTS1 = [
PATTERN1,
PATTERN2,
PATTERN3,
PATTERN4,
PATTERN5,
PATTERN6,
PATTERN7,
PATTERN8,
]
MARGIN = 10
XMIN1 = DOORX - sum(WIDTHS1) - THICKNESS - MARGIN
YMIN1 = 70
TOTAL_HEIGHT1 = CEILING - YMIN1
WIDTH2_1 = 435
WIDTHS2 = [
WIDTH2_1,
DOORDX + 2*MARGIN - WIDTH2_1 - THICKNESS
]
HEIGHTS2 = [
[270],
[360],
]
XMIN2 = XMIN1 + sum(WIDTHS1) + THICKNESS
YMIN2 = DOORDY + MARGIN
TOTAL_HEIGHT2 = CEILING - MARGIN - DOORDY
WIDTHS3 = [
490,
220,
441,
]
HEIGHTS3 = [
[258] + list(reversed(PATTERN3))[:-1],
[417] + list(reversed(PATTERN2))[:-1],
[338] + list(reversed(PATTERN1))[:-1],
]
TOTAL_WIDTH1 = sum(WIDTHS1) + THICKNESS
TOTAL_WIDTH2 = sum(WIDTHS2) + THICKNESS
TOTAL_WIDTH3 = sum(WIDTHS3) + THICKNESS
XMIN3 = XMIN2 + sum(WIDTHS2) + THICKNESS
YMIN3 = YMIN1
TOTAL_HEIGHT3 = TOTAL_HEIGHT1
RIGHT_MARGIN = TOTAL_WIDTH - XMIN3 - sum(WIDTHS3) - THICKNESS
import matplotlib.pyplot as plt
from data import THICKNESS
def block(ax, x, y, dx, dy, facecolor="black"):
rect = plt.Rectangle([x, y], dx, dy, facecolor=facecolor, lw=0)
ax.add_patch(rect)
def draw(ax, xmin, ymin, total_height, widths, heights):
x = xmin
for width, heights_ in zip(widths, heights):
y = ymin
block(ax, x, y, THICKNESS, total_height)
for height in heights_:
block(ax, x + THICKNESS, y, width - THICKNESS, THICKNESS, facecolor="blue")
y += height
ax.text(x + width/2, y + THICKNESS + 10, y + THICKNESS // 2 - ymin,
horizontalalignment="center")
ax.text(x + width/2, y - height / 2, height - THICKNESS, horizontalalignment="center", alpha=0.5, verticalalignment="center")
block(ax, x + THICKNESS, y, width - THICKNESS, THICKNESS, facecolor="blue")
block(ax, x + THICKNESS, ymin + total_height - THICKNESS, width - THICKNESS, THICKNESS, facecolor="blue")
ax.text(x + width/2, total_height + ymin + 50, width - THICKNESS, fontweight="bold",
horizontalalignment="center", verticalalignment="center")
ax.text(x + width/2, (total_height + ymin + y + THICKNESS) / 2, total_height - y + ymin - 2 * THICKNESS, horizontalalignment="center", alpha=0.5)
x += width
block(ax, x, ymin, THICKNESS, total_height)
def circle(ax, x, y):
c = plt.Rectangle([x-40, y-40], 80, 80, facecolor="red", alpha=0.5)
ax.add_patch(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment