A creative coding animation of the shapes in polar coordinates
Description of how to make this creative coding animation.
It's a creative coding animation made with the 'Processing'. It draws some shapes that are calculated in polar coordinates.
I used to do not use global variables in my code. But I tried to use global variables to make an animation this time on a whim.
It calculates some wave shape with this code.
float fX = width * iRatio;
float fY = height * (0.5 + 0.4 * waveCalc(iRatio, radians));
Then, it translates the wave shape into polar coordinates.
float x = fY * cos(fX) * 0.5;
float y = fY * sin(fX) * 0.5;
I used beginShape() to draw.
'Processing' example code.
Please feel free to use this example code under the terms of the GPL. To see other works based on my code is my pleasure. And my honor.
/**
* Twist in the Dark.
* trying to use global variables to make an animation.
*
* Processing 3.5.3
* @author @deconbatch
* @version 0.1
* created 0.1 2020.06.27
*/
int frmMax = 24 * 3;
int ptnMax = 6;
int initPlot = floor(random(100));
float initHue = random(360.0);
float initRad = 0.0;
public void setup() {
size(720, 720);
colorMode(HSB, 360, 100, 100, 100);
rectMode(CENTER);
smooth();
frameRate(24);
}
public void draw() {
int frmCnt = frameCount - 1; // because of frameCount start from 1
if (frmCnt >= frmMax * ptnMax - 1) {
exit();
}
if (frmCnt % frmMax == 0) {
resetPtn();
}
// moving factor
float radians = initRad + easeInOutCosine(map(frmCnt % frmMax, 0, frmMax, 0.0, 1.0)) * TWO_PI * 2;
translate(width * 0.5, height * 0.5);
background(initHue % 360.0, 40.0, 90.0, 100.0);
strokeWeight(3.0);
stroke(initHue % 360.0, 40.0, 90.0, 100.0);
fill((initHue + 90) % 360.0, 90, 10, 100);
// draw shapes
beginShape(TRIANGLE_FAN);
vertex(0.0, 0.0);
int plotNum = initPlot + 120;
for (int i = 0; i < plotNum; i++) {
float iRatio = map(i, 0, plotNum, 0.0, 1.0);
float fX = width * iRatio;
float fY = height * (0.5 + 0.4 * waveCalc(iRatio, radians));
// translate wave shape into polar coordinates
float x = fY * cos(fX) * 0.5;
float y = fY * sin(fX) * 0.5;
vertex(x, y);
}
vertex(0.0, 0.0);
endShape(CLOSE);
// draw casing
casing();
}
/**
* waveCalc calculate the wave shape.
* @param _ratio : any value.
* @param _rad : any value.
* @return float -1.0 - 1.0 : calculated value.
*/
public float waveCalc(float _ratio, float _rad) {
return cos(_ratio * _rad) * sin(_ratio + _rad * 0.5);
}
/**
* resetPtn reset pattern parameters (global variables).
*/
public void resetPtn() {
initPlot += 39; //
initPlot %= 100;
initHue += 90.0;
initRad = random(-TWO_PI, TWO_PI) * 2.0;
}
/**
* casing : draw fancy casing
*/
public void casing() {
fill(0.0, 0.0, 0.0, 0.0);
strokeWeight(26.0);
stroke(0.0, 0.0, 0.0, 100.0);
rect(0.0, 0.0, width, height);
strokeWeight(20.0);
stroke(0.0, 0.0, 100.0, 100.0);
rect(0.0, 0.0, width, height);
}
/**
* easeInOutCosine easing function.
* @param _t 0.0 - 1.0 : linear value.
* @return float 0.0 - 1.0 : eased value.
*/
public float easeInOutCosine(float _t) {
return 0.5 - cos(PI * _t) * 0.5;
}
/*
Copyright (C) 2020- deconbatch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/