-
Couldn't load subscription status.
- Fork 0
Add Grotto sketch #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SThor
wants to merge
4
commits into
main
Choose a base branch
from
dev/grotto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import yash.oklab.*; | ||
|
|
||
| // Configuration parameters | ||
| final int WIDTH = 1000; | ||
| final int HEIGHT = 1000; | ||
| final float NOISE_SCALE = 0.5; | ||
| final float NOISE_AMPLITUDE = 100; | ||
| final int BASE_RADIUS = 130; | ||
| final int PARTICLES_PER_FRAME = 10000; | ||
| final float SPRAY_RADIUS = 2; | ||
| final int RIDGES = 3; | ||
| final int centerX = WIDTH / 2; | ||
| final int centerY = HEIGHT / 2; | ||
| final int BACKGROUND = 0; | ||
|
|
||
| // Global variables | ||
| String finalImagePath = null; | ||
| float m_noiseOffset = 0; | ||
| float m_hue = 0; | ||
| int m_fillColor = 0; | ||
|
|
||
| void settings() { | ||
| size(WIDTH, HEIGHT, P2D); | ||
| smooth(8); | ||
| } | ||
|
|
||
| void setup() { | ||
| colorMode(RGB, 255, 255, 255); | ||
| noiseDetail(4, 0.5); | ||
| Ok.p = this; | ||
| resetSketch(); | ||
| } | ||
|
|
||
| float noisyRadius(float baseRadius, float angle, float noiseOffset) { | ||
| // Convert angle to polar coordinates relative to center | ||
| float xoff = cos(angle) + 1; | ||
| float yoff = sin(angle) + 1; | ||
|
|
||
| // Calculate the noisy radius at this angle | ||
| return baseRadius + map(noise(xoff * NOISE_SCALE, yoff * NOISE_SCALE, noiseOffset), 0, 1, -NOISE_AMPLITUDE, NOISE_AMPLITUDE); | ||
| } | ||
|
|
||
| boolean insideRadius(float x, float y, float radius) { | ||
| // Check if the point (x, y) is outside the radius | ||
| float dist = dist(x, y, centerX, centerY); | ||
| return dist < radius; | ||
| } | ||
|
|
||
| void drawRidge(float radius, float noiseOffset) { | ||
| loadPixels(); | ||
| for (int x = 0; x < width; x++) { | ||
| for (int y = 0; y < height; y++) { | ||
| float dx = x - centerX; | ||
| float dy = y - centerY; | ||
|
|
||
|
|
||
| float angle = atan2(dy, dx); | ||
| float dist = sqrt(dx*dx + dy*dy); | ||
|
|
||
| float noisyRadius = noisyRadius(radius, angle, noiseOffset); | ||
| float distFromBoundary = abs(dist - noisyRadius); | ||
|
|
||
| if (insideRadius(x, y, noisyRadius)) { | ||
| continue; | ||
| } | ||
|
|
||
| // Create smooth falloff | ||
| float intensity = constrain(map(distFromBoundary, 0, 2*NOISE_AMPLITUDE, 1, 0), 0, 1); | ||
| //intensity = intensity * intensity; // Square for smoother falloff | ||
|
|
||
| int loc = x + y * width; | ||
| pixels[loc] = lerpColor(BACKGROUND, m_fillColor, intensity * 0.4); | ||
| } | ||
| } | ||
| updatePixels(); | ||
| for (int i = 0; i < PARTICLES_PER_FRAME;) { | ||
| // Focus particles around the circle boundary for efficiency | ||
| float angle = random(TWO_PI); | ||
| float noisyRadius = noisyRadius(radius, angle, noiseOffset); | ||
| float finalRadius = noisyRadius + randomGaussian() * NOISE_AMPLITUDE * 0.5; | ||
| float rx = centerX + cos(angle) * finalRadius; | ||
| float ry = centerY + sin(angle) * finalRadius; | ||
| if (insideRadius(rx, ry, noisyRadius)) { | ||
| continue; | ||
| } | ||
| circle(rx + randomGaussian() * SPRAY_RADIUS, | ||
| ry + randomGaussian() * SPRAY_RADIUS, | ||
| random(2, 3)); | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
| void draw() { | ||
| // Draw background with low opacity to create a fading effect | ||
| fill(BACKGROUND); | ||
| rect(0, 0, width, height); | ||
| // Draw particles | ||
| noStroke(); | ||
|
|
||
| for (int i = 0; i < RIDGES; i++) { | ||
| // H = Hue (0-360), S = Saturation (0-100), V = Value (0-100), L = Lightness (0-100) (unused here), A = Alpha (0-100). | ||
| // Set the fill color using the Ok.HSV function, which converts HSV values to a color | ||
| m_fillColor = Ok.HSV( | ||
| m_hue, // Hue: the base hue value, which is randomized in resetSketch() | ||
| 80, // ((float)i + 1.0f / (float)RIDGES) * 100.0f, // Saturation: increases with each ridge, creating a gradient effect | ||
| ((float)i + 1.0f / (float)RIDGES) * 100.0f, // Brightness: also increases with each ridge for a similar gradient effect | ||
| 30 // Alpha: transparency level, set to 30 for a subtle blending effect | ||
| ); | ||
| fill(m_fillColor); | ||
| drawRidge(BASE_RADIUS + 100 * i, m_noiseOffset + 10 * i); | ||
| } | ||
|
|
||
| m_noiseOffset += 0.05; | ||
| } | ||
|
|
||
| void keyPressed() { | ||
| if (key == 's' || key == 'S') { | ||
| saveImage(); | ||
| } else if (key == ENTER || key == '\n') { | ||
| resetSketch(); | ||
| } | ||
| } | ||
|
|
||
| void saveImage() { | ||
| String filename = year() + "-" + month() + "-" + day() + "-" + hour() + "-" + minute() + "-" + second() + ".png"; | ||
| if (finalImagePath != null) { | ||
| // Copy the temporary file to the new filename | ||
| File source = new File(sketchPath(finalImagePath)); | ||
| File dest = new File(sketchPath(filename)); | ||
| try { | ||
| java.nio.file.Files.copy(source.toPath(), dest.toPath()); | ||
| } catch (IOException e) { | ||
| println("Error saving file: " + e.getMessage()); | ||
| } | ||
| } else { | ||
| save(filename); | ||
| } | ||
| } | ||
|
|
||
| void resetSketch() { | ||
| background(0); | ||
| frameCount = 0; | ||
| finalImagePath = null; | ||
| m_hue = random(360.0f); | ||
| loop(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Grotto | ||
|
|
||
| Inspired by Jean-Marie Chupin. |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider capitalizing the first word for consistency with other task entries, e.g., 'Try reversing the drawing process...'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope it's fine, this file doesn't need to be perfect, it's simply a quick todolist