/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.l55rZ28MHmC/rev.12 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Perlin Egg (v2.43) * 2013/Mar/30 * forum.processing.org/one/topic/how-to-make-perlin-noise-loop * forum.processing.org/one/topic/ * how-do-i-add-another-same-circle-but-smaller-inside-this * * studio.processingtogether.com/sp/pad/export/ro.9DrxZ3Xdrd4eI/latest */ final static byte NUM_CIRCLES = 2; final static PerlinCircle[] circles = new PerlinCircle[NUM_CIRCLES]; final static color BG = -1; final static short FPS = 40, BOLD = 3; final static String RENDERER = JAVA2D; // JAVA2D or P2D void setup() { size(600, 500, RENDERER); frameRate(FPS); smooth(4); ellipseMode(CENTER); strokeWeight(BOLD); final int CenterX = width >> 1, CenterY = height >> 1; circles[0] = new PerlinCircle(CenterX, CenterY, width/5, height/3, #204080); circles[1] = new PerlinCircle(CenterX, CenterY, width/10, height/5, #F04020); } void draw() { background(BG); for (final PerlinCircle pc: circles) pc.render(); } final class PerlinCircle { final static short SEGMENTS = 50; final static float NUM_ANGLES = TWO_PI/SEGMENTS; final static float NOISE_SCALE = .5; final static float TIME_SCALE = .01; final static short TIME_DIFF = 1000; float dx, dy; final float TIME_UNIQUE = random(TIME_DIFF); final short X, Y; final short MIN_RAD, MAX_RAD; final color FG; PerlinCircle(int xx, int yy, int minSize, int maxSize, color c) { X = (short) xx; Y = (short) yy; MIN_RAD = (short) minSize; MAX_RAD = (short) maxSize; FG = c; } void render() { translate(X, Y); stroke(FG); findNextCoords(0); float px = dx, py = dy; int i = 0; while (i++ != SEGMENTS) { findNextCoords(i); line(px, py, px = dx, py = dy); } resetMatrix(); } void findNextCoords(final int seg) { final float angle = NUM_ANGLES*seg; final float cosAngle = cos(angle); final float sinAngle = sin(angle); final float time = TIME_SCALE*frameCount + TIME_UNIQUE; final float noiseValue = noise( NOISE_SCALE*cosAngle + NOISE_SCALE, NOISE_SCALE*sinAngle + NOISE_SCALE, time); final float rad = MAX_RAD*noiseValue + MIN_RAD; dx = rad*cosAngle; dy = rad*sinAngle; } }