/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.xyu1E6MiImy/rev.8 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Easing Box (v2.2) * Author: MsKelly (2016-Oct-04) * Mod: GoToLoop * * forum.Processing.org/two/discussion/18404/ * processing-code-doesn-t-work-in-p5#Item_5 * * studio.SketchPad.cc/sp/pad/view/ro.9XkJm3bjTAxB2/latest */ static final float EASING = .05, LIMIT = .1; static final int RAD = 15, EDGE = 50; static final int INNER = EDGE + RAD; float mx = INNER, my = INNER; int iw, ih, ew, eh; void setup() { size(400, 500); ellipseMode(RADIUS); rectMode(CORNERS); noStroke(); background(0); iw = width - INNER; ih = height - INNER; ew = width - EDGE; eh = height - EDGE; } void draw() { final float dx = mouseX - mx, dy = mouseY - my; if (abs(dx) > LIMIT) mx = constrain(mx + dx*EASING, INNER, iw); if (abs(dy) > LIMIT) my = constrain(my + dy*EASING, INNER, ih); fill(196, 239, 234); rect(EDGE, EDGE, ew, eh); fill(146, 140, 211); ellipse(mx, my, RAD, RAD); }