{ "nodes": [ { "datums": [ { "expr": "-2.642943263053894", "name": "x0", "type": "float", "uid": 0 }, { "expr": "0.5100404024124146", "name": "y0", "type": "float", "uid": 1 }, { "expr": "c1.r/2", "name": "r", "type": "float", "uid": 2 }, { "expr": "0.08452280088280156", "name": "_a", "type": "float", "uid": 3 }, { "expr": "\u0012fab.types.Shape('-r+q-Xf-2.64294q-Yf0.51004f1',float('-3.642943'),float('-0.489960'),float('-inf'),float('-1.642943'),float('1.510040'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ -317.83734594947816, 398.37107796641396 ], "name": "c0", "script": [ "# Neil Gershenfeld 1/24/15", "# Matt Keeter 6/11/18", "", "import fab", "import math", "", "title('Circle (center)')", "", "input('x0',float)", "input('y0',float)", "input('r',float)", "input('_a',float)", "", "output('shape', fab.shapes.circle(x0, y0, r))", "", "def drag_r(this,x,y,z):", " dx = x - this.x0", " dy = y - this.y0", " this.r = math.sqrt(dx**2 + dy**2)", " this._a = math.atan2(dy, dx)", "", "# UI", "sb.ui.wireframe([", " (math.cos(i/36. * 2*math.pi) * r + x0,", " math.sin(i/36. * 2*math.pi) * r + y0, 0)", " for i in range(36)], close=True)", "sb.ui.point(x0,y0)", "sb.ui.point(x0 + r*math.cos(_a),", " y0 + r*math.sin(_a),", " drag=drag_r, relative=False)", "", "" ], "uid": 0 }, { "datums": [ { "expr": "0.0", "name": "_x", "type": "float", "uid": 0 }, { "expr": "0.28999995440244675", "name": "_y", "type": "float", "uid": 1 }, { "expr": "\u0011[__0.__0]", "name": "zmin", "type": "float", "uid": 2 }, { "expr": "\u0011[__0.__1]", "name": "zmax", "type": "float", "uid": 3 }, { "expr": "\u0011[__0.__4]", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 }, { "expr": "\u0012fab.types.Shape('am__f1-r+q-Xf-2.64294q-Yf0.51004f1a-f-2.64294Z-Zf0.51004',float('-3.642943'),float('-0.489960'),float('-2.642943'),float('-1.642943'),float('1.510040'),float('0.510040'))", "name": "out", "type": "_fabtypes.Shape", "uid": 5 } ], "inspector": [ 146.36174033145028, 461.8506203962334 ], "name": "e0", "script": [ "import fab", "", "title('Extrude')", "", "input('_x', float)", "input('_y', float)", "input('zmin', float)", "input('zmax', float)", "", "input('shape', fab.types.Shape)", "output('out', fab.shapes.extrude_z(shape, zmin, zmax))", "", "# UI", "sb.ui.wireframe([(_x, _y, zmin), (_x, _y, zmax)], color=sb.color.green)", "sb.ui.point(_x, _y, zmin, color=sb.color.green)", "sb.ui.point(_x, _y, zmax, color=sb.color.green)", "", "" ], "uid": 1 }, { "datums": [ { "expr": "-0.16678225994110107", "name": "x", "type": "float", "uid": 0 }, { "expr": "-0.8226348161697388", "name": "y", "type": "float", "uid": 1 }, { "expr": "0.4899998903274536", "name": "z0", "type": "float", "uid": 2 }, { "expr": "2.669999599456787", "name": "z1", "type": "float", "uid": 3 }, { "expr": "2", "name": "r", "type": "float", "uid": 4 }, { "expr": "\u0012fab.types.Shape('m+f-0.166782/*-Xf-0.166782f2.18+*f0-Zf0.49*f1-f2.67Z+f-0.822635/*-Yf-0.822635f2.18+*f0-Zf0.49*f1-f2.67Z_am__f1-r+q-Xf-0.166782q-Yf-0.822635f2a-f0.49Z-Zf2.67',float('-2.166783'),float('-2.822635'),float('0.490000'),float('1.833218'),float('1.177366'),float('2.670000'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 5 } ], "inspector": [ -532.5895219875574, 80.07909280481178 ], "name": "c1", "script": [ "import fab", "import math", "", "title('Cone (center)')", "", "input('x', float)", "input('y', float)", "input('z0', float)", "input('z1', float)", "input('r', float)", "", "output('shape', fab.shapes.cone(x, y, z0, z1, r))", "", "# UI", "sb.ui.wireframe([", " (math.cos(i/36. * 2*math.pi) * r + x,", " math.sin(i/36. * 2*math.pi) * r + y, z0)", " for i in range(36)], close=True)", "sb.ui.wireframe([(x,y,z0), (x+r,y,z0)])", "sb.ui.wireframe([(x,y,z0), (x,y,z1)])", "", "sb.ui.point(x, y, z0)", "sb.ui.point(x, y, z1)", "sb.ui.point(x + r, y, z0, drag=(r, None, None))", "" ], "uid": 2 }, { "datums": [ { "expr": "\u0011[__2.__5]", "name": "shape", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "0", "name": "hue", "type": "float", "uid": 1 }, { "expr": "1", "name": "saturation", "type": "float", "uid": 2 }, { "expr": "1", "name": "brightness", "type": "float", "uid": 3 }, { "expr": "\u0012fab.types.Shape('m+f-0.166782/*-Xf-0.166782f2.18+*f0-Zf0.49*f1-f2.67Z+f-0.822635/*-Yf-0.822635f2.18+*f0-Zf0.49*f1-f2.67Z_am__f1-r+q-Xf-0.166782q-Yf-0.822635f2a-f0.49Z-Zf2.67',float('-2.166783'),float('-2.822635'),float('0.490000'),float('1.833218'),float('1.177366'),float('2.670000'),color=(255,0,0))", "name": "out", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ -179.22463627743582, 7.105427357601002e-15 ], "name": "s0", "script": [ "import math", "import fab", "", "title('Set color (HSB)')", "", "input(\"shape\", fab.types.Shape)", "input(\"hue\", float)", "input(\"saturation\", float)", "input(\"brightness\", float)", "", "# copied from Java's HSBtoRGB", "# http://www.docjar.com/html/api/java/awt/Color.java.html", "", "r = 0", "g = 0", "b = 0", "", "if saturation == 0:", " r = g = b = int(brightness * 255.0 + 0.5)", "else:", " h = (hue - float(math.floor(hue))) * 6.0", " f = h - float(math.floor(h))", " p = brightness * (1-saturation)", " q = brightness * (1-saturation*f)", " t = brightness * (1-(saturation*(1-f)))", "", " h = int(h)", "", " if(h==0):", " r = int(brightness * 255.0 + 0.5)", " g = int(t * 255.0 + 0.5)", " b = int(p * 255.0 + 0.5)", " elif(h==1):", " r = int(q * 255.0 + 0.5)", " g = int(brightness * 255.0 + 0.5)", " b = int(p * 255.0 + 0.5)", " elif(h==2):", " r = int(p * 255.0 + 0.5)", " g = int(brightness * 255.0 + 0.5)", " b = int(t * 255.0 + 0.5)", " elif(h==3):", " r = int(p * 255.0 + 0.5)", " g = int(q * 255.0 + 0.5)", " b = int(brightness * 255.0 + 0.5)", " elif(h==4):", " r = int(t * 255.0 + 0.5)", " g = int(p * 255.0 + 0.5)", " b = int(brightness * 255.0 + 0.5)", " elif(h==5):", " r = int(brightness * 255.0 + 0.5)", " g = int(p * 255.0 + 0.5)", " b = int(q * 255.0 + 0.5)", "", "output(\"out\", fab.shapes.set_color(shape, r, g, b))", "" ], "uid": 3 }, { "datums": [ { "expr": "2", "name": "x", "type": "float", "uid": 0 }, { "expr": "4", "name": "y", "type": "float", "uid": 1 }, { "expr": "5", "name": "N", "type": "int", "uid": 2 }, { "expr": "3", "name": "r", "type": "float", "uid": 3 }, { "expr": "\u0012fab.types.Shape('m-Xf2-Yf4-Zf0aaaam-Xf0-Yf0-Zf0m+*f1X*f0Y+*f-0X*f1Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f0.309017X*f0.951057Y+*f-0.951057X*f0.309017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f-0.809017X*f0.587785Y+*f-0.587785X*f-0.809017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f-0.809017X*f-0.587785Y+*f0.587785X*f-0.809017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f0.309017X*f-0.951057Y+*f0.951057X*f0.309017Y_m-Xf0-Yf0-Zf0-f-2.42705Y',float('-1.000000'),float('1.000000'),float('-inf'),float('5.000000'),float('7.000000'),float('inf'))", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ -508.7965559994666, 627.384968039911 ], "name": "p0", "script": [ "# Neil Gershenfeld 2/14/15", "# Matt Keeter 6/12/15", "", "import fab", "import math", "", "title('Polygon')", "", "input('x', float)", "input('y', float)", "input('N', int)", "input('r', float)", "", "output('shape', fab.shapes.move(fab.shapes.polygon_radius(x, y, r, N), x, y))", "", "# UI", "# (we need to do a bit of work to make the UI work for both even and", "# odd vertex counts; otherwise it will be off for one or the other)", "a_ = 0 if (N % 2) else (math.pi / N)", "sb.ui.wireframe([", " (x + r * math.sin(a_ + a * math.pi * 2/N),", " y + r * math.cos(a_ + a * math.pi * 2/N), 0)", " for a in range(N)], close=True)", "sb.ui.point(x, y)", "sb.ui.point(x + r * math.sin(a_), y + r * math.cos(a_),", " drag=(None, r, None))", "" ], "uid": 4 }, { "datums": [ { "expr": "0.0", "name": "_x", "type": "float", "uid": 0 }, { "expr": "0.011274337768554688", "name": "_y", "type": "float", "uid": 1 }, { "expr": "\u0011[__4.__0]", "name": "zmin", "type": "float", "uid": 2 }, { "expr": "\u0011[__4.__1]", "name": "zmax", "type": "float", "uid": 3 }, { "expr": "\u0011[__4.__4]", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 }, { "expr": "\u0012fab.types.Shape('am__f1m-Xf2-Yf4-Zf0aaaam-Xf0-Yf0-Zf0m+*f1X*f0Y+*f-0X*f1Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f0.309017X*f0.951057Y+*f-0.951057X*f0.309017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f-0.809017X*f0.587785Y+*f-0.587785X*f-0.809017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f-0.809017X*f-0.587785Y+*f0.587785X*f-0.809017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f0.309017X*f-0.951057Y+*f0.951057X*f0.309017Y_m-Xf0-Yf0-Zf0-f-2.42705Ya-f2Z-Zf4',float('-1.000000'),float('1.000000'),float('2.000000'),float('5.000000'),float('7.000000'),float('4.000000'))", "name": "out", "type": "_fabtypes.Shape", "uid": 5 } ], "inspector": [ -113.12760729568635, 710.5430615538053 ], "name": "e1", "script": [ "import fab", "", "title('Extrude')", "", "input('_x', float)", "input('_y', float)", "input('zmin', float)", "input('zmax', float)", "", "input('shape', fab.types.Shape)", "output('out', fab.shapes.extrude_z(shape, zmin, zmax))", "", "# UI", "sb.ui.wireframe([(_x, _y, zmin), (_x, _y, zmax)], color=sb.color.green)", "sb.ui.point(_x, _y, zmin, color=sb.color.green)", "sb.ui.point(_x, _y, zmax, color=sb.color.green)", "", "" ], "uid": 5 }, { "datums": [ { "expr": "-2.95386403799057", "name": "x", "type": "float", "uid": 0 }, { "expr": "1.9053553342819214", "name": "y", "type": "float", "uid": 1 }, { "expr": "0.0", "name": "_z", "type": "float", "uid": 2 }, { "expr": "-52.490690969601225", "name": "a", "type": "float", "uid": 3 }, { "expr": "\u0011[__3.__0]", "name": "shape", "type": "_fabtypes.Shape", "uid": 4 }, { "expr": "\u0012fab.types.Shape('m-Xf-2.95386-Yf1.90536-Zf0m+*f0.60889X*f-0.793254Y+*f0.793254X*f0.60889Y_m-Xf2.95386-Yf-1.90536-Zf0m+f-0.166782/*-Xf-0.166782f2.18+*f0-Zf0.49*f1-f2.67Z+f-0.822635/*-Yf-0.822635f2.18+*f0-Zf0.49*f1-f2.67Z_am__f1-r+q-Xf-0.166782q-Yf-0.822635f2a-f0.49Z-Zf2.67',float('-6.225118'),float('-4.770838'),float('0.490000'),float('-0.616540'),float('0.837740'),float('2.670000'))", "name": "rotated", "type": "_fabtypes.Shape", "uid": 5 } ], "inspector": [ 139.82063823062356, 242.77947183681007 ], "name": "r0", "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": 6 }, { "datums": [ { "expr": "\u0011[__5.__5]", "name": "shape", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "2", "name": "r", "type": "int", "uid": 1 }, { "expr": "4", "name": "g", "type": "int", "uid": 2 }, { "expr": "230", "name": "b", "type": "int", "uid": 3 }, { "expr": "\u0012fab.types.Shape('am__f1m-Xf2-Yf4-Zf0aaaam-Xf0-Yf0-Zf0m+*f1X*f0Y+*f-0X*f1Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f0.309017X*f0.951057Y+*f-0.951057X*f0.309017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f-0.809017X*f0.587785Y+*f-0.587785X*f-0.809017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f-0.809017X*f-0.587785Y+*f0.587785X*f-0.809017Y_m-Xf0-Yf0-Zf0-f-2.42705Ym-Xf0-Yf0-Zf0m+*f0.309017X*f-0.951057Y+*f0.951057X*f0.309017Y_m-Xf0-Yf0-Zf0-f-2.42705Ya-f2Z-Zf4',float('-1.000000'),float('1.000000'),float('2.000000'),float('5.000000'),float('7.000000'),float('4.000000'),color=(2,4,230))", "name": "out", "type": "_fabtypes.Shape", "uid": 4 } ], "inspector": [ 186.8512165445606, 700.3742878643054 ], "name": "s1", "script": [ "import fab", "import math", "", "title('Set color (RGB)')", "", "input(\"shape\", fab.types.Shape)", "input(\"r\", int)", "input(\"g\", int)", "input(\"b\", int)", "", "output(\"out\", fab.shapes.set_color(shape, r, g, b))", "" ], "uid": 7 }, { "datums": [ { "expr": "\u0011[__3.__4]", "name": "shape", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "2", "name": "x", "type": "float", "uid": 1 }, { "expr": "4", "name": "y", "type": "float", "uid": 2 }, { "expr": "-1", "name": "z0", "type": "float", "uid": 3 }, { "expr": "1", "name": "z1", "type": "float", "uid": 4 }, { "expr": "0", "name": "theta0", "type": "float", "uid": 5 }, { "expr": "90", "name": "theta1", "type": "float", "uid": 6 }, { "expr": "\u0012fab.types.Shape('m-Xf2-Yf4-Zf-1mXY/Zf2m+*Xc+*f1.5708Z*f0-f1Z*Ys+*f1.5708Z*f0-f1Z+n*Xs+*f1.5708Z*f0-f1Z*Yc+*f1.5708Z*f0-f1Z_mXY/Zf0.5m-Xf-2-Yf-4-Zf1m+f-0.166782/*-Xf-0.166782f2.18+*f0-Zf0.49*f1-f2.67Z+f-0.822635/*-Yf-0.822635f2.18+*f0-Zf0.49*f1-f2.67Z_am__f1-r+q-Xf-0.166782q-Yf-0.822635f2a-f0.49Z-Zf2.67',float('-8.989418'),float('-6.989418'),float('0.490000'),float('12.989418'),float('14.989418'),float('2.670000'),color=(255,0,0))", "name": "twisted", "type": "_fabtypes.Shape", "uid": 7 } ], "inspector": [ 179.22463627743568, -49.57277173631199 ], "name": "t0", "script": [ "# Neil Gershenfeld 1/24/15", "# Matt Keeter 6/13/15", "", "import fab", "", "title('Twist (Z)')", "", "input('shape', fab.types.Shape)", "input('x', float)", "input('y', float)", "input('z0', float)", "input('z1', float)", "input('theta0', float)", "input('theta1', float)", "", "output('twisted', fab.shapes.twist_xy_z(shape, x, y, z0, z1, theta0, theta1))", "", "" ], "uid": 8 }, { "datums": [ { "expr": "\u0011[__8.__0]", "name": "shape", "type": "_fabtypes.Shape", "uid": 0 }, { "expr": "\u0012fab.types.Shape('m+f-0.166782/*-Xf-0.166782f2.18+*f0-Zf0.49*f1-f2.67Z+f-0.822635/*-Yf-0.822635f2.18+*f0-Zf0.49*f1-f2.67Z_am__f1-r+q-Xf-0.166782q-Yf-0.822635f2a-f0.49Z-Zf2.67',float('-2.166783'),float('-2.822635'),float('0.490000'),float('1.833218'),float('1.177366'),float('2.670000'),color=(255,0,0))", "name": "copy", "type": "_fabtypes.Shape", "uid": 1 } ], "inspector": [ 530.0473285651822, -30.50632106849969 ], "name": "c2", "script": [ "# Neil Gershenfeld 2/14/15", "# Matt Keeter 6/12/15", "", "import fab", "", "title('Copy')", "", "input('shape', fab.types.Shape)", "output('copy', shape)", "", "" ], "uid": 9 } ], "protocol": 6, "type": "sb" }