Skip to content

Instantly share code, notes, and snippets.

/sc Secret

Created January 11, 2015 19:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8315fcab5fd44685fca4 to your computer and use it in GitHub Desktop.
Save anonymous/8315fcab5fd44685fca4 to your computer and use it in GitHub Desktop.
supercollider language:
```
MyPoint { var <x,<y;
*constraint { |v| v = v.asFloat;
v.inclusivelyBetween(-10,10).if({ ^v }, { Error('Not in [-10,10]').throw }) }
*new { |x=0,y=0|
^super.newCopyArgs(*[x,y] collect: this.constraint(_)) }
x_ { |v| x = this.class.constraint(v) }
y_ { |v| y = this.class.constraint(v) }
asString { ^format("[%,%]", x, y) }
}
```
usage:
```
p = MyPoint(-5,5);
p.x = 4;
p.x_(6).y_(2);
p.y_(51); // boom!
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment