Last active
December 13, 2023 15:59
-
-
Save KrabCode/ecc03a279d4a54cb6ced88ec62e39357 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
import com.krab.lazy.*; | |
LazyGui gui; | |
void setup() { | |
size(1200, 800, P3D); | |
smooth(8); | |
gui = new LazyGui(this); | |
} | |
void draw() { | |
drawBackground(); | |
drawForegroundShape(); | |
drawForegroundText(); | |
} | |
void drawForegroundShape() { | |
// go into a new "shape" folder nested inside the current folder | |
gui.pushFolder("shape"); | |
// get various values from the GUI using a unique path and an optional default value parameter | |
PVector pos = gui.plotXY("position"); | |
float rotationAngle = gui.slider("rotation"); | |
// enforce a minimum and maximum value on sliders with the min/max parameters (-10, 10) here | |
float rotateDelta = gui.slider("rotation ++", 0.1, -10, 10); | |
// change GUI values from code | |
gui.sliderSet("rotation", rotationAngle + rotateDelta); | |
fill(gui.colorPicker("fill", color(0xFF000000)).hex); | |
// plug GUI values directly into where they get consumed | |
stroke(gui.colorPicker("stroke", 0xFFF6F6F6).hex); | |
strokeWeight(gui.slider("stroke weight", 1)); | |
if (gui.toggle("no stroke")) { | |
noStroke(); | |
} | |
rectMode(CENTER); | |
pushMatrix(); | |
translate(width/2f, height/2f); | |
translate(pos.x, pos.y); | |
rotate(radians(rotationAngle)); | |
drawCog(); | |
popMatrix(); | |
// go up one level into the root folder | |
gui.popFolder(); | |
} | |
void drawCog(){ | |
int vertexCount = gui.sliderInt("vertex count", 64); | |
float innerRadius = gui.slider("inner radius", 107); | |
float outerRadius = gui.slider("outer radius", 262); | |
int cogFreq = gui.sliderInt("cog freq", 6); | |
float cogAngle = gui.slider("cog angle", 5.5); | |
beginShape(TRIANGLE_STRIP); | |
for(int i = 0; i < vertexCount; i++){ | |
float theta = map(i, 0, vertexCount-1, 0, TAU); | |
float cogWave = cos(theta*cogFreq); | |
cogWave = 0.5+0.5*constrain(cogWave*cogAngle, 0, 1); | |
float outerRadiusWithCog = lerp(innerRadius,outerRadius, cogWave); | |
vertex(innerRadius*cos(theta), innerRadius*sin(theta)); | |
vertex(outerRadiusWithCog*cos(theta), outerRadiusWithCog*sin(theta)); | |
} | |
endShape(); | |
} | |
void drawForegroundText() { | |
// pushFolder() and popFolder() is not the only way to control folder placement | |
// we can use forward slash separators '/' to achieve the same effect | |
String labelText = gui.text("text/content", "the machine yearns for your touch"); | |
int textSize = gui.sliderInt("text/size", 64); | |
PVector pos = gui.plotXY("text/pos", width*0.1, height*0.9); | |
fill(gui.colorPicker("text/fill", color(255)).hex); | |
textSize(textSize); | |
text(labelText, pos.x, pos.y); | |
} | |
void drawBackground() { | |
gui.pushFolder("background"); | |
// the controls are ordered on screen by which gets called first | |
// so it can be better to ask for all the values before any if-statement branching | |
// because this way you can enforce any given ordering of them in the GUI | |
// and avoid control elements appearing suddenly at runtime at unexpected places | |
int solidBackgroundColor = gui.colorPicker("solid", color(0xFF252525)).hex; | |
PGraphics gradient = gui.gradient("gradient"); | |
boolean useGradient = gui.toggle("solid\\/gradient"); // here '\\' escapes the '/' path separator | |
if (useGradient) { | |
image(gradient, 0, 0); | |
} else { | |
background(solidBackgroundColor); | |
} | |
gui.popFolder(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment