mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Merge pull request #1725 from ybakos/p5_web_45_examples_CubicGridRetained
Examples patch (9 of 9)
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
/* CubicGridRetained
|
||||
*
|
||||
* You may need to increase the maximum available memory in the
|
||||
* Processing preferences menu.
|
||||
*/
|
||||
float boxSize = 20;
|
||||
float margin = boxSize*2;
|
||||
float depth = 400;
|
||||
@@ -14,16 +19,16 @@ void setup() {
|
||||
frameRate(60);
|
||||
noSmooth();
|
||||
noStroke();
|
||||
|
||||
|
||||
grid = createShape(GROUP);
|
||||
|
||||
// Build grid using multiple translations
|
||||
|
||||
// Build grid using multiple translations
|
||||
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
|
||||
for (float j =- height+margin; j <= height-margin; j += boxSize){
|
||||
for (float k =- width+margin; k <= width-margin; k += boxSize){
|
||||
// Base fill color on counter values, abs function
|
||||
// Base fill color on counter values, abs function
|
||||
// ensures values stay within legal range
|
||||
boxFill = color(abs(i), abs(j), abs(k), 50);
|
||||
boxFill = color(abs(i), abs(j), abs(k), 50);
|
||||
PShape cube = createShape(BOX, boxSize, boxSize, boxSize);
|
||||
cube.setFill(boxFill);
|
||||
cube.translate(k, j, i);
|
||||
@@ -35,9 +40,9 @@ void setup() {
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
|
||||
hint(DISABLE_DEPTH_TEST);
|
||||
|
||||
|
||||
// Center and spin grid
|
||||
pushMatrix();
|
||||
translate(width/2, height/2, -depth);
|
||||
@@ -46,17 +51,17 @@ void draw() {
|
||||
|
||||
shape(grid);
|
||||
popMatrix();
|
||||
|
||||
|
||||
hint(ENABLE_DEPTH_TEST);
|
||||
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
println("fps: " + frate);
|
||||
}
|
||||
fill(0);
|
||||
text("fps: " + frate, 10, 20);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user