# CubicGridRetained # # You may need to increase the maximum available memory # by passing -mx1000m to jvm (in run script if you use that) # BOX_SIZE = 20 MARGIN = BOX_SIZE * 2 DEPTH = 400 boxFill = None grid = None fcount = 0 lastm = 0 frate = 0 FINT = 3 def setup(): size(640, 360, P3D) frameRate(60) noSmooth() noStroke() global grid grid = createShape(GROUP) # Build grid using multiple for i in range(-DEPTH / 2 + MARGIN, DEPTH / 2 - MARGIN, BOX_SIZE): for j in range(-height + MARGIN, height - MARGIN, BOX_SIZE): for k in range(-width + MARGIN, width - MARGIN, BOX_SIZE): # Base fill color on counter values, abs function # ensures values stay within legal range boxFill = color(abs(i), abs(j), abs(k), 50) sz = [BOX_SIZE, BOX_SIZE, BOX_SIZE] cube = createShape(BOX, sz) cube.setFill(boxFill) cube.translate(k, j, i) grid.addChild(cube) def draw(): background(255) hint(DISABLE_DEPTH_TEST) # Center and spin grid pushMatrix() translate(width / 2, height / 2, -DEPTH) rotateY(frameCount * 0.01) rotateX(frameCount * 0.01) global grid shape(grid) popMatrix() hint(ENABLE_DEPTH_TEST) global fcount, lastm, frate fcount += 1 m = millis() if (m - lastm > 1000 * FINT): frate = float(fcount) / FINT fcount = 0 lastm = m print("fps: %d" % frate) fill(0) text("fps: %d" % frate, 10, 20)
Saturday, 6 April 2013
Thanks to work by Ralf Biedert processing.py has recently been update to use jython-2.7b1 and processing-2.0b8. It might be interesting to follow his fork in the meantime it has been pulled into the original by Jonathan Feinberg. So you can even update it yourself to the development version of vanilla processing if you wish (strange thing is why opengl is still kept in libraries folder instead of alongside core as P2D and P3D are both rendered using opengl). Here is another Shader example translated to processing.py.
1 monjori = None 2 3 def setup(): 4 size(640, 360, P2D) 5 noStroke() 6 global monjori 7 monjori = loadShader("monjori.glsl") 8 monjori.set("resolution", float(width), float(height)) 9 10 11 def draw(): 12 monjori.set("time", millis() / 1000.0) 13 shader(monjori) 14 # The rect is needed to make the fragment shader go through every pixel of 15 # the screen, but is not used for anything else since the rendering is entirely 16 # generated by the shader. 17 fill(0) 18 rect(0, 0, width, height)