# Would it be possible to create a triangular application?

**URL:** <https://discourse.processing.org/t/would-it-be-possible-to-create-a-triangular-application/41564>\
**Category:** Coding Questions\
**Created:** [April 2, 2023, 2:26am UTC](https://discourse.processing.org/t/would-it-be-possible-to-create-a-triangular-application/41564 "2023-04-02T02:26:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanto2016](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nanto2016](https://discourse.processing.org/u/nanto2016)\
**Post date:** [April 2, 2023, 2:26am UTC](https://discourse.processing.org/t/would-it-be-possible-to-create-a-triangular-application/41564/1 "2023-04-02T02:26:22Z")

</div>

So I thought of trying to create some cellular automata or simulation, whatever, and I thought of making one triangular. I guess it would be pretty cool to make a triangular 2D array _somehow_…? I might find a way to do that (maybe), but if anyone has an idea, feel free to share it as I am pretty confused on how that would be possible (if it is). But if I make a triangular cellular automata, I’d like the window itself to be triangular. This is clearly not _really_ possible, but I can make it undecorated and have transparency to do the same effect… already tried that out before, seems like it’s possible with some java libraries but it doesn’t work in Processing. So would this be possible, and if yes, how would I do it, exactly? Thanks in advance for responses!

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [April 2, 2023, 10:22am UTC](https://discourse.processing.org/t/would-it-be-possible-to-create-a-triangular-application/41564/2 "2023-04-02T10:22:27Z")

</div>

Hi @nanto2016,

To make an undecorated window with a custom shape, you can see this previous post I did:

> [@Possible to change top bars layout? (window frame color)](https://discourse.processing.org/t/possible-to-change-top-bars-layout-window-frame-color/40914/2):
>
> Hi @Aryszin, In Windows, the title bar can be customized using the Windows API in C#: [Title bar customization - Windows apps | Microsoft Learn](https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=wasdk) You can access the [java.awt.Frame](https://docs.oracle.com/javase/7/docs/api/java/awt/Frame.html) instance like this and modify it’s shape for example (you can make it transparent [here](https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/misc/ShapedWindowDemoProject/src/misc/ShapedWindowDemo.java)) : import processing.awt.PSurfaceAWT; import java.awt.Frame; import java.awt.geom.Ellipse2D; void setup() { size(500, 500); PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas)(surface.getNative()); Frame frame = ca…

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [April 2, 2023, 2:07pm UTC](https://discourse.processing.org/t/would-it-be-possible-to-create-a-triangular-application/41564/3 "2023-04-02T14:07:20Z")

</div>

Hi @nanto2016

I have occasionally wanted a triangular array for e.g. the numbers in Pascal’s triangle. I’ve used a 1D array with the data for each triangle row one after another. You need to know where each row starts. It’s at (Row\*Row+Row)/2. (0,1,3,6,10,15) Sometimes I’ve kept the results from that formula in a separate 1D array. That’s probably faster for intensive use.

---

<div class="post-metadata">

**Author:** ![nanto2016](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nanto2016](https://discourse.processing.org/u/nanto2016)\
**Post date:** [April 2, 2023, 2:44pm UTC](https://discourse.processing.org/t/would-it-be-possible-to-create-a-triangular-application/41564/4 "2023-04-02T14:44:06Z")

</div>

Thanks a lot! That’s pretty cool, I now have a triangular application!

```auto
import processing.awt.PSurfaceAWT;
import java.awt.Frame;
import java.awt.Polygon;

void setup() {
  size(500, 500);

  PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas)(surface.getNative());
  Frame frame = canvas.getFrame();

  frame.removeNotify();
  frame.setUndecorated(true);
  int[] x = { 0, 250, 500 }, y = { 500, 0, 500 };
  int n = 3;
  frame.setShape(new Polygon(x, y, n));
  frame.addNotify();
  frame.setVisible(false);
  frame.setVisible(true);
}

```

I don’t think there is a Trinagle class in java, so I just used Polygon. There was a problem, though, the edges were weirdly cut-off, but when I minimised and re-focused on the app it became fine. So the setVisible false true is just to make it right from the beggining.
