Last active
September 30, 2016 13:17
-
-
Save monkstone/5b9faa0aea5860c26610aabf15ee3bb3 to your computer and use it in GitHub Desktop.
Examples Strict normalize sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static public final float map(float value, | |
float start1, float stop1, | |
float start2, float stop2) { | |
float outgoing = | |
start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); | |
String badness = null; | |
if (outgoing != outgoing) { | |
badness = "NaN (not a number)"; | |
} else if (outgoing == Float.NEGATIVE_INFINITY || | |
outgoing == Float.POSITIVE_INFINITY) { | |
badness = "infinity"; | |
} | |
if (badness != null) { | |
final String msg = | |
String.format("map(%s, %s, %s, %s, %s) called, which returns %s", | |
nf(value), nf(start1), nf(stop1), | |
nf(start2), nf(stop2), badness); | |
PGraphics.showWarning(msg); | |
} | |
return outgoing; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def settings | |
size 800, 200 | |
# pixel_density(2) # for HiDpi screens | |
# smooth # see https://processing.org/reference/smooth_.html | |
end | |
def setup | |
sketch_title 'Strict Norm' | |
color_mode(HSB, 1.0) | |
end | |
def draw | |
background 0.3, 1.0, norm_strict(mouse_x, 0, height) | |
fill norm_strict(mouse_x, 0, width), 1.0, 1.0 | |
ellipse(mouse_x, mouse_y, 50, 100) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment