Skip to content

Instantly share code, notes, and snippets.

@rkrishnasanka
Created November 17, 2020 04:09
Show Gist options
  • Save rkrishnasanka/45495678fc9d3435eeee58c00cb7080c to your computer and use it in GitHub Desktop.
Save rkrishnasanka/45495678fc9d3435eeee58c00cb7080c to your computer and use it in GitHub Desktop.
import cairo
from parchmint import Device
import json
PT_TO_UM = 1/352.778
f = open("cariotest2.json", "r")
text = f.read()
f.close()
alljson = json.loads(text)
d = Device(alljson)
xspan = d.params.get_param("xspan")
yspan = d.params.get_param("yspan")
print(len(d.components))
print(len(d.connections))
surface = cairo.SVGSurface('test.svg', xspan * PT_TO_UM, yspan * PT_TO_UM)
ctx = cairo.Context(surface)
ctx.scale(PT_TO_UM, PT_TO_UM)
for component in d.components:
xpos = component.params.get_param('position')[0]
ypos = component.params.get_param('position')[1]
# Printing
ctx.rectangle(xpos, ypos, component.xspan, component.yspan)
ctx.fill()
for connection in d.connections:
waypoints = connection.params.get_param("wayPoints")
channelwidth = connection.params.get_param("channelWidth")
for i in range(len(waypoints)-1):
waypoint = waypoints[i]
next_waypoint = waypoints[i+1]
ctx.move_to(waypoint[0], waypoint[1])
ctx.line_to(next_waypoint[0], next_waypoint[1])
ctx.set_line_width(channelwidth/2)
ctx.stroke()
surface.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment