Sam Pottingers development version of processing supports lambda syntax in processing ide.
import hype.*;
HDrawablePool pool;
void setup() {
size(640, 640);
H.init(this);
H.background(#242424);
pool = new HDrawablePool(100);
pool.autoAddToStage()
.add(new HRect(50))
.onCreate(
((Object obj) -> {
HDrawable d = (HDrawable) obj;
d
.strokeWeight(1)
.stroke(#999999)
.fill(#202020)
.loc((int) random(width), (int) random(height));
}
)
)
.requestAll();
H.drawStage();
noLoop();
}
void draw() {
}
Of course we’ve been able to do that sort of stuff in JRubyArt for ages (and it looks a lot more elegant)
3 Likes
Here is a more complicated example:-
import hype.H;
import hype.HCanvas;
import hype.HDrawable;
import hype.HDrawablePool;
import hype.HRect;
import hype.extended.behavior.HOscillator;
import hype.extended.behavior.HTimer;
import hype.extended.colorist.HPixelColorist;
HDrawablePool pool;
HPixelColorist colors;
HCanvas canvas;
void setup() {
H.init(this);
H.background(0xff000000);
H.use3D(true);
colors = new HPixelColorist("gradient.jpg");
canvas = new HCanvas(P3D).autoClear(true);
H.add(canvas);
pool = new HDrawablePool(1000);
pool.autoParent(canvas)
.add(new HRect().rounding(10))
.onCreate((Object obj) -> {
int i = pool.currentIndex();
HDrawable d = (HDrawable) obj;
d.noStroke()
.size((int) random(40, 80), (int) random(60, 80))
.loc((int) random(width), (int) random(height))
.anchorAt(H.CENTER)
.obj("xo", new HOscillator()
.target(d)
.property(H.X)
.relativeVal(d.x())
.range(-(int) random(5, 10), (int) random(5, 10))
.speed(random(.005f, .2f))
.freq(10)
.currentStep(i)
)
.obj("ao", new HOscillator()
.target(d)
.property(H.ALPHA)
.range(50, 255)
.speed(random(.3f, .9f))
.freq(5)
.currentStep(i)
)
.obj("wo", new HOscillator()
.target(d)
.property(H.WIDTH)
.range(-d.width(), d.width())
.speed(random(.05f, .2f))
.freq(10)
.currentStep(i)
)
.obj("ro", new HOscillator()
.target(d)
.property(H.ROTATION)
.range(-180, 180)
.speed(random(.005f, .05f))
.freq(10)
.currentStep(i)
)
.obj("zo", new HOscillator()
.target(d)
.property(H.Z)
.range(-400, 400)
.speed(random(.005f, .01f))
.freq(15)
.currentStep(i * 5)
);
}
)
.onRequest((Object obj) -> {
HDrawable d = (HDrawable) obj;
d.scale(1).alpha(0).loc((int) random(width), (int) random(height), -(int) random(200));
HOscillator xo = (HOscillator) d.obj("xo");
xo.register();
HOscillator ao = (HOscillator) d.obj("ao");
ao.register();
HOscillator wo = (HOscillator) d.obj("wo");
wo.register();
HOscillator ro = (HOscillator) d.obj("ro");
ro.register();
HOscillator zo = (HOscillator) d.obj("zo");
zo.register();
}
)
.onRelease((Object obj) -> {
HDrawable d = (HDrawable) obj;
HOscillator xo = (HOscillator) d.obj("xo");
xo.unregister();
HOscillator ao = (HOscillator) d.obj("ao");
ao.unregister();
HOscillator wo = (HOscillator) d.obj("wo");
wo.unregister();
HOscillator ro = (HOscillator) d.obj("ro");
ro.unregister();
HOscillator zo = (HOscillator) d.obj("zo");
zo.unregister();
}
);
new HTimer(50)
.callback((Object obj) -> {
pool.request();
}
);
}
void draw() {
for (HDrawable d : pool) {
d.loc(d.x(), d.y() - random(0.25f, 1), d.z());
d.noStroke();
d.fill(colors.getColor(d.x(), d.y()));
if (d.z() > -10 && d.z() < 10) {
d.fill(0xffFFFFCC); // if the z axis hits this range, change fill to light yellow
}
if (d.y() < -40) {
pool.release(d);
}
}
H.drawStage();
}
void settings() {
size(640, 640, P3D);
}
Here’s the write up on my JRubyArt blog
1 Like
kll
August 30, 2019, 3:28am
3
the intro you did
Sam Pottinger has done an amazing job in updating processing, not only to update to OpenJDK11, but also to support java 8 syntax in the processing ide. I’m sure he would welcome your support. Here is an example using lambda syntax in the processing ide.
[lambda]
interface MyFunction {
float calculate(float x);
}
float[] values = new float[2];
void setup() {
// lambda expression to define the calculate method
MyFunction doubling = (float x)->x * 2;
values[0] = doubling.calculate(5);
…
was good for understand the basics
here testing the second example, get
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.jogamp.common.os.NativeLibrary$3 (file:/C:/Users/ZEN%202/Documents/processing-3.5.3_SAM/core/library/gluegen-rt.jar) to method java.lang.ClassLoader.findLibrary(java.lang.String)
WARNING: Please consider reporting this to the maintainers of com.jogamp.common.os.NativeLibrary$3
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
The file "gradient.jpg" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
but it RUNs using WIN 10
/ Processing ( Sam Pottinger 0270 ) / HYPE ( 2.1.0 )
can we have the missing picture pls?
1 Like
Here’s gradient.jpg|500x500 example from JRubyArt-examples the original supplied by Joshua Davis hype library. Here is snapshot of running sketch:-
2 Likes