“Rainy Day Loop” by Lexin Yuan
https://openprocessing.org/sketch/589254
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
pls observe how cute it is
CC Attribution ShareAlike
Rainy Day Loop
Yuan
xxxxxxxxxx
// This is a template for creating a looping animation in Processing/Java.
// When you press the 'F' key, this program will export a series of images
// into a "frames" directory located in its sketch folder.
// These can then be combined into an animated gif.
// Known to work with Processing 3.3.6
// Prof. Golan Levin, January 2018
//===================================================
// Global variables.
String myNickname = "nixel";
int nFramesInLoop = 60;
int nElapsedFrames;
boolean bRecording;
Drop[] drops = new Drop[50];
//===================================================
void setup() {
size (640, 640);
bRecording = false;
nElapsedFrames = 0;
for (int i = 0; i < drops.length; i++) {
drops[i] = new Drop();
}
}
//===================================================
void keyPressed() {
if ((key == 'f') || (key == 'F')) {
bRecording = true;
nElapsedFrames = 0;
}
}
//===================================================
void draw() {
// Compute a percentage (0...1) representing where we are in the loop.
float percentCompleteFraction = 0;
if (bRecording) {
percentCompleteFraction = (float) nElapsedFrames / (float)nFramesInLoop;
} else {
percentCompleteFraction = (float) (frameCount % nFramesInLoop) / (float)nFramesInLoop;
}
// Render the design, based on that percentage.
renderMyDesign (percentCompleteFraction);
// If we're recording the output, save the frame to a file.
if (bRecording) {
saveFrame("frames/" + myNickname + "_frame_" + nf(nElapsedFrames, 4) + ".png");
nElapsedFrames++;
if (nElapsedFrames >= nFramesInLoop) {
bRecording = false;
}
}
}
//===================================================
void renderMyDesign (float percent) {
int bgColor = 255;
background (bgColor);
stroke (0, 0, 0);
strokeWeight (2);
float pennerEase = FlatTopWindow(percent);
noStroke();
//umbrella
float umbrellashift = (map(pennerEase, 0, 1, -50, -20));
fill(255, 0, 0);
ellipse(width/2, 240 + umbrellashift, 360, 360);
//cutout umbrella
fill(bgColor);
int r = 250;
for (int i = 0; i < 360; i += 30){
float dy = sin(radians(i)) * r;
float dx = cos(radians(i)) * r;
ellipse(width/2 + dx, 240 + umbrellashift + dy, 180, 180);
}
rectMode(CENTER);
//ground
fill(10, 95, 223);
rect(width/2, 600, width, 200);
//puddle
noFill();
stroke(255);
float jumpWeight = map(percent, 0, 1, 15, 0);
float puddleEase = map(PennerEaseOutExpo(percent-0.7), 0, 1, 100, 1000);
float puddleEaseY = map(PennerEaseOutExpo(percent), 0, 1, 0, 50);
strokeWeight(jumpWeight);
if (percent >= 0.7){
ellipse(355, 530, puddleEase, puddleEaseY);
ellipse(200, 560, puddleEase, puddleEaseY);
ellipse(300, 600, puddleEase, puddleEaseY);
ellipse(50, 650, puddleEase, puddleEaseY);
ellipse(550, 610, puddleEase, puddleEaseY);
}
//hair
noStroke();
float hairshift = (map(pennerEase, 0, 1, 60, -40));
fill(0);
arc(width/2, 240 + hairshift, 180, 300, PI, TWO_PI);
//legs
float rX = map(pennerEase, 0, 1, 350, 340);
float Y = map(pennerEase, 0, 1, 560, 510);
float squishX = map(pennerEase, 0, 1, 10, 0);
float lX = map(pennerEase, 0, 1, width - 360, width - 350);
fill(247,227,40);
//right leg
triangle(rX, Y, rX - 5 - squishX, Y - 150, rX + 10 + squishX, Y - 150);
//left leg
triangle(lX, Y, lX - 5 - squishX, Y - 150, lX + 10 + squishX, Y - 150);
//body
float bsquish = map(pennerEase, 0, 1, 10, -10);
float bodyshift = (map(pennerEase, 0, 1, 50, -20));
fill(247, 227, 40);
triangle(width/2, 170 + bodyshift, width/2 - 100 - bsquish, 380 + bodyshift, width/2 + 100 + bsquish, 380 + bodyshift);
//mirrored legs
float mrX = map(pennerEase, 0, 1, 350, 340);
float mrY = map(pennerEase, 0, 1, 510, 560);
float msquishX = map(pennerEase, 0, 1, 10, 0);
float mlX = map(pennerEase, 0, 1, width - 360, width - 350);
fill(247,227,40);
//right leg
triangle(mrX, mrY + 50, mrX - 5 - msquishX, mrY + 175, mrX + 10 + msquishX, mrY + 175);
//left leg
triangle(mlX, mrY + 50, mlX - 5 - msquishX, mrY + 175, mlX + 10 + msquishX, mrY + 175);
//head
float headshift = (map(pennerEase, 0, 1, 55, -30));
fill(255);
ellipse(width/2, 170 + headshift, 100, 100);
//mouth
float mouthshift = (map(pennerEase, 0, 1, 30, -70));
float mouthY = (map(pennerEase, 0, 1, -5, 10));
fill(255, 0, 0);
ellipse(width/2, 225 + mouthshift, 20, 15 + mouthY);
//bangs
fill(0);
arc(width/2, 150 + hairshift, 100, 100, PI, TWO_PI);
//eyes
float eyeY = (map(pennerEase, 0, 1, 1, 5));
float eyeX = (map(pennerEase, 0, 1, 1, 5));
ellipse(width/2 - 30, 200 + mouthshift, 10 + eyeX, 15 + eyeY);
ellipse(width/2 + 30, 200 + mouthshift, 10 + eyeX, 15 + eyeY);
//arms
fill(247,227,40);
float Ya = map(pennerEase, 0, 1, 10, 80);
//right arm
triangle(345, 230 + bodyshift, 345, 260 + bodyshift, 450, 250 + Ya);
//left arm
triangle(width - 345, 230 + bodyshift, width - 345, 260 + bodyshift, width - 450, 250 + Ya);
//rain
for (int i = 0; i < drops.length; i++){
drops[i].fall();
drops[i].show();
}
}
//===================================================
//rain code refenced from Dan Shiffman's Purple Rain Coding Challenge
class Drop {
float x = random(width);
float y = random(0, height);
float yspeed = 11;
float len = 15;
void fall(){
y += yspeed;
if (y > height) {
y = 0;
yspeed = 11;
}
}
void show(){
stroke(10, 95, 223);
strokeWeight(2);
line(x, y, x, y+len);
}
}
//===================================================
//easing functions from Pattern Master https://github.com/golanlevin/Pattern_Master
float FlatTopWindow (float x) {
// http://en.wikipedia.org/wiki/Window_function
final float a0 = 1.000;
final float a1 = 1.930;
final float a2 = 1.290;
final float a3 = 0.388;
final float a4 = 0.032;
float pix = PI*x;
float y = a0 - a1*cos(2*pix) + a2*cos(4*pix) - a3*cos(6*pix) + a4*cos(8*pix);
y /= (a0 + a1 + a2 + a3 + a4);
return y;
}
float PennerEaseOutExpo(float t) {
return (t==1) ? 1 : (-pow(2, -10 * t) + 1);
}
See More Shortcuts