Created
December 13, 2019 21:19
-
-
Save hidex7777/8670756540b02d9dd991afccf2dfd6b6 to your computer and use it in GitHub Desktop.
Pharmakon 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
//date | |
int _y = year(); | |
int _mo = month(); | |
int _d = day(); | |
int _h = hour(); | |
int _mi = minute(); | |
int _s = second(); | |
//cube | |
ArrayList<Cube> _cube = new ArrayList<Cube>(); | |
int _meshalph = 0; | |
int _mesh = 50; | |
//Earth | |
Earth _earth; | |
int _earthsize = 700; | |
int _earthdots = 80; | |
float _earthdotsdist = 0; | |
void setup(){ | |
size(1000, 1000, P3D); | |
pixelDensity(displayDensity()); | |
smooth(); | |
frameRate(60); | |
_earth = new Earth(width/2, height/2, height*-1/2); | |
for(float z = height/_mesh * -0.5; z < height/_mesh * 0.5; z++){ | |
for(float y = height/_mesh * -0.5; y < height/_mesh * 0.5; y++){ | |
for(float x = width/_mesh * -0.5; x < width/_mesh * 0.5; x++){ | |
float myx = x * _mesh + _mesh * 0.5; | |
float myy = y * _mesh + _mesh * 0.5; | |
float myz = (z * _mesh + _mesh * 0.5) * -1; | |
_cube.add(new Cube(myx, myy, myz)); | |
} | |
} | |
} | |
} | |
void draw(){ | |
camera(width/2, height/2 * 2.5, width, width/2, height/2, 0, 0, 1.0, 0); | |
background(255); | |
pushMatrix(); | |
translate(width/2, height/2, 0); | |
rotateY(frameCount * 0.02); | |
_earth.updateMe(); | |
_earth.drawMe(); | |
for(Cube cb: _cube){ | |
cb.updateMe(); | |
cb.drawMe(); | |
} | |
popMatrix(); | |
} | |
void mouseReleased(){ | |
saveFrame("output/pharmakon" + _y + _mo + _d + _h + _mi + _s + "#######.jpg"); | |
} | |
class Cube{ | |
PVector location; | |
float mya; | |
int myc; | |
boolean crash; | |
Cube(float x, float y, float z){ | |
location = new PVector(x, y, z); | |
myc = 0; | |
mya = 255; | |
crash = false; | |
} | |
void updateMe(){ | |
for(int i = 0; i < _earthdots; i++){ | |
float d = location.dist(_earth.mydots[i][1]); | |
if(d < _mesh){ | |
crash = true; | |
} | |
} | |
} | |
void drawMe(){ | |
if(crash){ | |
pushMatrix(); | |
translate(location.x, location.y, location.z); | |
noFill(); | |
stroke(myc, mya); | |
strokeWeight(2); | |
box(_mesh); | |
popMatrix(); | |
crash = false; | |
} | |
} | |
} | |
class Earth{ | |
float myr, myalpha; | |
PVector center; | |
PVector[][] mydots = new PVector[_earthdots][2]; | |
PVector[][] target = new PVector[_earthdots][2]; | |
Earth(float x, float y, float z){ | |
myr = _earthsize; | |
center = new PVector(x, y, z); | |
myalpha = 255; | |
for(int i = 0; i < _earthdots; i++){ | |
float phi = random(TWO_PI); | |
float unitZ = random(-1, 1); | |
mydots[i][0] = new PVector(phi, unitZ); | |
float x2 = myr * sqrt(1 - mydots[i][0].y * mydots[i][0].y) * cos(mydots[i][0].x); | |
float y2 = myr * sqrt(1 - mydots[i][0].y * mydots[i][0].y) * sin(mydots[i][0].x); | |
float z2 = myr * mydots[i][0].y; | |
mydots[i][1] = new PVector(x2, y2, z2); | |
} | |
setTarget(); | |
} | |
void setTarget(){ | |
for(int i = 0; i < _earthdots; i++){ | |
float phi = random(TWO_PI); | |
float unitZ = random(-1, 1); | |
target[i][0] = new PVector(phi, unitZ); | |
float x = myr * sqrt(1 - target[i][0].y * target[i][0].y) * cos(target[i][0].x); | |
float y = myr * sqrt(1 - target[i][0].y * target[i][0].y) * sin(target[i][0].x); | |
float z = myr * target[i][0].y; | |
target[i][1] = new PVector(x, y, z); | |
} | |
} | |
void updateMe(){ | |
if(frameCount % 120 == 0){ | |
setTarget(); | |
} | |
for(int i = 0; i < mydots.length; i++){ | |
mydots[i][1].x += (target[i][1].x - mydots[i][1].x) * 0.05; | |
mydots[i][1].y += (target[i][1].y - mydots[i][1].y) * 0.05; | |
mydots[i][1].z += (target[i][1].z - mydots[i][1].z) * 0.05; | |
} | |
} | |
void drawMe(){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment