Permalink
Browse files

destroy more folder. Rewrite SpaceJunk to be more brief

  • Loading branch information...
1 parent dcc69da commit 4f739fbf8a09c9a0f38fd744b8089ef984e55101 @jdf committed Sep 8, 2010
View
@@ -15,8 +15,8 @@ Write [Processing](http://processing.org) sketches in Python.
$ java -jar processing-py.jar examples.py/Basics/Math/NoiseField/noisefield.py
$ java -jar processing-py.jar examples.py/3D/Typography/KineticType.py
- $ java -jar processing-py.jar examples.py/Library/OpenGL/SpaceJunk/SpaceJunk.py
- $ java -jar processing-py.jar examples.py/3D/Textures/TextureCube/TextureCube.py
+ $ java -jar processing-py.jar examples.py/Library/OpenGL/SpaceJunk.py
+ $ java -jar processing-py.jar examples.py/3D/Textures/TextureCube.py
$ cat > mysketch.py
def draw():
background(0)
@@ -0,0 +1,58 @@
+"""
+ Space Junk
+ by Ira Greenberg.
+ Zoom suggestion
+ by Danny Greenberg.
+ (Rewritten in Python by Jonathan Feinberg.)
+
+ Rotating cubes in space using a custom Cube class.
+ Color controlled by light sources. Move the mouse left
+ and right to zoom.
+"""
+
+# Cube count-lower/raise to test P3D/OPENGL performance
+limit = 500
+
+# Array for all cubes
+cubes = [(int(random(-10, 10)), # width
+ int(random(-10, 10)), # height
+ int(random(-10, 10)), # depth
+ int(random(-140, 140)), # x
+ int(random(-140, 140)), # y
+ int(random(-140, 140))) # z
+ for i in range(limit)]
+
+def setup():
+ size(1024, 768, OPENGL)
+ background(0)
+ noStroke()
+
+def draw():
+ background(0)
+ fill(200)
+
+ # Set up some different colored lights
+ pointLight(51, 102, 255, 65, 60, 100)
+ pointLight(200, 40, 60, -65, -60, -150)
+
+ # Raise overall light in scene
+ ambientLight(70, 70, 10)
+
+ # Center geometry in display windwow.
+ # you can change 3rd argument ('0')
+ # to move block group closer(+)/further(-)
+ translate(width / 2, height / 2, -200 + mouseX * 0.65)
+
+ # Rotate around y and x axes
+ rotateY(frameCount * .01)
+ rotateX(frameCount * .01)
+
+ # Draw cubes
+ for cube in cubes:
+ pushMatrix()
+ translate(cube[3], cube[4], cube[5])
+ box(cube[0], cube[1], cube[2])
+ popMatrix()
+ rotateY(.01)
+ rotateX(.01)
+ rotateZ(.01)
@@ -1,64 +0,0 @@
-class Cube:
-
- def __init__(self, w, h, d, shiftX, shiftY, shiftZ):
- self.w = w
- self.h = h
- self.d = d
- self.shiftX = shiftX
- self.shiftY = shiftY
- self.shiftZ = shiftZ
-
- # Main cube drawing method, which looks
- # more confusing than it really is. It's
- # just a bunch of rectangles drawn for
- # each cube face
- def drawCube(self):
- (hx, hy, hz) = (self.w / 2 + self.shiftX,
- self.h / 2 + self.shiftY,
- self.d / 2 + self.shiftZ)
- (x, y, z) = (self.w + self.shiftX,
- self.h + self.shiftY,
- self.d + self.shiftZ)
- beginShape(QUADS)
- # Front face
- vertex(-hx, -hy, -hz)
- vertex(x, -hy, -hz)
- vertex(x, y, -hz)
- vertex(-hx, y, -hz)
-
- # Back face
- vertex(-hx, -hy, z)
- vertex(x, -hy, z)
- vertex(x, y, z)
- vertex(-hx, y, z)
-
- # Left face
- vertex(-hx, -hy, -hz)
- vertex(-hx, -hy, z)
- vertex(-hx, y, z)
- vertex(-hx, y, -hz)
-
- # Right face
- vertex(x, -hy, -hz)
- vertex(x, -hy, z)
- vertex(x, y, z)
- vertex(x, y, -hz)
-
- # Top face
- vertex(-hx, -hy, -hz)
- vertex(x, -hy, -hz)
- vertex(x, -hy, z)
- vertex(-hx, -hy, z)
-
- # Bottom face
- vertex(-hx, y, -hz)
- vertex(x, y, -hz)
- vertex(x, y, z)
- vertex(-hx, y, z)
-
- endShape()
-
- # Add some rotation to each box for pizazz.
- rotateY(radians(1))
- rotateX(radians(1))
- rotateZ(radians(1))
@@ -1,58 +0,0 @@
-"""
- * Space Junk
- * by Ira Greenberg.
- * Zoom suggestion
- * by Danny Greenberg.
- *
- * Rotating cubes in space using a custom Cube class.
- * Color controlled by light sources. Move the mouse left
- * and right to zoom.
-"""
-
-from Cube import Cube
-# Used for oveall rotation
-ang = 0.0
-
-# Cube count-lower/raise to test P3D/OPENGL performance
-limit = 500
-
-# Array for all cubes
-cubes = [Cube(int(random(-10, 10)), int(random(-10, 10)),
- int(random(-10, 10)), int(random(-140, 140)),
- int(random(-140, 140)), int(random(-140, 140)))
- for i in range(limit)]
-
-def setup():
- size(1024, 768, OPENGL)
- background(0)
- noStroke()
-
-def draw():
- background(0)
- fill(200)
-
- # Set up some different colored lights
- pointLight(51, 102, 255, 65, 60, 100)
- pointLight(200, 40, 60, -65, -60, -150)
-
- # Raise overall light in scene
- ambientLight(70, 70, 10)
-
- # Center geometry in display windwow.
- # you can change 3rd argument ('0')
- # to move block group closer(+)/further(-)
- translate(width / 2, height / 2, -200 + mouseX * 0.65)
-
- # Rotate around y and x axes
- global ang
- rotateY(radians(ang))
- rotateX(radians(ang))
-
- # Draw cubes
- for cube in cubes:
- cube.drawCube()
-
- # Used in rotate function calls above
- ang += 1
-
-

0 comments on commit 4f739fb

Please sign in to comment.