Skip to content

Instantly share code, notes, and snippets.

@hidex7777
Created December 17, 2019 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidex7777/f0b49b024c147150a17f412fa06961f0 to your computer and use it in GitHub Desktop.
Save hidex7777/f0b49b024c147150a17f412fa06961f0 to your computer and use it in GitHub Desktop.
Salto Mortal for Processing (bug fixed)
//salto mortal
int _y = year();
int _mo = month();
int _d = day();
int _h = hour();
int _mi = minute();
int _s = second();
//circles
int _circlesnum = 40;
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);
for(int i = 0; i < _circlesnum; i++){
_ys[i] = height/2;
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 = 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/saltomortal2-" + _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