java Vera Molnar变奏曲

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Vera Molnar变奏曲相关的知识,希望对你有一定的参考价值。

/*

THIS IS A PROCESSING SKETCH!
change file suffix in .pde before running
*/

/*
The 25 Squares by Vera Molnar Variations
Exercise 01 of week 02
Creative Coding Monash University
*/

/*Rows & cols. Change this to control
 the pattern density*/
int grid = 5; 

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

/*We'll use alpha to color the squares and
background color could influence the final result.*/
background(125); 

  rectMode(CORNER);
  for (float x = 0; x < grid; x++) {
    for (float y = 0; y < grid; y++) {

//Here we have the red tint and alpha
fill(random(125, 200), 0, 0, random(125, 200));

      /*The gaps, the squares size and the rect drawing.
       Thanks to Jerome Herr and Adam Wellings
       This way, gaps can be setted to different values*/
      float gapx = 5 + (int)random(-5, 5); // Gaps 
      float gapy = 5 + (int)random(-5, 5); // Gaps
      float sqrsz = (500 - (grid+1)*gapx) / grid; //The Square size
      rect(gapx*(x+1)+(sqrsz*x), gapy*(y+1)+(sqrsz*y), sqrsz, sqrsz);
    }
  }
}

void draw() {
//Nothing here, but the engine is running.
}

//Click for a different pattern
void mouseClicked() {
  background(125);
  for (float x = 0; x < grid; x++) {
    for (float y = 0; y < grid; y++) {
      fill(random(125, 200), 0, 0, random(125, 200));
      float gapx = 5 + (int)random(-5, 5); // Gaps
      float gapy = 5 + (int)random(-5, 5); // Gaps
      float sqrsz = (500 - (grid+1)*gapx) / grid; //The Square size
      rect(gapx*(x+1)+(sqrsz*x), gapy*(y+1)+(sqrsz*y), sqrsz, sqrsz);
    }
  }
}
//Hit a key to save your pattern
void keyPressed() {
  saveFrame("Molnar.jpg");
  print("Vera was saved!");
}

以上是关于java Vera Molnar变奏曲的主要内容,如果未能解决你的问题,请参考以下文章

代码风格检查工具vera++

代码风格检查工具vera++

代码风格检查工具vera++

时光变奏曲

时光变奏曲

Dear Vera