This commit is contained in:
Panayiotis Lipiridis
2020-04-07 13:23:58 +03:00
parent 7726bec6b5
commit 5a10a06c19
4 changed files with 15504 additions and 0 deletions
+1
View File
@@ -1 +1,2 @@
.DS_store
__pycache__
+25
View File
@@ -0,0 +1,25 @@
import excalidraw
scene = excalidraw.Excalidraw()
size = 32
width = 16
for column in range(size):
for row in range(size):
red = row * 256 // size
green = column * 256 // size
blue = column * 256 // size
color = "#%02x%02x%02x" % (red, green, blue)
scene.add_rectangle(
row * size,
column * size,
size,
size,
backgroundColor=color,
fillStyle="solid",
)
scene.save_as("hola")
print(f"Total objects {size * size}")
+108
View File
@@ -0,0 +1,108 @@
import json
import random
CANVAS = [
"#ffffff",
"#f8f9fa",
"#f1f3f5",
"#fff5f5",
"#fff0f6",
"#f8f0fc",
"#f3f0ff",
"#edf2ff",
"#e7f5ff",
"#e3fafc",
"#e6fcf5",
"#ebfbee",
"#f4fce3",
"#fff9db",
"#fff4e6",
]
BACKGROUND = [
"transparent",
"#ced4da",
"#868e96",
"#fa5252",
"#e64980",
"#be4bdb",
"#7950f2",
"#4c6ef5",
"#228be6",
"#15aabf",
"#12b886",
"#40c057",
"#82c91e",
"#fab005",
"#fd7e14",
]
STROKE = [
"#000000",
"#343a40",
"#495057",
"#c92a2a",
"#a61e4d",
"#862e9c",
"#5f3dc4",
"#364fc7",
"#1864ab",
"#0b7285",
"#087f5b",
"#2b8a3e",
"#5c940d",
"#e67700",
"#d9480f",
]
class Excalidraw:
data = {
"version": 1,
"type": "excalidraw",
"source": "py-excalidraw",
"elements": [],
"appState": {"viewBackgroundColor": CANVAS[0]},
}
def __new_element(
self, element_type, angle=0, roughness=1, strokeWidth=1, fillStyle="hachure"
):
return {
"type": element_type,
"opacity": 100,
"seed": random.randint(1000000, 100000000),
"strokeColor": STROKE[0],
"fillStyle": fillStyle,
"strokeWidth": strokeWidth,
"roughness": roughness,
"angle": angle,
}
def add_rectangle(
self,
x,
y,
width,
height,
strokeColor=STROKE[0],
backgroundColor=BACKGROUND[0],
**kargs,
):
rectangle = self.__new_element("rectangle", **kargs)
rectangle["x"] = x
rectangle["y"] = y
rectangle["width"] = width
rectangle["height"] = height
rectangle["strokeColor"] = strokeColor
rectangle["backgroundColor"] = backgroundColor
self.data["elements"].append(rectangle)
def save_as(self, filename):
filename = filename if filename.find(".") > -1 else f"{filename}.excalidraw"
with open(filename, "w") as excalidraw_file:
json.dump(self.data, excalidraw_file, indent=2)
print(f"File saved {filename}")
def get_data(self):
return self.data
File diff suppressed because it is too large Load Diff