Would it be possible to create a triangular application?

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!

Hi @nanto2016,

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

2 Likes

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.

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

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.

1 Like