Last active
August 22, 2023 22:02
-
-
Save KrabCode/73c1d8d6e0c4dffe28674d551940b4c5 to your computer and use it in GitHub Desktop.
This file contains 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
float minValue = 0; | |
float maxValue = 300; | |
float startValue = 100; | |
float stepLength = 200; | |
float stepValue = 1.5; | |
int stepCount = ceil((maxValue - minValue) / stepValue); | |
float xDrag = 0; | |
float xDragSpd = 0; | |
float xSpdCoeff = 0.9; | |
float lineHeight = 150; | |
float textX = 0; | |
float textSizeBig = 64; | |
float textSizeSmall = 52; | |
int bg, fg, alt; | |
HashMap<String, String> cache = new HashMap<String, String>(); | |
void setup() { | |
orientation(LANDSCAPE); | |
fullScreen(P2D); | |
rectMode(CENTER); | |
bg = color(16); | |
fg = color(255); | |
alt = color(128); | |
xDrag = - ((startValue-minValue) / stepValue) * stepLength; | |
} | |
void mouseDragged() { | |
float d = mouseX - pmouseX; | |
if (abs(d) < 1) { | |
xDragSpd = 0; | |
return; | |
} | |
int sign = d > 0 ? 1 : -1; | |
xDragSpd = max(abs(xDragSpd), abs(d)); | |
xDragSpd *= sign; | |
} | |
void draw() { | |
updateDrag(); | |
background(bg); | |
drawTitle(); | |
textAlign(CENTER, CENTER); | |
translate(0, 200); | |
drawLine("/1", 1, 1); | |
drawLine("/2", 2, 2); | |
drawLine("/4", 4, 2); | |
drawLine("/6", 6, 2); | |
drawLine("/12", 12, 2); | |
} | |
void updateDrag(){ | |
xDrag += xDragSpd; | |
xDrag = constrain(xDrag, -stepCount * stepLength, 0); | |
xDragSpd *= xSpdCoeff; | |
} | |
void drawTitle(){ | |
textAlign(CENTER, CENTER); | |
textSize(textSizeBig); | |
text("relax, enjoy death", width/2, 50); | |
} | |
void drawLine(String label, float divisor, int nfTrail) { | |
float x = 0; | |
float y = 0; | |
pushMatrix(); | |
translate(width/2+xDrag, 0); | |
if(divisor > 1){ | |
textSize(textSizeSmall); | |
} | |
for (float val = minValue; val <= maxValue; val += stepValue) { | |
if (isOnScreen(x+xDrag)) { | |
String cacheKey = val + ":" + divisor; | |
if (!cache.containsKey(cacheKey)) { | |
String cacheValue = nf(val/divisor, 0, nfTrail); | |
cache.put(cacheKey, cacheValue); | |
} | |
String valText = cache.get(cacheKey); | |
fill(fg); | |
text(valText, x+textX, y); | |
noFill(); | |
stroke(alt); | |
rect(x, y, stepLength, lineHeight); | |
} | |
x += stepLength; | |
} | |
popMatrix(); | |
fill(bg); | |
stroke(alt); | |
rect(50, y, stepLength, lineHeight); | |
fill(fg); | |
textSize(textSizeBig); | |
text(label, stepLength*0.33+textX, y); | |
translate(0, lineHeight); | |
} | |
boolean isOnScreen(float screenX) { | |
return(screenX > -width/2-stepLength && | |
screenX < width/2+stepLength); | |
} |
Author
KrabCode
commented
Aug 22, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment