{ "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": [ -281.5078125, -277 ], "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": "1", "name": "x0", "type": "float", "uid": 0 }, { "expr": "0", "name": "y0", "type": "float", "uid": 1 }, { "expr": ".14", "name": "width", "type": "float", "uid": 2 }, { "expr": "1.414", "name": "height", "type": "float", "uid": 3 }, { "expr": "\u0012fab.types.Shape('aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707',float('0.930000'),float('-0.707000'),float('-inf'),float('1.070000'),float('0.707000'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ -266, -54 ], "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 }, { "datums": [ { "expr": "r1.x0", "name": "x", "type": "float", "uid": 0 }, { "expr": "r1.y0", "name": "y", "type": "float", "uid": 1 }, { "expr": "0.0", "name": "_z", "type": "float", "uid": 2 }, { "expr": "-45", "name": "a", "type": "float", "uid": 3 }, { "expr": "\u0011[__1.__4]", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 }, { "expr": "\u0012fab.types.Shape('m-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707',float('0.450578'),float('-0.549422'),float('-inf'),float('1.549422'),float('0.549422'),float('inf'))", "name": "rotated", "type": "_fabtypes.Shape", "uid": 5 } ], "inspector": [ -116.77155916467842, 110.47524270870255 ], "name": "r2", "script": [ "import fab", "import math", "", "title('Rotate (Z)')", "", "input('x', float)", "input('y', float)", "input('_z', float)", "input('a', float)", "", "input('shape', fab.types.Shape)", "output('rotated', fab.shapes.rotate_z(shape, a, x, y))", "", "# UI", "rad = math.radians(a)", "sb.ui.wireframe([(x + math.cos(rad), y + math.sin(rad), _z),", " (x, y, _z),", " (x + 1, y, _z)], color=sb.color.teal)", "", "# Draw a semi-circular arc showing the rotation", "if int(a) % 360 != 0:", " sb.ui.wireframe([", " (x + math.cos(math.radians(a_)) * 0.3,", " y + math.sin(math.radians(a_)) * 0.3, _z)", " for a_ in range(int(a) % 360)], color=sb.color.teal)", "", "sb.ui.point(x, y, _z, color=sb.color.teal)", "", "def drag_pt(this, x, y, z):", " this.a = math.degrees(math.atan2(y - this.y, x - this.x))", "sb.ui.point(x + math.cos(rad), y + math.sin(rad), _z,", " color=sb.color.teal, drag=drag_pt, relative=False)", "", "" ], "uid": 2 }, { "datums": [ { "expr": "\u0011[__0.__5]", "name": "a", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "\u0011[__5.__4]", "name": "b", "type": "_fabtypes.Shape", "uid": 1 }, { "expr": "\u0012fab.types.Shape('aiiiiiaa-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.25niiim-Xf0-Yf0-Zf0m+*f1X*f0Y+*f-0X*f1Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f6.12323e-17X*f1Y+*f-1X*f6.12323e-17Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f-1X*f1.22465e-16Y+*f-1.22465e-16X*f-1Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f-1.83697e-16X*f-1Y+*f1X*f-1.83697e-16Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025',float('-1.000000'),float('-1.000000'),float('-inf'),float('1.000000'),float('1.000000'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 2 } ], "inspector": [ 226.27372835253982, -319.96519399851354 ], "name": "d0", "script": [ "import fab.types", "", "title('Difference')", "input('a', fab.types.Shape)", "input('b', fab.types.Shape)", "", "output('shape', a & ~b)", "" ], "uid": 3 }, { "datums": [ { "expr": "r1.x0", "name": "x0", "type": "float", "uid": 0 }, { "expr": "r1.y0-.10", "name": "y0", "type": "float", "uid": 1 }, { "expr": "0.15", "name": "width", "type": "float", "uid": 2 }, { "expr": ".15", "name": "height", "type": "float", "uid": 3 }, { "expr": "\u0012fab.types.Shape('aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025',float('0.925000'),float('-0.175000'),float('-inf'),float('1.075000'),float('-0.025000'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ -268.70005241864112, 475.52838224088453 ], "name": "r3", "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": 4 }, { "datums": [ { "expr": "\u0011[__2.__5,__4.__4]", "name": "shape", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "0.0", "name": "x", "type": "float", "uid": 1 }, { "expr": "0.0", "name": "y", "type": "float", "uid": 2 }, { "expr": "4", "name": "n", "type": "int", "uid": 3 }, { "expr": "\u0012fab.types.Shape('iiim-Xf0-Yf0-Zf0m+*f1X*f0Y+*f-0X*f1Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f6.12323e-17X*f1Y+*f-1X*f6.12323e-17Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f-1X*f1.22465e-16Y+*f-1.22465e-16X*f-1Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f-1.83697e-16X*f-1Y+*f1X*f-1.83697e-16Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025',float('-1.549422'),float('-1.549422'),float('-inf'),float('1.549422'),float('1.549422'),float('inf'))", "name": "array", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ 206.82832982224346, 277.53886993241213 ], "name": "a0", "script": [ "import fab", "import math", "", "title('Array (polar)')", "", "input('shape', fab.types.Shape)", "input('x', float)", "input('y', float)", "input('n', int)", "", "output('array', fab.shapes.iterate_polar(shape, x, y, n))", "", "# UI", "sb.ui.wireframe([", " (math.cos(i/36. * 2*math.pi) * 0.3 + x,", " math.sin(i/36. * 2*math.pi) * 0.3 + y, 0)", " for i in range(36)], close=True, color=sb.color.teal)", "", "sb.ui.point(x, y, 0, color=sb.color.teal)", "" ], "uid": 5 }, { "datums": [ { "expr": "\u0011[__3.__2]", "name": "shape", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "\u0012fab.types.Shape('aiiiiiaa-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.25niiim-Xf0-Yf0-Zf0m+*f1X*f0Y+*f-0X*f1Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f6.12323e-17X*f1Y+*f-1X*f6.12323e-17Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f-1X*f1.22465e-16Y+*f-1.22465e-16X*f-1Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025m-Xf0-Yf0-Zf0m+*f-1.83697e-16X*f-1Y+*f1X*f-1.83697e-16Y_m-Xf-0-Yf-0-Zf0im-Xf1-Yf0-Zf0m+*f0.707107X*f-0.707107Y+*f0.707107X*f0.707107Y_m-Xf-1-Yf-0-Zf0aa-f0.93X-Xf1.07a-f-0.707Y-Yf0.707aa-f0.925X-Xf1.075a-f-0.175Y-Yf-0.025',float('-1.000000'),float('-1.000000'),float('-inf'),float('1.000000'),float('1.000000'),float('inf'))", "name": "out", "type": "_fabtypes.Shape", "uid": 1 } ], "inspector": [ 551.5422128593159, -182.07964078368443 ], "name": "h0", "script": [ "import fab", "", "title('Heightmap (.png)')", "", "input('shape', fab.types.Shape)", "output('out', shape)", "", "sb.export.heightmap(shape)", "" ], "uid": 6 } ], "protocol": 6, "type": "sb" }