# Processing seemingly capped at 35% cpu

**URL:** <https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872>\
**Category:** Processing\
**Created:** [June 5, 2019, 8:13pm UTC](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872 "2019-06-05T20:13:00Z")\
**Posts on this page:** 5\
**Page:** 3

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 18, 2019, 6:20pm UTC](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872/41 "2019-09-18T18:20:26Z")

</div>

> [@sampottinger](#):
>
> - `females.stream()` : Start streaming (going through) the elements of the `females` collection.
> - `.parallel()` : Split this stream up so that its contents can be run through in parallel.

Those 2 can be shortened as `females.parallelStream()`:  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collection.html#parallelStream()](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collection.html#parallelStream())

> [@sampottinger](#):
>
> `(female) ->` : Call the element I am currently on _female_.

When a lambda expression got 1 parameter only we can omit its parens: `female ->`

> **[Lambda Expressions (The Java™ Tutorials \>        
            Learning the...](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax)**
>
> This beginner Java tutorial describes fundamentals of programming in the Java programming language

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 18, 2019, 8:23pm UTC](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872/42 "2019-09-18T20:23:17Z")

</div>

> [@paulgoux](#):
>
> `if (isLooping ^= true)`  
> Also, what does the `^=` mean?

That’s the XOR operator:  
[http://voidexception.weebly.com/java-xor-exclusive-or-operator-on-booleans.html](http://voidexception.weebly.com/java-xor-exclusive-or-operator-on-booleans.html)

Together w/ the assignment `=` operator:  
`if (isLooping ^= true)` → `if (isLooping = isLooping ^ true)`

When _isLooping_ is `true`, isLooping ^ true evals as `false`: true ^ true = false  
When _isLooping_ is `false`, isLooping ^ true evals as `true`: false ^ true = true

That is equivalent to `if (isLooping = !isLooping)`:

> **[! (logical NOT) / Reference](https://processing.org/reference/logicalNOT.html)**
>
> Inverts the Boolean value of an expression. Returns true if the expression is false and returns false if the expression is true. If the expression (a\>b) evaluates to…

> [@paulgoux](#):
>
> `background(isMainCanvas? altCanvas : mainCanvas);`  
> What does this mean?

That’s the conditional operator, which acts upon 3 operands (ternary):

> **[?: (conditional) / Reference](https://processing.org/reference/conditional.html)**
>
> A shortcut for writing an if and else structure. The conditional operator, ?: is sometimes called the ternary operator, an operator that takes three arguments. If the test …

> **[Ternary conditional operator](https://en.wikipedia.org/wiki/%3F:)**
>
> In computer programming, the ternary conditional operator is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages. It is commonly referred to as the conditional operator, ternary if, or inline if (abbreviated iif). An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c. One can read it aloud as "if a then b otherwise c". The form a ? b : c is by far and large the most common, but alternative syntaxes do exis...

> [@paulgoux](#):
>
> Also, is this running two canvases,

Yes, 2 PGraphics objects:

```auto
mainCanvas = createCanvas();
altCanvas = createCanvas();

```

The idea is while **render()** (which is run by another Thread):  
`thread("render");`

is busy working on the 1st PGraphics:  
`final PGraphics pg = isMainCanvas? main : alt;`

the “Animation” Thread displays the 2nd PGraphics object:  
`background(isMainCanvas? altCanvas : mainCanvas);`

and vice-versa: `isMainCanvas ^= true;`

---

<div class="post-metadata">

**Author:** ![sampottinger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sampottinger/32/6347_2.png) [@sampottinger](https://discourse.processing.org/u/sampottinger)\
**Post date:** [September 19, 2019, 12:27am UTC](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872/43 "2019-09-19T00:27:57Z")

</div>

Thanks very much @GoToLoop! Yeah I elected for the more verbose construction to hopefully improve readability but your version is probably more common online.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [September 22, 2019, 4:36pm UTC](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872/44 "2019-09-22T16:36:32Z")

</div>

I noticed this and honestly like this feature, so often one has to loop through a bunch of functions which makes for repetitive code which can be avoided through the chaining method.

```auto
Particle script(final PGraphics pg) {
    return move().bounce().gravity().display(pg);
  }

```

and I like how its called

```auto
for (int j, i = 0; i < NUM; ) {
      pg.stroke(0);
      final Particle b = particles[j = i++].script(pg);
    }

```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [September 22, 2019, 4:37pm UTC](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872/45 "2019-09-22T16:37:20Z")

</div>

Aah cool. I shall have to give this a go.

[Previous page](https://discourse.processing.org/t/processing-seemingly-capped-at-35-cpu/11872.md?page=2)
