{ "nodes": [ { "datums": [ { "expr": "0.0", "name": "x", "type": "float", "uid": 0 }, { "expr": "0.0", "name": "y", "type": "float", "uid": 1 }, { "expr": "2", "name": "width", "type": "float", "uid": 2 }, { "expr": "2", "name": "height", "type": "float", "uid": 3 }, { "expr": "0.25", "name": "r", "type": "float", "uid": 4 }, { "expr": "\u0012fab.types.Shape('iiiiiaa-f-1X-Xf1a-f-0.75Y-Yf0.75aa-f-0.75X-Xf0.75a-f-1Y-Yf1-r+q-Xf-0.75q-Yf-0.75f0.25-r+q-Xf-0.75q-Yf0.75f0.25-r+q-Xf0.75q-Yf-0.75f0.25-r+q-Xf0.75q-Yf0.75f0.25',float('-1.000000'),float('-1.000000'),float('-inf'),float('1.000000'),float('1.000000'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 5 } ], "inspector": [ -251, -331 ], "name": "r0", "script": [ "# Neil Gershenfeld 1/24/15", "# Matt Keeter 6/11/15", "", "import fab", "", "title('Rounded rectangle (center)')", "", "input('x', float)", "input('y', float)", "input('width', float)", "input('height', float)", "input('r', float)", "", "xmin, xmax = x - width/2, x + width/2", "ymin, ymax = y - height/2, y + height/2", "", "# This is the circle's radius in actual units (not a 0-1 fraction)", "r_ = r * min(width, height)/2", "", "output('shape', fab.shapes.rounded_rectangle(xmin, xmax, ymin, ymax, r))", "", "def drag_r(this, x, y, z):", " if abs(this.width) < abs(this.height):", " d = abs(this.width)", " mid = this.y + this.height/2 - d/2", " else:", " d = abs(this.width)", " mid = this.y", " r = 1 - (y - mid) / (d/2)", " this.r = float(min(1, max(0, r)))", "", "def drag_hw(this, x, y, z):", " this.height = abs(2 * (y - this.y))", " this.width = abs(2 * (x - this.x))", "", "# UI", "sb.ui.wireframe(", " [(xmin, ymin, 0), (xmax, ymin, 0), (xmax, ymax, 0), (xmin, ymax, 0)],", " close=True)", "sb.ui.wireframe([(xmax - r_, ymax, 0), (xmax, ymax - r_, 0)])", "sb.ui.point(x, y)", "sb.ui.point(xmax, ymax, drag=drag_hw, relative=False)", "sb.ui.point(xmax, ymax - r_, drag=drag_r, relative=False)", "", "" ], "uid": 0 }, { "datums": [ { "expr": "r0.4", "name": "x0", "type": "float", "uid": 0 }, { "expr": "0", "name": "y0", "type": "float", "uid": 1 }, { "expr": "2", "name": "width", "type": "float", "uid": 2 }, { "expr": "1", "name": "height", "type": "float", "uid": 3 }, { "expr": "\u0012fab.types.Shape('aa-f-1X-Xf1a-f-0.5Y-Yf0.5',float('-1.000000'),float('-0.500000'),float('-inf'),float('1.000000'),float('0.500000'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ -239, -80 ], "name": "r1", "script": [ "# Neil Gershenfeld 1/24/15", "# Matt Keeter 6/11/15", "", "import fab", "", "title('Rectangle (center)')", "", "input('x0', float)", "input('y0', float)", "input('width', float)", "input('height', float)", "", "xmin, xmax = x0 - width/2, x0 + width/2", "ymin, ymax = y0 - height/2, y0 + height/2", "", "output('shape', fab.shapes.rectangle(xmin, xmax, ymin, ymax))", "", "def drag_hw(this, x, y, z):", " this.width = abs(2 * (x - this.x0))", " this.height = abs(2 * (y - this.y0))", "", "# UI", "sb.ui.wireframe(", " [(xmin, ymin, 0), (xmax, ymin, 0), (xmax, ymax, 0), (xmin, ymax, 0)],", " close=True)", "sb.ui.point(x0, y0)", "sb.ui.point(xmax, ymax, drag=drag_hw, relative=False)", "" ], "uid": 1 } ], "protocol": 6, "type": "sb" }