sba1ÀtÀdÜlp8Ú  __namea1_s 1.7645_s@10.0_c0.22063x0.60728y0.64265_s12.5_s2 0.625_c10.1_c2 -1.25left right__script\$# Dragging Squares example # by Erin RobotGrrl import fab title('Script') width = 5 height = width/2 input('x', float) input('y', float) input('_s1', float) input('_s2', float) input('_c1', float) input('_c2', float) rectangle_left = fab.shapes.rectangle(x-_s1, x, y-_s1/2, y+_s1/2) rectangle_right = fab.shapes.rectangle(x, x+_s2, y-_s2/2, y+_s2/2) def map_nums(val, from_nums, to_nums): return to_nums[0] + (to_nums[1] - to_nums[0]) * ((val - from_nums[0]) / (from_nums[1] - from_nums[0])) val1 = int(map_nums(_c1, [-height/2, height/2], [0, 255])) val2 = int(map_nums(_c2, [-height/2, height/2], [0, 255])) output('left', fab.shapes.set_color(rectangle_left, val1, 0, 200)) output('right', fab.shapes.set_color(rectangle_right, val2, 0, 200)) def drag_middle(this,x,y,z): if x > 0: this._s1 -= x this._s2 += x if y > 0: this._c2 += y elif y < 0: this._c2 -= math.fabs(y) elif x < 0: this._s1 += math.fabs(x) this._s2 -= math.fabs(x) if y > 0: this._c1 += y elif y < 0: this._c1 -= math.fabs(y) if this._s1 < width/8: this._s1 = width/8 elif this._s1 > width/2: this._s1 = width/2 if this._s2 < width/8: this._s2 = width/8 elif this._s2 > width/2: this._s2 = width/2 if this._c1 > height/2: this._c1 = height/2 elif this._c1 < -height/2: this._c1 = -height/2 if this._c2 > height/2: this._c2 = height/2 elif this._c2 < -height/2: this._c2 = -height/2 fab.ui.point(x, y, drag=drag_middle, relative=True, color=(0,255,0)) fab.ui.wireframe([(x-width/2, y-height/2, 0), (x+width/2, y-height/2, 0), (x+width/2, y+height/2, 0), (x-width/2, y+height/2, 0)], close=True, color=fab.color.orange) fab.ui.point(x-width/2, y-height/2, drag=(x,y,None), color=(128,0,128))