0

I'm looking to make a graphic in Processing that's centered in the middle of the window. I want to be able to change the size of the window and have the graphic remain centred no matter what, so I intend to do this through centering the matrix itself.

How would I go about doing this? Normally I would translate the matrix to the center of the window based on the size of the window itself, but if I'm changing the size then it won't work.

Suggestions?

4

1 回答 1

0

在这里,我得到了这样的旧代码......

import processing.opengl.*;

int newCanvasWidth  = MIN_WINDOW_WIDTH;  // made global to  use in draw
int newCanvasHeight = MIN_WINDOW_HEIGHT;


java.awt.Insets insets;  //"An Insets object is a representation of the borders of a container"
                         //from http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Insets.html

void setup()
{
  size(200, 200);   // always first line
  frame.pack();     //frame.pack() no need for setResizable... plus insets
  insets = frame.getInsets();
  frame.setResizable(true);

      /// for debuging, system depende`nt, at least screen is...
  print("MIN_WINDOW_WIDTH = " + MIN_WINDOW_WIDTH);
  print("   MIN_WINDOW_HEIGHT = " + MIN_WINDOW_HEIGHT);
  print("   screenWidth = " + displayWidth);
  println("    screenHeight = " + displayHeight);
}


void draw()
{
  background(255);
  ellipse(width/2, height/2, width/2, height/2);
}
于 2013-09-19T17:51:39.717 回答