Permalink
Browse files

added demos

  • Loading branch information...
gka committed May 21, 2012
1 parent 9fb53d1 commit bee90b685605edd604ff6466fc311d01708896a8
Showing with 90 additions and 0 deletions.
  1. +43 −0 animator.py
  2. BIN data/melon.jpg
  3. +15 −0 helloworld.py
  4. +32 −0 pointillism.py
View
@@ -0,0 +1,43 @@
+# Animator.
+# http://processing.org/learning/topics/animator.html
+
+from P5 import *
+
+
+currentFrame = 0
+frames = [PImage() for i in range(24)]
+lastTime = 0
+
+
+def setup():
+ size(640, 200)
+ strokeWeight(12)
+ frameRate(30)
+ smooth()
+ background(0)
+ stroke(240)
+ for i in range(len(frames)):
+ frames[i] = get()
+
+
+def draw():
+ global lastTime
+ currentTime = millis()
+ if currentTime > lastTime + 30:
+ nextFrame()
+ lastTime = currentTime
+
+ if mouse.pressed:
+ line(mouse.px, mouse.py, mouse.x, mouse.y)
+
+
+def nextFrame():
+ global currentFrame
+ frames[currentFrame] = get() # Get the display window
+ currentFrame += 1 # Increment to next frame
+ if currentFrame >= len(frames):
+ currentFrame = 0
+ image(frames[currentFrame], 0, 0)
+
+
+run(globals())
View
Binary file not shown.
View
@@ -0,0 +1,15 @@
+
+from P5 import *
+
+def setup():
+ size(400, 400)
+ smooth()
+
+def draw():
+ if mouse.pressed:
+ fill(0)
+ else:
+ fill(255)
+ ellipse(mouse.x, mouse.y, 80, 80)
+
+run(globals())
View
@@ -0,0 +1,32 @@
+
+from P5 import *
+
+smallPoint = 2
+top = left = largePoint = 0
+img = None
+
+
+def setup():
+ global largePoint, left, top, img
+ size(500, 500)
+ frameRate(120)
+ img = loadImage("../data/melon.jpg")
+ noStroke()
+ background(255)
+ smooth()
+ largePoint = min(P5.width, P5.height) / 10
+ left = (P5.width - img.width) / 2
+ top = (P5.height - img.height) / 2
+
+
+def draw():
+ pointillize = P5.map(mouse.x, 0, P5.width, smallPoint, largePoint)
+ x = int(random(img.width))
+ y = int(random(img.height))
+ pix = img.get(x, y)
+ fill(pix, 128)
+ ellipse(left + x, top + y, pointillize, pointillize)
+ if P5.frameCount % 100 == 0:
+ print round(P5.frameRate), 'frames per second'
+
+run(globals())

0 comments on commit bee90b6

Please sign in to comment.