/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.y0Y3U43MmTN/rev.33
*
* authors:
* GoToLoop
*
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* Rotating Card (v2.82)
* by Redwire (2013/Oct)
* mod GoToLoop
*
* forum.processing.org/two/discussion/92/displaying-text-in-p3d
* studio.processingtogether.com/sp/pad/export/ro.9oKy5N3D6zFZT/latest
*/
final static float TAU = TWO_PI; // JS
final static float STEP = .01;
final static short FPS = 60, SMOOTH = 8;
PImage front, back;
float angle, dir = 1.;
boolean isPaused;
void setup() {
size(500, 600, P3D);
frameRate(FPS);
smooth();
rectMode(CORNER);
//camera(width - 100, -100, 300, 0, 0, 0, 0, 1, 0);
front = createCard(true);
back = createCard(false);
}
void draw() {
background(-1);
translate(width>>1, height>>2);
rotateY(angle);
//showInfo(); // Java
final boolean bool = angle < HALF_PI
| angle > TAU - HALF_PI;
image(bool? front : back, 0, 0);
if ((angle += STEP*dir) > TAU) angle = 0;
else if (angle < 0) angle = TAU;
}
void mousePressed() {
if (mouseButton != LEFT) dir *= -1.;
else if (isPaused = !isPaused) noLoop();
else loop();
}
void keyPressed() {
mousePressed();
}
/*
void showInfo() { // Java
frame.setTitle("Rotating Card \t\t\t Angle: "
+ nf(angle, 0, 2));
}
*/
PImage createCard(boolean hasText) {
final PGraphics pg = createGraphics(200, 340, P2D);
pg.beginDraw();
pg.smooth();
pg.rectMode(CORNER);
pg.background(0200);
pg.stroke(-1);
pg.textSize(040);
pg.fill(89, 92, 255, 100);
pg.rect(20, 20, 150, 250);
if (hasText) {
pg.fill(#FF0000);
pg.text("Action", 30, 50);
pg.fill(#00FFFF);
pg.text("Hey", pg.width - 100, pg.height - 100);
}
pg.endDraw();
return pg.get();
}