Skip to content

Instantly share code, notes, and snippets.

@echophon
Created January 29, 2015 06:31
Show Gist options
  • Save echophon/f2b8af5c2eb07dbbca3c to your computer and use it in GitHub Desktop.
Save echophon/f2b8af5c2eb07dbbca3c to your computer and use it in GitHub Desktop.
//requires HPolarLayout
import processing.pdf.*;
HDrawablePool pool;
HPolarLayout layout;
HColorPool colors;
boolean paused = false;
boolean record = false;
void setup(){
size(1000,800,P3D);
H.init(this).background(#202020).use3D(true).autoClear(false);
smooth();
colors = new HColorPool(#5C96A8,#7A7AA3,#8B6AAA,#553066,#CE19C9,#83106C,#A12465,#D1246C);
layout = new HPolarLayout(0.8, 4.3, width / 2, height / 2, false, 0.01);
pool = new HDrawablePool( 50 );
pool.autoAddToStage()
.add ( new HPath() )
.onCreate (
new HCallback() {
public void run(Object obj) {
int i = pool.currentIndex();
HPath d = (HPath) obj;
d
.polygon( 3 )
.size(50,50)
.strokeWeight(1)
.stroke( colors.getColor(i*100) )
.fill( #181818 )
.anchor(25,-100)
;
layout.applyLayout(d);
new HOscillator()
.target(d)
.property(H.SCALE)
.range(0.25, 1.25)
.speed(0.3)
.freq(2)
.currentStep( i )
;
new HOscillator()
.target(d)
.property(H.ROTATION)
.range(-360, 360)
.speed(0.15)
.freq(1)
.currentStep( i )
;
new HOscillator()
.target(d)
.property(H.ROTATIONX)
.range(270, 360)
.speed(0.5)
.freq(2)
.currentStep( i )
;
new HOscillator()
.target(d)
.property(H.ROTATIONY)
.range(270, 360)
.speed(0.7)
.freq(1)
.currentStep( i )
;
new HOscillator()
.target(d)
.property(H.Z)
.range(-900, 100)
.speed(0.5)
.freq(1)
.currentStep( i )
;
}
}
)
.requestAll()
;
}
void draw(){
H.drawStage();
}
// pause, restart, advance 1 / with key presses
// spacebar = pause and restart animation
// + = redraw() advances 1 iteration in the animation
// r = render to PDF
// c = recolor and redraw() advances 1 iteration in the animation
void keyPressed() {
if (key == ' ') {
if (paused) {
loop();
paused = false;
} else {
noLoop();
paused = true;
}
}
if (key == '+') {
redraw();
}
if (key == 'p') {
savePNG();
}
if (key == 'r') {
record = true;
saveVector();
}
}
void saveVector() {
PGraphics tmp = null;
tmp = beginRecord(PDF, "render_#####.pdf");
if (tmp == null) {
H.drawStage();
} else {
H.stage().paintAll(tmp, false, 1); // PGraphics, uses3D, alpha
}
endRecord();
}
void savePNG() {
saveFrame("render_#####.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment