Skip to content

Instantly share code, notes, and snippets.

@modiprabal
Created November 21, 2020 14:31
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 modiprabal/4fe3fee226e40fb4cf8f82940237381e to your computer and use it in GitHub Desktop.
Save modiprabal/4fe3fee226e40fb4cf8f82940237381e to your computer and use it in GitHub Desktop.
import peasy.*;
boolean pcam, record, SubText, RotateScreen, orthographic;
PeasyCam cam;
PFont font;
color c1, c2, c3;
float totalFrameRecord, rotateDegree, rotateSpeed, rotatex, rotatey, frameStep;
void settings(){
System.setProperty("jogl.disable.openglcore", "true");
size(1000, 1000, P3D);
}
float linear(float speed)
{
return (frameCount%speed)/(speed-1);
}
float linear(float speed, float offset)
{
return ((frameCount+offset)%speed)/(speed-1);
}
float triangular(float speed, float offset)
{
float t;
t=((frameCount+offset)%speed)/(speed-1);
if(t<0.5) return 2*t; else return 2*(1-t);
}
float triangular(float speed)
{
float t;
t=((frameCount)%speed)/(speed-1);
if(t<0.5) return 2*t; else return 2*(1-t);
}
void save()
{
if(frameCount%frameStep == 0)
saveFrame("z####.jpg");
if(frameCount == totalFrameRecord) exit();
}
void subText()
{
font = loadFont("CharterBT-BoldItalic-25.vlw");
textFont(font);
textAlign(LEFT, BOTTOM);
push();
fill(255);
text("@modiprabal", -width/2 - 70, height/2 + 70);
pop();
}
void rotateScreen()
{
rotate(radians(rotateDegree));
rotateDegree = (rotateDegree + rotateSpeed)%361;
}
void keyPressed()
{
if(key == 'o') orthographic = !orthographic;
if(key == 't') SubText = !SubText;
if(key == 'r') redraw();
}
//____________________________________________________________________________________________________
OpenSimplexNoise noise;
// Downloaded from https://gist.github.com/Bleuje/fce86ef35b66c4a2b6a469b27163591e
Hexagon[][] hexagons;
boolean[][] falling;
Hexagon one;
int radius;
int tilesx, tilesz;
float yHeight;
void setup()
{
pcam = true;
SubText = true;
orthographic = false;
RotateScreen = false;
rotateDegree=0;
rotateSpeed = 1;
rotatex = 10;
rotatey = 90;
record = true;
totalFrameRecord = 300;
frameStep = 1;
c1 = color(178, 255, 241);
c2 = color(#CEBFFF);
c3 = color(#FFFCB9);
if(pcam) cam = new PeasyCam(this, 0, 0, 0, 1000);
noise = new OpenSimplexNoise(20);
randomSeed(20);
yHeight = -2*height;
radius = 80;
tilesx = ((width + radius - 1)/radius)*2;
tilesz = ((width + radius - 1)/radius);
hexagons = new Hexagon[tilesx][tilesz];
for(int i=0; i<tilesx; i++)
{
for(int j=0; j<tilesz; j++)
{
if((i)%2==0)
hexagons[i][j] = new Hexagon(-width*3/2 - 0*radius + (3*i*radius)/2, yHeight, -2*height - 4*radius + 2*j*radius*cos(PI/6) , radius, 20);
else
hexagons[i][j] = new Hexagon(-width*3/2 - 0*radius + (3*i*radius)/2, yHeight, -2*height - 4*radius + radius*cos(PI/6)*(2*j+1) , radius, 20);
}
}
stroke(100);
}
void draw()
{
background(20);
if(orthographic) ortho(); else perspective();
if(!pcam) translate(width/2, height/2);
if(SubText) subText();
if(RotateScreen) rotateScreen();
// Start draw code _________________
//rotateY(radians(rotatey));
fill(255);
rotateX(radians(rotatex));
translate(0,0,-height);
for(int i=0; i<tilesx; i++)
{
for(int j=0; j<tilesz; j++)
{
//if((i+j)%2==0)
hexagons[i][j].fall();
hexagons[i][j].show();
}
}
// End draw code ______________________
if(record) save();
}
class Hexagon
{
float radius, thickness=30, jump = random(20) + 20, bh = height*3, th = -1.5*height, bhj = 5;
float xpos, ypos, zpos, curoff=10;
boolean fallin = false, reached = false;
Hexagon(float x, float y, float z, float r)
{
xpos = x;
ypos = y;
zpos = z;
radius = r;
}
Hexagon(float x, float y, float z, float r, float w)
{
xpos = x;
ypos = y;
zpos = z;
radius = r;
thickness = w;
th = y;
}
void show()
{
float angle = 0;
for (int v=0; v<6; v++)
{
beginShape();
vertex(xpos + radius*cos(angle), ypos, zpos + radius*sin(angle));
vertex(xpos + radius*cos(angle+PI/3), ypos, zpos + radius*sin(angle+PI/3));
vertex(xpos + radius*cos(angle+PI/3), ypos + thickness, zpos + radius*sin(angle+PI/3));
vertex(xpos + radius*cos(angle), ypos + thickness, zpos + radius*sin(angle));
vertex(xpos + radius*cos(angle), ypos, zpos + radius*sin(angle));
endShape(CLOSE);
angle += (PI/3);
}
beginShape();
for(int v=0; v<6; v++)
{
vertex(xpos + radius*cos(angle), ypos, zpos + radius*sin(angle));
angle += PI/3;
}
endShape();
beginShape();
for(int v=0; v<6; v++)
{
vertex(xpos + radius*cos(angle), ypos + thickness, zpos + radius*sin(angle));
angle += PI/3;
}
endShape();
}
void fall()
{
int fc = 200;
float temp = -height + linear(fc, (float)noise.eval(xpos,zpos) * fc/2)*height/2;
if(!fallin && temp >= -height + 250)
{
fallin = true;
ypos = th;
println(frameCount);
}
if(fallin && !reached)
{
ypos += jump;
jump -= 0.1;
}
if(ypos >= bh)
{
ypos = bh;
reached = true;
}
bh -= bhj;
bhj += 0.09;
if(bh <= th)
{
println(frameCount);
bh = th;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment