pushMatrix到窗口中心

时间:2013-09-19 17:42:33

标签: java processing

我正在寻找在窗口中间居中的Processing中制作图形。我希望能够改变窗口的大小并使图形保持居中,无论如何,所以我打算通过居中矩阵本身来做到这一点。

我该怎么做呢?通常我会根据窗口本身的大小将矩阵转换到窗口的中心,但如果我改变了大小,那么它将无法工作。

建议?

1 个答案:

答案 0 :(得分: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);
}