# Using lambda form with hype processing

**URL:** <https://discourse.processing.org/t/using-lambda-form-with-hype-processing/13687>\
**Category:** Gallery\
**Created:** [August 29, 2019, 2:04pm UTC](https://discourse.processing.org/t/using-lambda-form-with-hype-processing/13687 "2019-08-29T14:04:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [August 29, 2019, 2:04pm UTC](https://discourse.processing.org/t/using-lambda-form-with-hype-processing/13687/1 "2019-08-29T14:04:18Z")

</div>

Sam Pottingers development version of [processing](https://www.datadrivenempathy.com/processing) supports lambda syntax in processing ide.

```java
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() {
}

```

 ![lamba](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8da2359460f7f85c76eb7bc510192ecdd3aeb263.png)

Of course we’ve been able to do that sort of stuff in [JRubyArt](https://monkstone.github.io/jruby_art/update/2016/04/20/hype_advanced.html) for ages (and it looks a lot more elegant)

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [August 29, 2019, 2:49pm UTC](https://discourse.processing.org/t/using-lambda-form-with-hype-processing/13687/2 "2019-08-29T14:49:48Z")

</div>

Here is a more complicated example:-

```java
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](https://monkstone.github.io/jruby_art/update/2018/01/30/hype-java-lambda.html)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 30, 2019, 3:28am UTC](https://discourse.processing.org/t/using-lambda-form-with-hype-processing/13687/3 "2019-08-30T03:28:54Z")

</div>

the intro you did

> [@Arraylist full of functions?](https://discourse.processing.org/t/arraylist-full-of-functions/10786/6):
>
> [Sam Pottinger](https://github.com/sampottinger/processing) 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. 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

```auto

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?

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [August 30, 2019, 6:29am UTC](https://discourse.processing.org/t/using-lambda-form-with-hype-processing/13687/4 "2019-08-30T06:29:52Z")

</div>

Here’s [gradient.jpg|500x500](https://discourse.processing.org/uploads/short-url/kCUnsTD3dpRA0SaZTG05K347Xk9.jpeg) example from [JRubyArt-examples](https://github.com/ruby-processing/JRubyArt-examples/tree/master/external_library/java/hype) the original supplied by Joshua Davis hype library. Here is snapshot of running sketch:-

 ![hype](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c70ef3ba7a98ae203ff05026da697f0713c1f25d.png)
