Created
December 13, 2019 21:22
-
-
Save hidex7777/36118656d245249b9f3a6542c2b20096 to your computer and use it in GitHub Desktop.
Salto Mortal for Processing
This file contains 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
//salto mortal | |
int _y = year(); | |
int _mo = month(); | |
int _d = day(); | |
int _h = hour(); | |
int _mi = minute(); | |
int _s = second(); | |
//circles | |
int _circlesnum = 50; | |
int _dotsnum = 20; | |
float _maxr; | |
float _minr = 80.0; | |
float _minx = 0.0; | |
float _maxx; | |
float _miny = 20; | |
float _maxy; | |
float _maxz; | |
float _minz; | |
Circle[] _cl = new Circle[_circlesnum]; | |
float[] _ys = new float[_circlesnum]; | |
void setup(){ | |
//size(1000, 1000, P3D); | |
fullScreen(P3D); | |
pixelDensity(displayDensity()); | |
smooth(); | |
frameRate(60); | |
background(255); | |
_maxr = (height/2) * 0.7; | |
_maxx = height - 50; | |
_maxy = height; | |
_maxz = height/2; | |
_minz = -1 * (height/2); | |
setys(); | |
for(int i = 0; i < _circlesnum; i++){ | |
Circle ccl = new Circle(i); | |
_cl[i] = ccl; | |
} | |
} | |
void draw(){ | |
camera(width/2, height * 0.7, height * 0.99, | |
width/2, height * 0.5, 0, | |
0, 1, 0); | |
background(255); | |
//pushMatrix(); | |
translate(width/2, 0, 0); | |
rotateY(frameCount * 0.01); | |
for(Circle cl: _cl){ | |
cl.updateMe(); | |
cl.drawMe(); | |
} | |
for(int i = 1; i < _cl.length; i++){ | |
for(int j = 0; j < _dotsnum; j++){ | |
stroke(0); | |
strokeWeight(1); | |
line(_cl[i].dotlocations[j].x, _cl[i].dotlocations[j].y, _cl[i].dotlocations[j].z, | |
_cl[i - 1].dotlocations[j].x, _cl[i - 1].dotlocations[j].y, _cl[i - 1].dotlocations[j].z); | |
} | |
} | |
} | |
void mouseReleased(){ | |
saveFrame("output/saltomortal-" + _y + _mo + _d + _h + _mi + _s + "#######.jpg"); | |
} | |
void setys(){ | |
for(int i = 0; i < _circlesnum; i++){ | |
_ys[i] = random(_miny, _maxy); | |
} | |
_ys = sort(_ys); | |
} | |
class Circle{ | |
float myr; | |
PVector mycenter; | |
PVector[] dotlocations = new PVector[_dotsnum]; | |
PVector[] dottargets = new PVector[_dotsnum]; | |
int myorder; | |
Circle(int i){ | |
myorder = i; | |
myr = random(_minr, _maxr); | |
mycenter = new PVector(width/2, _ys[myorder], 0); | |
//dotの位置 | |
dotsset(); | |
for(int j = 0; j < _dotsnum; j++){ | |
PVector dot = new PVector(dottargets[j].x, dottargets[j].y, dottargets[j].z); | |
dotlocations[j] = dot; | |
} | |
} | |
void dotsset(){ | |
setys(); | |
mycenter.y = _ys[myorder]; | |
float[] phis = new float[_dotsnum]; | |
for(int i = 0; i < _dotsnum; i++){ | |
phis[i] = random(0, 360); | |
} | |
phis = sort(phis); | |
for(int j = 0; j < _dotsnum; j++){ | |
float phi = radians(phis[j]); | |
float x = myr * cos(phi); | |
float z = myr * sin(phi); | |
PVector dot = new PVector(x, mycenter.y, z); | |
dottargets[j] = dot; | |
} | |
} | |
void updateMe(){ | |
if(frameCount % 120 == 0){ | |
myr = random(_minr, _maxr); | |
dotsset(); | |
} | |
for(int i = 0; i < _dotsnum; i++){ | |
dotlocations[i].x += (dottargets[i].x - dotlocations[i].x) * 0.05; | |
dotlocations[i].y += (dottargets[i].y - dotlocations[i].y) * 0.05; | |
dotlocations[i].z += (dottargets[i].z - dotlocations[i].z) * 0.05; | |
} | |
} | |
void drawMe(){ | |
for(PVector dot: dotlocations){ | |
stroke(0); | |
strokeWeight(4); | |
point(dot.x, dot.y, dot.z); | |
} | |
for(int i = 0; i < _dotsnum; i++){ | |
stroke(0); | |
strokeWeight(1); | |
if(i == 0){ | |
line(dotlocations[_dotsnum - 1].x, dotlocations[_dotsnum - 1].y, dotlocations[_dotsnum - 1].z, | |
dotlocations[i].x, dotlocations[i].y, dotlocations[i].z); | |
}else{ | |
line(dotlocations[i - 1].x, dotlocations[i - 1].y, dotlocations[i - 1].z, | |
dotlocations[i].x, dotlocations[i].y, dotlocations[i].z); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment