Created
September 29, 2014 05:56
-
-
Save yoggy/266a6564a09970245d09 to your computer and use it in GitHub Desktop.
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
| // | |
| // ordinal indicator sample | |
| // see also... http://en.wikipedia.org/wiki/Ordinal_indicator#English | |
| // | |
| String getOrdinalIndicatorStr(int num) { | |
| String result; | |
| int d1 = num % 10; | |
| int d2 = num % 100; | |
| if (d2 == 11 || d2 == 12 || d2 == 13) { | |
| // all the "teen" numbers ending with 11 | |
| result = "th"; | |
| } | |
| else if (d1 == 1) { | |
| result = "st"; | |
| } | |
| else if (d1 == 2) { | |
| result = "nd"; | |
| } | |
| else if (d1 == 3) { | |
| result = "rd"; | |
| } | |
| else { | |
| result = "th"; | |
| } | |
| return result; | |
| } | |
| import controlP5.*; | |
| ControlP5 cp5; | |
| Slider slider; | |
| PFont pfont_l, pfont_s; | |
| void setup() { | |
| size(320, 160); | |
| cp5 = new ControlP5(this); | |
| slider = cp5.addSlider("sliderValue") | |
| .setPosition(10, 130) | |
| .setSize(300, 20) | |
| .setRange(1, 300) | |
| .setValue(100); | |
| pfont_l = createFont("Arial", 128); | |
| pfont_s = createFont("Arial", 64); | |
| } | |
| void draw() { | |
| background(255); | |
| fill(0); | |
| int num = (int)slider.getValue(); | |
| String ordinal_indicator_str = getOrdinalIndicatorStr(num); | |
| textAlign(RIGHT); | |
| textFont(pfont_l); | |
| text("" + num, 230, 110); | |
| textAlign(LEFT); | |
| textFont(pfont_s); | |
| text(ordinal_indicator_str, 235, 110); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment