Skip to content
Snippets Groups Projects
base.sb 22.3 KiB
Newer Older
Ahmad Fares's avatar
Ahmad Fares committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
{
    "nodes": [
        {
            "datums": [
                {
                    "expr": "\u0011[__1.__4]",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 0
                },
                {
                    "expr": "0",
                    "name": "_x",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "0",
                    "name": "_y",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "4",
                    "name": "i",
                    "type": "int",
                    "uid": 3
                },
                {
                    "expr": "1",
                    "name": "j",
                    "type": "int",
                    "uid": 4
                },
                {
                    "expr": "30",
                    "name": "dx",
                    "type": "float",
                    "uid": 5
                },
                {
                    "expr": "1",
                    "name": "dy",
                    "type": "float",
                    "uid": 6
                },
                {
                    "expr": "\u0012fab.types.Shape('m-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf9.5',float('-54.500000'),float('-9.500000'),float('-inf'),float('54.500000'),float('9.500000'),float('inf'))",
                    "name": "array",
                    "type": "_fabtypes.Shape",
                    "uid": 7
                }
            ],
            "inspector": [
                321.8462833927515,
                -228.85073208229224
            ],
            "name": "a0",
            "script": [
                "import fab",
                "",
                "title('Array (2D)')",
                "",
                "input('shape', fab.types.Shape)",
                "input('_x', float)",
                "input('_y', float)",
                "input('i', int)",
                "input('j', int)",
                "input('dx', float)",
                "input('dy', float)",
                "",
                "output('array', fab.shapes.iterate3d(shape, i, j, 1, dx, dy, 0))",
                "",
                "# UI",
                "sb.ui.wireframe([",
                "    (_x + dx, _y, 0), (_x, _y, 0), (_x, _y + dy, 0)], color=sb.color.teal)",
                "sb.ui.wireframe([",
                "    (_x + dx, _y - 0.3, 0), (_x + dx, _y + 0.3, 0)], color=sb.color.teal)",
                "sb.ui.wireframe([",
                "    (_x + 0.3, _y + dy, 0), (_x - 0.3, _y + dy, 0)], color=sb.color.teal)",
                "",
                "sb.ui.point(_x, _y, 0, color=sb.color.teal)",
                "sb.ui.point(_x + dx, _y, 0, color=sb.color.teal, drag=(dx, None, None))",
                "sb.ui.point(_x, _y + dy, 0, color=sb.color.teal, drag=(None, dy, None))",
                ""
            ],
            "uid": 5
        },
        {
            "datums": [
                {
                    "expr": "-r1.width/2+20",
                    "name": "x0",
                    "type": "float",
                    "uid": 0
                },
                {
                    "expr": "0",
                    "name": "y0",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "9.5",
                    "name": "r",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "0",
                    "name": "_a",
                    "type": "float",
                    "uid": 3
                },
                {
                    "expr": "\u0012fab.types.Shape('-r+q-Xf-45qYf9.5',float('-54.500000'),float('-9.500000'),float('-inf'),float('-35.500000'),float('9.500000'),float('inf'))",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 4
                }
            ],
            "inspector": [
                -35.63910414545871,
                -318.96998210185552
            ],
            "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": 1
        },
        {
            "datums": [
                {
                    "expr": "-r1.width/2+20",
                    "name": "x0",
                    "type": "float",
                    "uid": 0
                },
                {
                    "expr": "0",
                    "name": "y0",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "7.5",
                    "name": "r",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "0",
                    "name": "_a",
                    "type": "float",
                    "uid": 3
                },
                {
                    "expr": "\u0012fab.types.Shape('-r+q-Xf-45qYf7.5',float('-52.500000'),float('-7.500000'),float('-inf'),float('-37.500000'),float('7.500000'),float('inf'))",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 4
                }
            ],
            "inspector": [
                -45.395618792840565,
                -510.23947507205816
            ],
            "name": "c1",
            "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": 2
        },
        {
            "datums": [
                {
                    "expr": "\u0011[__2.__4]",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 0
                },
                {
                    "expr": "0",
                    "name": "_x",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "0.0",
                    "name": "_y",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "4",
                    "name": "i",
                    "type": "int",
                    "uid": 3
                },
                {
                    "expr": "1",
                    "name": "j",
                    "type": "int",
                    "uid": 4
                },
                {
                    "expr": "30",
                    "name": "dx",
                    "type": "float",
                    "uid": 5
                },
                {
                    "expr": "1",
                    "name": "dy",
                    "type": "float",
                    "uid": 6
                },
                {
                    "expr": "\u0012fab.types.Shape('m-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf7.5',float('-52.500000'),float('-7.500000'),float('-inf'),float('52.500000'),float('7.500000'),float('inf'))",
                    "name": "array",
                    "type": "_fabtypes.Shape",
                    "uid": 7
                }
            ],
            "inspector": [
                314.55933307629243,
                -596.69407471347017
            ],
            "name": "a1",
            "script": [
                "import fab",
                "",
                "title('Array (2D)')",
                "",
                "input('shape', fab.types.Shape)",
                "input('_x', float)",
                "input('_y', float)",
                "input('i', int)",
                "input('j', int)",
                "input('dx', float)",
                "input('dy', float)",
                "",
                "output('array', fab.shapes.iterate3d(shape, i, j, 1, dx, dy, 0))",
                "",
                "# UI",
                "sb.ui.wireframe([",
                "    (_x + dx, _y, 0), (_x, _y, 0), (_x, _y + dy, 0)], color=sb.color.teal)",
                "sb.ui.wireframe([",
                "    (_x + dx, _y - 0.3, 0), (_x + dx, _y + 0.3, 0)], color=sb.color.teal)",
                "sb.ui.wireframe([",
                "    (_x + 0.3, _y + dy, 0), (_x - 0.3, _y + dy, 0)], color=sb.color.teal)",
                "",
                "sb.ui.point(_x, _y, 0, color=sb.color.teal)",
                "sb.ui.point(_x + dx, _y, 0, color=sb.color.teal, drag=(dx, None, None))",
                "sb.ui.point(_x, _y + dy, 0, color=sb.color.teal, drag=(None, dy, None))",
                ""
            ],
            "uid": 3
        },
        {
            "datums": [
                {
                    "expr": "\u0011[__5.__7]",
                    "name": "a",
                    "type": "_fabtypes.Shape",
                    "uid": 0
                },
                {
                    "expr": "\u0011[__3.__7]",
                    "name": "b",
                    "type": "_fabtypes.Shape",
                    "uid": 1
                },
                {
                    "expr": "\u0012fab.types.Shape('am-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf9.5nm-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf7.5',float('-54.500000'),float('-9.500000'),float('-inf'),float('54.500000'),float('9.500000'),float('inf'))",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 2
                }
            ],
            "inspector": [
                690.67143226920359,
                -431.23561517692269
            ],
            "name": "d0",
            "script": [
                "import fab.types",
                "",
                "title('Difference')",
                "input('a', fab.types.Shape)",
                "input('b', fab.types.Shape)",
                "",
                "output('shape', a & ~b)",
                ""
            ],
            "uid": 4
        },
        {
            "datums": [
                {
                    "expr": "0.0",
                    "name": "_x",
                    "type": "float",
                    "uid": 0
                },
                {
                    "expr": "0.0",
                    "name": "_y",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "0",
                    "name": "zmin",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "5",
                    "name": "zmax",
                    "type": "float",
                    "uid": 3
                },
                {
                    "expr": "\u0011[__8.__5]",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 4
                },
                {
                    "expr": "\u0012fab.types.Shape('am__f1iiiiiaa-f-65X-Xf65a-f-10Y-Yf10aa-f-55X-Xf55a-f-20Y-Yf20-r+q-Xf-55q-Yf-10f10-r+q-Xf-55q-Yf10f10-r+q-Xf55q-Yf-10f10-r+q-Xf55q-Yf10f10a-f0Z-Zf5',float('-65.000000'),float('-20.000000'),float('0.000000'),float('65.000000'),float('20.000000'),float('5.000000'))",
                    "name": "out",
                    "type": "_fabtypes.Shape",
                    "uid": 5
                }
            ],
            "inspector": [
                365.05661584615689,
                47.37390521650412
            ],
            "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": 6
        },
        {
            "datums": [
                {
                    "expr": "0.0",
                    "name": "_x",
                    "type": "float",
                    "uid": 0
                },
                {
                    "expr": "0.0",
                    "name": "_y",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "0",
                    "name": "zmin",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "11",
                    "name": "zmax",
                    "type": "float",
                    "uid": 3
                },
                {
                    "expr": "\u0011[__4.__2]",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 4
                },
                {
                    "expr": "\u0012fab.types.Shape('am__f1am-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf9.5nm-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf7.5a-f0Z-Zf11',float('-54.500000'),float('-9.500000'),float('0.000000'),float('54.500000'),float('9.500000'),float('11.000000'))",
                    "name": "out",
                    "type": "_fabtypes.Shape",
                    "uid": 5
                }
            ],
            "inspector": [
                723.93246515624139,
                -650.21967780906368
            ],
            "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": 7
        },
        {
            "datums": [
                {
                    "expr": "0.0",
                    "name": "x",
                    "type": "float",
                    "uid": 0
                },
                {
                    "expr": "0.0",
                    "name": "y",
                    "type": "float",
                    "uid": 1
                },
                {
                    "expr": "130",
                    "name": "width",
                    "type": "float",
                    "uid": 2
                },
                {
                    "expr": "40",
                    "name": "height",
                    "type": "float",
                    "uid": 3
                },
                {
                    "expr": "0.5",
                    "name": "r",
                    "type": "float",
                    "uid": 4
                },
                {
                    "expr": "\u0012fab.types.Shape('iiiiiaa-f-65X-Xf65a-f-10Y-Yf10aa-f-55X-Xf55a-f-20Y-Yf20-r+q-Xf-55q-Yf-10f10-r+q-Xf-55q-Yf10f10-r+q-Xf55q-Yf-10f10-r+q-Xf55q-Yf10f10',float('-65.000000'),float('-20.000000'),float('-inf'),float('65.000000'),float('20.000000'),float('inf'))",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 5
                }
            ],
            "inspector": [
                -65.145025882845601,
                69.959039231485292
            ],
            "name": "r1",
            "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": 8
        },
        {
            "datums": [
                {
                    "expr": "\u0011[__6.__5,__7.__5]",
                    "name": "shape",
                    "type": "_fabtypes.Shape",
                    "uid": 0
                },
                {
                    "expr": "\u0012fab.types.Shape('iam__f1iiiiiaa-f-65X-Xf65a-f-10Y-Yf10aa-f-55X-Xf55a-f-20Y-Yf20-r+q-Xf-55q-Yf-10f10-r+q-Xf-55q-Yf10f10-r+q-Xf55q-Yf-10f10-r+q-Xf55q-Yf10f10a-f0Z-Zf5am__f1am-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf9.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf9.5nm-Xf0-Yf0-Zf0m-Xf0-Yf0-Zf0iiim-Xf0-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf30-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf60-Yf0-Zf0-r+q-Xf-45qYf7.5m-Xf90-Yf0-Zf0-r+q-Xf-45qYf7.5a-f0Z-Zf11',float('-65.000000'),float('-20.000000'),float('0.000000'),float('65.000000'),float('20.000000'),float('11.000000'))",
                    "name": "out",
                    "type": "_fabtypes.Shape",
                    "uid": 1
                }
            ],
            "inspector": [
                746.01561898097418,
                4.2029048956674604
            ],
            "name": "m0",
            "script": [
                "import fab",
                "",
                "title('Mesh (.stl)')",
                "",
                "input('shape', fab.types.Shape)",
                "output('out', shape)",
                "",
                "sb.export.stl(shape)",
                ""
            ],
            "uid": 0
        }
    ],
    "protocol": 6,
    "type": "sb"
}