wonderburg7
12/29/2018 - 6:35 PM

GE spinner.pde

Letter letterg, lettere;
PImage img1, img2, img3;
float i = 0;
float j = 0;
float count = 0;
float rotationValue = 40;
float rotationCount = 0;
float rotationTest = 0;
int delay = 10;
int f;
static final color BG = -4;
    
void setup()
{
    size(1000,1000,P3D);
    imageMode(CENTER);
    translate(width/2.0, height/2.0);
    int picheight = height, picwidth = width;
    
    img1 = loadImage("hexagon 2.png");
    img2 = loadImage("ge g.png");
    img3 = loadImage("ge e.png");
    img1.resize(picheight, picwidth);
    img2.resize(picheight, picwidth);
    img3.resize(picheight, picwidth);
    letterg = new Letter(img2, i);
    lettere = new Letter(img3, j);
    
    hint(DISABLE_DEPTH_TEST);

}

void draw(){

background(BG);
image(img1 ,width/2, height/2); 

rotationTest = rotationCount;

if (rotationCount > (rotationValue*2)-delay){
letterg.display();
} else if (count > delay ) {
  f = 1;
letterg.rotateOnceandDisplay();
rotationCount += 1;
} else {
letterg.display();
}


if (rotationCount > rotationValue*2-delay+10) {
lettere.display();
} else if (count > delay) {
  f = 2;
lettere.rotateOnceandDisplay();
 j = j+(PI/rotationValue);

  if (rotationTest == rotationCount){
  rotationCount += 1;
  }
} else {
lettere.display();
}


 i = i+(PI/rotationValue);

count++;

if (rotationCount > 100) {
 rotationCount = 0; 
}

saveTransparentCanvas(BG, "img");

}

void saveTransparentCanvas(final color bg, final String name) {
  final PImage canvas = get(0,0,height,width);
  canvas.format = ARGB;
 
  final color p[] = canvas.pixels, bgt = bg & ~#000000;
  for (int i = 0; i != p.length; ++i)  if (p[i] == bg)  p[i] = bgt;
 
  canvas.updatePixels();
  canvas.save("GE"+frameCount+".png");
}

 

class Letter {
  PImage img;
  float tempj;
  
  Letter(PImage tempi, float tempj) {
   img = tempi;
   i = tempj;
   
  }
  
  void rotateOnceandDisplay() {
  pushMatrix();
  translate(width/2.0, height/2.0);
  if (f == 1) {
     rotateY(i); 
  } else if (f == 2) {
  rotateY(i-1); 
  }
   image(img, 0, 0);
   popMatrix();
  }
  
  void display() {
  image(img, width/2, height/2);
  }
  
  
}