Created
April 25, 2016 13:10
-
-
Save monkstone/c03416694a7097ee646b6543a36886e0 to your computer and use it in GitHub Desktop.
Java8 Lambda with hype
This file contains hidden or 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
package hype; | |
@FunctionalInterface | |
public interface HCallback { | |
public void run(Object obj); | |
} |
This file contains hidden or 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
package hype; | |
import processing.core.*; | |
import hype.extended.colorist.HColorField; | |
import hype.extended.layout.HGridLayout; | |
import hype.extended.behavior.HOscillator; | |
public class HColorFieldExample extends PApplet { | |
HColorField colorField; | |
HDrawablePool pool; | |
int poolCols = 9; | |
int poolRows = 7; | |
int poolDepth = 9; | |
@Override | |
public void setup() { | |
H.init(this); | |
H.background(0xff242424); | |
H.use3D(true); | |
colorField = new HColorField(width, height) | |
.addPoint(-300, 0, 0xffFF0066, 0.6f) | |
.addPoint(width - 300, 0, 0xff3300FF, 0.6f) | |
.fillOnly() // .strokeOnly() | |
// .fillAndStroke() | |
; | |
pool = new HDrawablePool(poolCols * poolRows * poolDepth); | |
pool.autoAddToStage() | |
.add(new HSphere()) | |
.layout(new HGridLayout().startX(-600).startY(-450).startZ(-600).spacing(150, 150, 150).rows(poolRows).cols(poolCols)) | |
.onCreate( | |
(Object obj) -> { | |
int i = pool.currentIndex(); | |
HSphere d = (HSphere) obj; | |
d.size(40).strokeWeight(0).noStroke().fill(0).anchorAt(H.CENTER); | |
new HOscillator().target(d).property(H.SCALE).range(0.25f, 2.5f).speed(0.25f).freq(10).currentStep(i * 3); | |
} | |
) | |
.requestAll(); | |
} | |
@Override | |
public void draw() { | |
for (HDrawable d : pool) { | |
d.fill(0); | |
colorField.applyColor(d); | |
} | |
lights(); | |
sphereDetail(10); | |
pushMatrix(); | |
translate(width / 2, height / 2, -800); | |
rotateY(radians(frameCount / 2)); | |
H.drawStage(); | |
popMatrix(); | |
} | |
@Override | |
public void settings() { | |
size(640, 640, P3D); | |
} | |
static public void main(String[] passedArgs) { | |
String[] appletArgs = new String[]{"hype.HColorFieldExample"}; | |
if (passedArgs != null) { | |
PApplet.main(concat(appletArgs, passedArgs)); | |
} else { | |
PApplet.main(appletArgs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment