Created
December 31, 2019 11:14
-
-
Save hidex7777/825afe26c44e8e8bd2835becbe70679b to your computer and use it in GitHub Desktop.
Salto Mortal for Processing (bug fixed)
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 = 20; | |
int _dotsnum = 90; | |
float _maxr; | |
float _minr; | |
float _minx; | |
float _maxx; | |
float _miny; | |
float _maxy; | |
float _maxz; | |
float _minz; | |
Circle[] _cl = new Circle[_circlesnum]; | |
float[] _ys = new float[_circlesnum]; | |
void setup(){ | |
fullScreen(P3D); | |
pixelDensity(displayDensity()); | |
smooth(); | |
frameRate(60); | |
background(255); | |
_maxr = (height/2) * 0.7; | |
_minr = (height/2) * 0.3; | |
_minx = (width/2) - (height/2) + 50; | |
_maxx = (width/2) + (height/2) - 50; | |
_miny = 0; | |
_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 * 0.5, height * 0.5, height * 0.99, | |
width * 0.5, height * 0.5, 0, | |
0, 1, 0); | |
background(255); | |
translate(width/2, 0, 0); | |
rotateY(frameCount * 0.01); | |
setys(); | |
for(Circle cl: _cl){ | |
cl.updateMe(); | |
cl.drawMe(); | |
} | |
for(int i = 0; i < _dotsnum; i++){ | |
stroke(0); | |
strokeWeight(1); | |
noFill(); | |
beginShape(); | |
curveVertex(_cl[0].dotlocations[i].x, _cl[0].dotlocations[i].y, _cl[0].dotlocations[i].z); | |
for(int j = 0; j < _cl.length; j++){ | |
curveVertex(_cl[j].dotlocations[i].x, _cl[j].dotlocations[i].y, _cl[j].dotlocations[i].z); | |
} | |
curveVertex(_cl[_cl.length - 1].dotlocations[i].x, _cl[_cl.length - 1].dotlocations[i].y, _cl[_cl.length - 1].dotlocations[i].z); | |
endShape(); | |
} | |
} | |
void mouseReleased(){ | |
saveFrame("output/saltomortal3-" + _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の位置 | |
setdots(); | |
for(int j = 0; j < _dotsnum; j++){ | |
PVector dot = new PVector(dottargets[j].x, dottargets[j].y, dottargets[j].z); | |
dotlocations[j] = dot; | |
} | |
} | |
void setdots(){ | |
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); | |
setdots(); | |
} | |
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