├── .gitignore ├── MANIFEST.in ├── examples ├── reference │ ├── rect.py │ ├── images │ │ ├── tex.jpg │ │ ├── arch.jpg │ │ ├── doll.jpg │ │ ├── tower.jpg │ │ └── Foto-Aerea-Fundao.gif │ ├── box.py │ ├── loadimage.py │ ├── sphere.py │ ├── get.py │ ├── sheary.py │ ├── shearx.py │ ├── ellipse.py │ ├── screen.py │ ├── tint.py │ ├── text2.py │ ├── beziervertex.py │ ├── text3.py │ ├── nocursor.py │ ├── pointlight.py │ ├── colormode.py │ ├── line.py │ ├── set.py │ ├── bezier.py │ ├── ortho.py │ ├── arc.py │ ├── spotlight.py │ ├── directionallight.py │ ├── save.py │ ├── camera.py │ ├── emissive.py │ ├── pmousex.py │ ├── lights.py │ ├── text.py │ ├── curve.py │ ├── cursor.py │ ├── curvevertex.py │ ├── exit.py │ ├── pimageset.py │ ├── popmatrix.py │ ├── ambientlight.py │ ├── redraw.py │ ├── textwidth.py │ ├── perspective.py │ ├── bezierpoint.py │ ├── textAscent.py │ ├── mousemoved.py │ ├── loop.py │ ├── textDescent.py │ ├── blendcolor.py │ ├── mousedragged.py │ ├── specular.py │ ├── keycode.py │ ├── backgroundimage.py │ ├── bezierdetail.py │ ├── lerpcolor.py │ ├── mouseclicked.py │ ├── mousebutton.py │ ├── shininess.py │ ├── createimage.py │ ├── applymatrix.py │ ├── keytyped.py │ ├── curvepoint.py │ ├── curvetangent.py │ ├── curvedetail.py │ ├── resetmatrix.py │ ├── screenx.py │ ├── filter.py │ ├── beziertangent.py │ ├── modelx.py │ └── texture.py ├── usage │ ├── basicusage.py │ ├── interaction.py │ ├── interactioncallback.py │ └── animation.py ├── misc │ ├── helloworld.py │ ├── fonttest.py │ ├── coordsystem.py │ ├── widthandheight.py │ ├── piechart.py │ ├── helloworldrot.py │ ├── polygons.py │ ├── recursion.py │ ├── falloff.py │ ├── boxandsphere.py │ ├── circles.py │ ├── orthoandperspective.py │ ├── triflower.py │ └── fpstest.py └── handbook │ ├── 9-08.py │ ├── 9-18.py │ ├── 9-09.py │ ├── 3D_02.py │ ├── 05_waves.py │ ├── centipede.py │ └── 3D_03.py ├── pyprocessing ├── globalconfig.txt ├── materials.py ├── config.py ├── globs.py ├── attribs.py ├── fbo.py ├── mathfunctions.py ├── lights.py ├── fonts.py ├── pvector.py ├── constants.py ├── transformations.py ├── flippolicy.py ├── shapes.py ├── primitives.py ├── __init__.py └── colors.py ├── setup.py ├── README.md ├── tools ├── accumfliptest.py ├── flip_setup.py ├── takesnapshot.py ├── fbo.py └── flippolicy.py ├── README.txt └── ez_setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.pyc -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.txt 2 | recursive-include examples *.py *.jpg *.gif *.png 3 | -------------------------------------------------------------------------------- /examples/reference/rect.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | rect (10,10,80,80) 4 | 5 | run() 6 | -------------------------------------------------------------------------------- /examples/reference/images/tex.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperanc/pyprocessing/HEAD/examples/reference/images/tex.jpg -------------------------------------------------------------------------------- /examples/reference/images/arch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperanc/pyprocessing/HEAD/examples/reference/images/arch.jpg -------------------------------------------------------------------------------- /examples/reference/images/doll.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperanc/pyprocessing/HEAD/examples/reference/images/doll.jpg -------------------------------------------------------------------------------- /examples/reference/images/tower.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperanc/pyprocessing/HEAD/examples/reference/images/tower.jpg -------------------------------------------------------------------------------- /examples/reference/box.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | translate(58, 48, 0); 4 | rotateY(0.5); 5 | box(40); 6 | 7 | run() 8 | -------------------------------------------------------------------------------- /examples/reference/loadimage.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | b = loadImage("images/arch.jpg") 4 | image (b,0,0) 5 | 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /examples/reference/images/Foto-Aerea-Fundao.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperanc/pyprocessing/HEAD/examples/reference/images/Foto-Aerea-Fundao.gif -------------------------------------------------------------------------------- /examples/reference/sphere.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noStroke(); 4 | lights(); 5 | translate(58, 48, 0); 6 | sphere(28); 7 | 8 | run() 9 | -------------------------------------------------------------------------------- /examples/usage/basicusage.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | smooth() 4 | for i in range(10): 5 | line(i*5+5,20,i*5+50,80) 6 | 7 | run() 8 | -------------------------------------------------------------------------------- /pyprocessing/globalconfig.txt: -------------------------------------------------------------------------------- 1 | multisample:True 2 | coordInversionHack:True 3 | halfPixelShiftHack:False 4 | smoothFixHack:False 5 | flipPolicy:BACKUP_FLIP_POLICY 6 | 7 | -------------------------------------------------------------------------------- /examples/reference/get.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | myImage = loadImage("images/arch.jpg"); 4 | image(myImage, 0, 0); 5 | cp = get(); 6 | image(cp, 50, 0); 7 | 8 | run() 9 | -------------------------------------------------------------------------------- /examples/reference/sheary.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | size(100, 100) 5 | translate(width/4, height/4) 6 | shearY(PI/4.0) 7 | rect(0, 0, 30, 30) 8 | 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/reference/shearx.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | size(100, 100) 5 | translate(width/4, height/4) 6 | shearX(PI/4.0) 7 | rect(0, 0, 30, 30) 8 | 9 | 10 | 11 | run() 12 | -------------------------------------------------------------------------------- /examples/reference/ellipse.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200,200,resizable=True) 4 | def draw(): 5 | background(200) 6 | ellipse(width/2,height/2,width-40,height-40) 7 | 8 | run() 9 | -------------------------------------------------------------------------------- /examples/reference/screen.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(screen.width, screen.height) 5 | 6 | def draw(): 7 | line(0, 0, screen.width, screen.height) 8 | 9 | run() 10 | -------------------------------------------------------------------------------- /examples/reference/tint.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | b = loadImage("images/arch.jpg"); 4 | image(b, 0, 0); 5 | # Tint blue 6 | tint(0, 153, 204, 126); 7 | image(b, 50, 0); 8 | 9 | run() 10 | 11 | -------------------------------------------------------------------------------- /examples/reference/text2.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | font = createFont("times", 12); 4 | textFont(font); 5 | s = "The quick brown fox jumped over the lazy dog." 6 | text(s, 15, 20, 70, 70) 7 | 8 | run() 9 | -------------------------------------------------------------------------------- /examples/reference/beziervertex.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | beginShape() 4 | vertex(30, 20) 5 | bezierVertex(80, 0, 80, 75, 30, 75) 6 | bezierVertex(50, 75, 60, 25, 30, 20) 7 | endShape() 8 | 9 | run() 10 | -------------------------------------------------------------------------------- /examples/reference/text3.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | font = createFont("Times",32); 4 | textFont(font); 5 | text("word", 15, 60, -30); 6 | fill(0, 102, 153); 7 | text("word", 15, 60); 8 | 9 | run() 10 | -------------------------------------------------------------------------------- /examples/reference/nocursor.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Press the mouse to hide the cursor 4 | 5 | def draw() : 6 | if mouse.pressed: 7 | noCursor() 8 | else: 9 | cursor(HAND) 10 | 11 | run() 12 | -------------------------------------------------------------------------------- /examples/reference/pointlight.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(100, 100); 4 | background(0); 5 | noStroke(); 6 | pointLight(51, 102, 126, 35, 40, 36); 7 | translate(80, 50, 0); 8 | sphere(30); 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/reference/colormode.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noStroke() 4 | colorMode(HSB, 100) 5 | for i in range(100): 6 | for j in range(100): 7 | stroke(i, j, 100) 8 | point(i, j) 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/reference/line.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(100, 100); 4 | line(30, 20, 0, 85, 20, 15); 5 | stroke(126); 6 | line(85, 20, 15, 85, 75, 0); 7 | stroke(255); 8 | line(85, 75, 0, 30, 75, -50); 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/reference/set.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | for i in range(30,width-15): 4 | for j in range(20,height-25): 5 | c = color(204-j, 153-i, 0); 6 | setScreen(i, j, c); 7 | 8 | 9 | run() 10 | 11 | -------------------------------------------------------------------------------- /examples/reference/bezier.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | stroke(255, 102, 0); 5 | line(30, 20, 80, 5); 6 | line(80, 75, 30, 75); 7 | stroke(0, 0, 0); 8 | bezier(30, 20, 80, 5, 80, 75, 30, 75); 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/reference/ortho.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill() 4 | camera(0,0,0,0,0,-1,0,1,0); 5 | ortho(0,width,0,height,-100,100) 6 | translate(50,50,0) 7 | rotateX(-PI/6); 8 | rotateY(PI/3); 9 | box(45) 10 | 11 | run() 12 | -------------------------------------------------------------------------------- /examples/reference/arc.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | arc(50, 55, 50, 50, 0, PI/2); 4 | noFill(); 5 | arc(50, 55, 60, 60, PI/2, PI); 6 | arc(50, 55, 70, 70, PI, TWO_PI-PI/2); 7 | arc(50, 55, 80, 80, TWO_PI-PI/2, TWO_PI); 8 | 9 | run() 10 | -------------------------------------------------------------------------------- /examples/reference/spotlight.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | size(100, 100); 5 | background(0); 6 | noStroke(); 7 | spotLight(51, 102, 126, 80, 20, 40, -1, 0, 0, PI/2, 2); 8 | translate(20, 50, 0); 9 | sphere(30); 10 | 11 | run() 12 | -------------------------------------------------------------------------------- /examples/misc/helloworld.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(300,300,caption="Hello") 4 | 5 | textFont(createFont("Times", 36, bold=True, italic=True)) 6 | textAlign(CENTER) 7 | text("Hello world", width/2, height/2) 8 | 9 | run() 10 | 11 | -------------------------------------------------------------------------------- /examples/handbook/9-08.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | background(56, 90, 94); 4 | smooth(); 5 | x = 0; 6 | strokeWeight(12); 7 | for i in range(51,256,51): 8 | stroke(242, 204, 47, i); 9 | line(x, 20, x+20, 80); 10 | x += 20; 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/handbook/9-18.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Change the saturation and brightness, hue constant 4 | colorMode(HSB); 5 | for i in range(100): 6 | for j in range(100): 7 | stroke(132, j*2.5, i*2.5); 8 | point(i, j) 9 | 10 | run() 11 | 12 | -------------------------------------------------------------------------------- /examples/reference/directionallight.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | hint(ENABLE_DEPTH_TEST) 4 | 5 | size(100, 100); 6 | background(0); 7 | noStroke(); 8 | directionalLight(51, 102, 126, -1, 0, 0); 9 | translate(20, 50, 0); 10 | sphere(30); 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/reference/save.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | line(20, 20, 80, 80); 4 | # Saves a PNG file named "diagonal.png" 5 | save("diagonal.png"); 6 | # Saves a PNG file named "cross.png" 7 | line(80, 20, 20, 80); 8 | save("cross.png"); 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/misc/fonttest.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200,200) 4 | font = createFont("Times New Roman", 20); 5 | textFont(font); 6 | textAlign(CENTER,CENTER) 7 | text("The quick brown\nfox jumps over\nthe lazy dogs", width/2, height/2) 8 | 9 | run() 10 | -------------------------------------------------------------------------------- /examples/reference/camera.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | background(204); 5 | camera(70.0, 35.0, 120.0, 50.0, 50.0, 0.0, 6 | 0.0, 1.0, 0.0); 7 | translate(50, 50, 0); 8 | rotateX(-PI/6); 9 | rotateY(PI/3); 10 | box(45); 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/reference/emissive.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(100, 100); 4 | background(0); 5 | noStroke(); 6 | background(0); 7 | directionalLight(204, 204, 204, .5, 0, -1); 8 | emissive(0, 26, 51); 9 | translate(70, 50, 0); 10 | sphere(30); 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/reference/pmousex.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | # Move the mouse quickly to see the difference 5 | # between the current and previous position 6 | def draw() : 7 | background(204); 8 | line(mouse.x, 20, pmouse.x, 80); 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /examples/reference/lights.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | background(0); 4 | noStroke(); 5 | # Sets the default ambient 6 | # and directional light 7 | lights(); 8 | translate(20, 50, 0); 9 | sphere(30); 10 | translate(60, 0, 0); 11 | sphere(30); 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/reference/text.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | font = createFont("Times New Roman", 24); 4 | textFont(font); 5 | text("word", 15, 30); 6 | fill(0, 102, 153); 7 | text("word", 15, 60); 8 | fill(0, 102, 153, 51); 9 | text("word", 15, 90); 10 | 11 | run() 12 | -------------------------------------------------------------------------------- /examples/misc/coordsystem.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200,200); 4 | rectMode(CENTER); 5 | rect(100,100,20,100); 6 | ellipse(100,70,60,60); 7 | ellipse(81,70,16,32); 8 | ellipse(119,70,16,32); 9 | line(90,150,80,160); 10 | line(110,150,120,160); 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/misc/widthandheight.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200, 200); 4 | background(127); 5 | noStroke(); 6 | for i in range(0,height,20): 7 | fill(0); 8 | rect(0, i, width, 10); 9 | fill(255); 10 | rect(i, 0, 10, height); 11 | 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/reference/curve.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | stroke(255, 102, 0); 5 | curve(5, 26, 5, 26, 73, 24, 73, 61); 6 | stroke(0); 7 | curve(5, 26, 73, 24, 73, 61, 15, 65); 8 | stroke(255, 102, 0); 9 | curve(73, 24, 73, 61, 15, 65, 15, 65); 10 | 11 | run() 12 | -------------------------------------------------------------------------------- /examples/reference/cursor.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Move the mouse left and right across the image 4 | # to see the cursor change from a cross to a hand 5 | 6 | def draw() : 7 | if mouse.x < 50: 8 | cursor(CROSS) 9 | else: 10 | cursor(HAND) 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/reference/curvevertex.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | beginShape(); 5 | curveVertex(84, 91); 6 | curveVertex(84, 91); 7 | curveVertex(68, 19); 8 | curveVertex(21, 17); 9 | curveVertex(32, 100); 10 | curveVertex(32, 100); 11 | endShape(); 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/reference/exit.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | x = 0 4 | 5 | def setup(): 6 | size(200, 200); 7 | 8 | def draw(): 9 | background(204); 10 | global x 11 | x = (x+1)%width 12 | line(x, 0, x, height); 13 | 14 | def mousePressed(): 15 | exit() 16 | 17 | run() 18 | 19 | -------------------------------------------------------------------------------- /examples/reference/pimageset.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | img = loadImage("images/tower.jpg"); 4 | black = color(0, 0, 0); 5 | img.set(30, 20, black); 6 | img.set(85, 20, black); 7 | img.set(85, 75, black); 8 | img.set(30, 75, black); 9 | image(img, 0, 0); 10 | 11 | run() 12 | 13 | -------------------------------------------------------------------------------- /examples/reference/popmatrix.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | rect(0, 0, 50, 50); #White rectangle 4 | pushMatrix(); 5 | translate(30, 20); 6 | fill(0); 7 | rect(0, 0, 50, 50); #Black rectangle 8 | popMatrix(); 9 | fill(102); 10 | rect(15, 10, 50, 50); #Gray rectangle 11 | 12 | run() 13 | -------------------------------------------------------------------------------- /examples/handbook/9-09.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | background(0); 4 | noStroke(); 5 | smooth(); 6 | fill(242, 204, 47, 160); 7 | ellipse(47, 36, 64, 64); 8 | fill(174, 221, 60, 160); 9 | ellipse(90, 47, 64, 64); 10 | fill(116, 193, 206, 160); 11 | ellipse(57, 79, 64, 64); 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/reference/ambientlight.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | background(0); 5 | noStroke(); 6 | directionalLight(126, 126, 126, 0, 0, -1); 7 | ambientLight(102, 102, 102); 8 | translate(32, 50, 0); 9 | rotateY(PI/5); 10 | box(40); 11 | translate(60, 0, 0); 12 | sphere(30); 13 | 14 | run() 15 | -------------------------------------------------------------------------------- /examples/reference/redraw.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | x = 0 4 | 5 | def setup(): 6 | size(200, 200); 7 | noLoop(); 8 | 9 | def draw(): 10 | background(204); 11 | line(x, 0, x, height); 12 | 13 | def mousePressed(): 14 | global x 15 | x += 1; 16 | redraw(); 17 | 18 | run() 19 | 20 | -------------------------------------------------------------------------------- /examples/reference/textwidth.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | font = createFont("Times"); 4 | textFont(font, 28); 5 | 6 | c = 'T'; 7 | cw = textWidth(c); 8 | text(c, 0, 40); 9 | line(cw, 0, cw, 50); 10 | 11 | s = "Tokyo"; 12 | sw = textWidth(s); 13 | text(s, 0, 85); 14 | line(sw, 50, sw, 100); 15 | 16 | run() 17 | -------------------------------------------------------------------------------- /examples/reference/perspective.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | fov = PI/3.0; 5 | cameraZ = (height/2.0) / tan(fov/2.0); 6 | perspective(fov, float(width)/float(height), 7 | cameraZ/10.0, cameraZ*10.0); 8 | translate(50, 50, 0); 9 | rotateX(-PI/6); 10 | rotateY(PI/3); 11 | box(45); 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/reference/bezierpoint.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | bezier(85, 20, 10, 10, 90, 90, 15, 80); 5 | fill(255); 6 | steps = 10; 7 | for i in range(steps+1): 8 | t = i / float(steps); 9 | x = bezierPoint(85, 10, 90, 15, t); 10 | y = bezierPoint(20, 10, 90, 80, t); 11 | ellipse(x, y, 5, 5); 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/usage/interaction.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200,200) 4 | 5 | def draw(): 6 | # scribble a line with the mouse 7 | if mouse.pressed: 8 | line (pmouse.x, pmouse.y, mouse.x, mouse.y) 9 | # typing 'C' clears the screen 10 | if key.pressed and key.char in 'cC': 11 | background(200) 12 | 13 | run() 14 | -------------------------------------------------------------------------------- /examples/usage/interactioncallback.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200,200) 4 | 5 | def mouseDragged(): 6 | # scribble a line with the mouse 7 | line (pmouse.x, pmouse.y, mouse.x, mouse.y) 8 | 9 | def keyPressed(): 10 | # typing 'C' clears the screen 11 | if key.char in 'cC': 12 | background(200) 13 | 14 | run() 15 | -------------------------------------------------------------------------------- /examples/reference/textAscent.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | font = createFont("Helvetica"); 4 | textFont(font); 5 | 6 | textSize(32); 7 | ascent = textAscent(); 8 | text("dp", 0, 70); 9 | line(0, 70-ascent, 100, 70-ascent); 10 | 11 | textSize(64); 12 | ascent = textAscent(); 13 | text("dp", 35, 70); 14 | line(35, 70-ascent, 100, 70-ascent); 15 | 16 | run() 17 | -------------------------------------------------------------------------------- /examples/reference/mousemoved.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Move your mouse across the 4 | # image to change the value of the rectangle 5 | 6 | value = 0; 7 | 8 | def draw(): 9 | fill(value); 10 | rect(25, 25, 50, 50); 11 | 12 | def mouseMoved(): 13 | global value 14 | value = value + 5; 15 | if (value > 255): 16 | value = 0; 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/reference/loop.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(200,200) 5 | noLoop() 6 | 7 | x = 0 8 | 9 | def draw(): 10 | global x 11 | background(204) 12 | x = x+0.5 13 | if x>width: x = 0 14 | line(x,0,x,height) 15 | 16 | 17 | def mousePressed(): loop() 18 | 19 | def mouseReleased(): noLoop() 20 | 21 | run() 22 | -------------------------------------------------------------------------------- /examples/reference/textDescent.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | font = createFont("Helvetica"); 4 | textFont(font); 5 | 6 | textSize(32); 7 | descent = textDescent(); 8 | text("dp", 0, 70); 9 | line(0, 70+descent, 100, 70+descent); 10 | 11 | textSize(64); 12 | descent = textDescent(); 13 | text("dp", 35, 70); 14 | line(35, 70+descent, 100, 70+descent); 15 | 16 | run() 17 | -------------------------------------------------------------------------------- /examples/misc/piechart.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200, 200); 4 | background(100); 5 | noStroke(); 6 | 7 | diameter = 150; 8 | angs = [30, 10, 45, 35, 60, 38, 75, 67]; 9 | lastAng = 0; 10 | smooth() 11 | for a in angs: 12 | fill(a * 3.0); 13 | arc(width/2, height/2, diameter, diameter, lastAng, 14 | lastAng+radians(a)) 15 | lastAng += radians(a) 16 | 17 | run() 18 | -------------------------------------------------------------------------------- /examples/misc/helloworldrot.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(300,300) 4 | textFont(createFont("Times New Roman", 36)) 5 | textAlign(CENTER,CENTER) 6 | ang = 0 7 | 8 | def draw(): 9 | global ang 10 | background(0,0,0) 11 | fill (255) 12 | translate (width/2, height/2) 13 | rotateZ (ang) 14 | ang += 0.01 15 | text("Hello world", 0, 0) 16 | 17 | run() 18 | 19 | -------------------------------------------------------------------------------- /examples/reference/blendcolor.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | orange = color(204, 102, 0); 4 | blue = color(0, 102, 153); 5 | print orange,blue 6 | orangeblueadd = blendColor(orange, blue, ADD); 7 | background(51); 8 | noStroke(); 9 | fill(orange); 10 | rect(14, 20, 20, 60); 11 | fill(orangeblueadd); 12 | rect(40, 20, 20, 60); 13 | fill(blue); 14 | rect(66, 20, 20, 60); 15 | 16 | run() 17 | -------------------------------------------------------------------------------- /examples/reference/mousedragged.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Drag (click and hold) your mouse across the 4 | # image to change the value of the rectangle 5 | 6 | value = 0; 7 | 8 | def draw(): 9 | fill(value); 10 | rect(25, 25, 50, 50); 11 | 12 | def mouseDragged(): 13 | global value 14 | value = value + 5; 15 | if (value > 255): 16 | value = 0; 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/misc/polygons.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(200,200) 4 | poly = [] 5 | smooth() 6 | def mousePressed(): 7 | poly [:] = [(mouse.x,mouse.y)] 8 | 9 | def mouseDragged(): 10 | poly.append((mouse.x,mouse.y)) 11 | 12 | def draw(): 13 | background(200) 14 | beginShape() 15 | for x,y in poly: vertex(x,y) 16 | endShape(CLOSE) 17 | 18 | run() 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/reference/specular.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(100, 100); 4 | background(0); 5 | noStroke(); 6 | background(0); 7 | fill(0, 51, 102); 8 | lightSpecular(255, 255, 255); 9 | directionalLight(204, 204, 204, 0, 0, -1); 10 | translate(20, 50, 0); 11 | specular(255, 255, 255); 12 | sphere(30); 13 | translate(60, 0, 0); 14 | specular(204, 102, 0); 15 | sphere(30); 16 | 17 | run() 18 | -------------------------------------------------------------------------------- /examples/reference/keycode.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | fillVal = color(126); 4 | 5 | def draw(): 6 | fill(fillVal); 7 | rect(25, 25, 50, 50); 8 | 9 | def keyPressed(): 10 | global fillVal 11 | if (key.char == CODED): 12 | if (key.code == UP): 13 | fillVal = 255; 14 | elif (key.code == DOWN): 15 | fillVal = 0; 16 | else: 17 | fillVal = 126; 18 | 19 | run() 20 | -------------------------------------------------------------------------------- /examples/reference/backgroundimage.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup() : 4 | global bg 5 | size(200,200) 6 | frameRate(30) 7 | bg = loadImage("images/doll.jpg") 8 | 9 | def draw(): 10 | global bg, a 11 | background(bg) 12 | a = (a + 1)%(width+32); 13 | stroke(226, 204, 0); 14 | line(0, a, width, a-26); 15 | line(0, a-6, width, a-32); 16 | 17 | 18 | a = 0 19 | run() 20 | -------------------------------------------------------------------------------- /examples/reference/bezierdetail.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(100, 100); 5 | noFill(); 6 | noLoop() 7 | 8 | def draw(): 9 | bezierDetail(1); 10 | bezier(85, 20, 10, 10, 90, 90, 15, 80); 11 | stroke(126); 12 | bezierDetail(3); 13 | bezier(85, 20, 10, 10, 90, 90, 15, 80); 14 | stroke(255); 15 | bezierDetail(12); 16 | bezier(85, 20, 10, 10, 90, 90, 15, 80); 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/reference/lerpcolor.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | stroke(255); 4 | background(51); 5 | frm = color(204, 102, 0); 6 | to = color(0, 102, 153); 7 | interA = lerpColor(frm, to, .33); 8 | interB = lerpColor(frm, to, .66); 9 | fill(frm); 10 | rect(10, 20, 20, 60); 11 | fill(interA); 12 | rect(30, 20, 20, 60); 13 | fill(interB); 14 | rect(50, 20, 20, 60); 15 | fill(to); 16 | rect(70, 20, 20, 60); 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/reference/mouseclicked.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | # Click within the image to change 5 | # the value of the rectangle after 6 | # after the mouse has been clicked 7 | 8 | value = 0; 9 | 10 | def draw(): 11 | fill(value); 12 | rect(25, 25, 50, 50); 13 | 14 | def mouseClicked(): 15 | global value 16 | if(value == 0): 17 | value = 255; 18 | else: 19 | value = 0; 20 | 21 | run() 22 | -------------------------------------------------------------------------------- /examples/reference/mousebutton.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Click within the image and press 4 | # the left and right mouse buttons to 5 | # change the value of the rectangle 6 | def draw(): 7 | if (mouse.pressed and (mouse.button == LEFT)): 8 | fill(0); 9 | elif (mouse.pressed and (mouse.button == RIGHT)): 10 | fill(255); 11 | else: 12 | fill(126); 13 | 14 | rect(25, 25, 50, 50); 15 | 16 | 17 | run() 18 | -------------------------------------------------------------------------------- /examples/reference/shininess.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | background(0); 4 | noStroke(); 5 | background(0); 6 | fill(0, 51, 102); 7 | ambientLight(102, 102, 102); 8 | lightSpecular(204, 204, 204); 9 | directionalLight(102, 102, 102, 0, 0, -1); 10 | specular(255, 255, 255); 11 | translate(30, 50, 0); 12 | shininess(1.0); 13 | sphere(20); 14 | translate(40, 0, 0); 15 | shininess(5.0); 16 | sphere(20); 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/reference/createimage.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | 5 | def setup(): 6 | global a 7 | size(200,200) 8 | a = createImage(120,120,'ARGB') 9 | for i in range(a.width*a.height): 10 | a.pixels[i] = color(0,90,102, i%a.width * 2) 11 | a.updatePixels() 12 | 13 | 14 | def draw(): 15 | global a 16 | background(204) 17 | image(a, 33, 33) 18 | image(a, mouse.x - 60, mouse.y - 60) 19 | 20 | 21 | run() 22 | -------------------------------------------------------------------------------- /examples/misc/recursion.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup() : 4 | size(200, 200) 5 | noStroke() 6 | smooth() 7 | noLoop() 8 | 9 | def draw(): 10 | drawCircle (126, 170, 6) 11 | 12 | def drawCircle (x, radius, level): 13 | fill(126 * level/4.0) 14 | ellipse(x, 100, radius*2, radius*2) 15 | if level > 1: 16 | level = level - 1 17 | drawCircle(x - radius/2, radius/2, level) 18 | drawCircle(x + radius/2, radius/2, level) 19 | 20 | run() 21 | -------------------------------------------------------------------------------- /examples/reference/applymatrix.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | translate(50, 50, 0); 5 | rotateY(PI/6); 6 | stroke(153); 7 | box(35); 8 | # Set rotation angles 9 | ct = math.cos(PI/9.0); 10 | st = math.sin(PI/9.0); 11 | #Matrix for rotation around the Y axis 12 | applyMatrix( ct, 0.0, st, 0.0, 13 | 0.0, 1.0, 0.0, 0.0, 14 | -st, 0.0, ct, 0.0, 15 | 0.0, 0.0, 0.0, 1.0); 16 | stroke(255); 17 | box(50); 18 | 19 | run() 20 | -------------------------------------------------------------------------------- /examples/reference/keytyped.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | # Run this program to learn how each of these functions 5 | # relate to the others 6 | 7 | def draw(): pass # Empty draw() needed to keep the program running 8 | 9 | def keyPressed(): 10 | print "pressed ", ord(key.char), " ", key.code; 11 | 12 | def keyTyped(): 13 | print "typed ", ord(key.char), " ", key.code; 14 | 15 | def keyReleased() : 16 | print "released ", ord(key.char), " ", key.code; 17 | 18 | 19 | run() 20 | -------------------------------------------------------------------------------- /examples/misc/falloff.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(200,200) 5 | noStroke() 6 | 7 | def draw(): 8 | background(200) 9 | if mouse.pressed: lightFalloff(1,0,1e-4) 10 | pointLight(255,255,255,100,100,50) 11 | nx = 6 12 | ny = 6 13 | for i in range(nx): 14 | for j in range(ny): 15 | pushMatrix() 16 | translate((i+0.5)*width/nx,(j+0.5)*height/ny) 17 | sphere(10) 18 | popMatrix() 19 | 20 | run() 21 | -------------------------------------------------------------------------------- /examples/reference/curvepoint.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill() 4 | curve(5, 26, 5, 26, 73, 24, 73, 61); 5 | curve(5, 26, 73, 24, 73, 61, 15, 65); 6 | ellipseMode(CENTER); 7 | steps = 6; 8 | fill(255) 9 | for i in range(steps+1): 10 | t = i / float(steps); 11 | x = curvePoint(5, 5, 73, 73, t); 12 | y = curvePoint(26, 26, 24, 61, t); 13 | ellipse(x, y, 5, 5); 14 | x = curvePoint(5, 73, 73, 15, t); 15 | y = curvePoint(26, 24, 61, 65, t); 16 | ellipse(x, y, 5, 5); 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/reference/curvetangent.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | from math import atan2, cos, sin 3 | 4 | noFill() 5 | curve(5, 26, 73, 24, 73, 61, 15, 65) 6 | steps = 6; 7 | for i in range(steps+1): 8 | t = i / float(steps); 9 | x = curvePoint(5, 73, 73, 15, t); 10 | y = curvePoint(26, 24, 61, 65, t); 11 | #ellipse(x, y, 5, 5); 12 | tx = curveTangent(5, 73, 73, 15, t); 13 | ty = curveTangent(26, 24, 61, 65, t); 14 | a = atan2(ty, tx); 15 | a -= PI/2.0; 16 | line(x, y, cos(a)*8 + x, sin(a)*8 + y); 17 | 18 | run() 19 | -------------------------------------------------------------------------------- /examples/reference/curvedetail.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(100, 100); 5 | noFill(); 6 | noLoop(); 7 | 8 | def draw(): 9 | curveDetail(1); 10 | drawCurves(-15); 11 | stroke(126); 12 | curveDetail(2); 13 | drawCurves(0); 14 | stroke(255); 15 | curveDetail(4); 16 | drawCurves(15); 17 | 18 | def drawCurves(y): 19 | curve( 5, 28+y, 5, 28+y, 73, 26+y, 73, 63+y); 20 | curve( 5, 28+y, 73, 26+y, 73, 63+y, 15, 67+y); 21 | curve(73, 26+y, 73, 63+y, 15, 67+y, 15, 67+y); 22 | 23 | run() 24 | -------------------------------------------------------------------------------- /examples/reference/resetmatrix.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill(); 4 | box(80); 5 | printMatrix(); 6 | # Processing prints 7 | # 01.0000 00.0000 00.0000 -50.0000 8 | # 00.0000 01.0000 00.0000 -50.0000 9 | # 00.0000 00.0000 01.0000 -86.6025 10 | # 00.0000 00.0000 00.0000 01.0000 11 | 12 | resetMatrix(); 13 | box(80); 14 | printMatrix(); 15 | # Prints: 16 | # 1.0000 0.0000 0.0000 0.0000 17 | # 0.0000 1.0000 0.0000 0.0000 18 | # 0.0000 0.0000 1.0000 0.0000 19 | # 0.0000 0.0000 0.0000 1.0000 20 | 21 | run() 22 | -------------------------------------------------------------------------------- /examples/misc/boxandsphere.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | import math 3 | import OpenGL.GL as gl 4 | 5 | def setup(): 6 | size(200,200) 7 | noLoop() 8 | 9 | def draw(): 10 | # clear the whole screen 11 | background(200) 12 | lights() 13 | noStroke() 14 | background(200) 15 | pushMatrix() 16 | fill(255,255,0) 17 | translate(130,130) 18 | rotate(PI/6,1,1,0) 19 | box(50) 20 | popMatrix() 21 | fill(255,0,255) 22 | translate(60, 50) 23 | sphere(50) 24 | 25 | 26 | run() 27 | -------------------------------------------------------------------------------- /examples/usage/animation.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | balls = [(20,20,2.5,3,10),(100,50,-3.5,-3,15)] 4 | 5 | def setup(): 6 | size(150,150) 7 | ellipseMode(CENTER) 8 | noStroke() 9 | 10 | def draw(): 11 | fill(200,50) 12 | rect(0,0,150,150) 13 | fill(0) 14 | for i in range(len(balls)): 15 | x,y,dx,dy,r = balls[i] 16 | x += dx 17 | if constrain(x,r,150-r) != x: dx = -dx 18 | y += dy 19 | if constrain(y,r,150-r) != y: dy = -dy 20 | balls[i] = x,y,dx,dy,r 21 | ellipse(x,y,r,r) 22 | 23 | run() 24 | -------------------------------------------------------------------------------- /examples/misc/circles.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | size(300,300) 4 | hint(DISABLE_DEPTH_TEST) 5 | smooth() 6 | 7 | l = [] 8 | 9 | def mousePressed(): 10 | l.append ([mouse.x,mouse.y,1]) 11 | 12 | def mouseDragged(): 13 | l.append ([mouse.x,mouse.y,1]) 14 | 15 | def draw(): 16 | fill(0,10) 17 | noStroke() 18 | rect(0,0,width,height) 19 | stroke(255) 20 | nl = l[:] 21 | l[:]=[] 22 | for x,y,w in nl: 23 | g = 255-w 24 | if g<0: continue 25 | stroke(g) 26 | ellipse(x,y,w,w) 27 | l.append([x,y,w+2]) 28 | 29 | run() 30 | -------------------------------------------------------------------------------- /examples/misc/orthoandperspective.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(640, 360); 5 | noStroke(); 6 | fill(204); 7 | 8 | def draw(): 9 | background(0); 10 | lights(); 11 | if (mouse.pressed): 12 | fov = PI/3.0; 13 | cameraZ = (height/2.0) / tan(fov / 2.0); 14 | perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0); 15 | else: 16 | ortho(-width/2, width/2, -height/2, height/2, -height, height); 17 | 18 | translate(width/2, height/2, 0); 19 | rotateX(-PI/6); 20 | rotateY(PI/3); 21 | box(160); 22 | 23 | 24 | run() 25 | -------------------------------------------------------------------------------- /examples/reference/screenx.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(100, 100); 5 | 6 | 7 | def draw(): 8 | background(204); 9 | 10 | x = mouse.x; 11 | y = mouse.y; 12 | z = -100; 13 | 14 | # Draw "X" at z = -100 15 | stroke(255); 16 | line(x-10, y-10, z, x+10, y+10, z); 17 | line(x+10, y-10, z, x-10, y+10, z); 18 | 19 | # Draw line in 2D at same x value 20 | # Notice the parallax 21 | stroke(102); 22 | line(x, 0, 0, x, height, 0); 23 | 24 | # Draw 2D line to match the x value 25 | # element drawn at z = -100 26 | stroke(0); 27 | theX = screenX(x, y, z); 28 | line(theX, 0, 0, theX, height, 0); 29 | 30 | run() 31 | -------------------------------------------------------------------------------- /examples/handbook/3D_02.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Draw a sphere on top of a box and moves the coordinates with the mouse 4 | # Press a mouse button to turn on the lights 5 | def setup(): 6 | size(400, 400); 7 | 8 | def draw(): 9 | background(0); 10 | if mouse.pressed == True: 11 | # If the mouse is pressed, 12 | lights(); # turn on lights 13 | noStroke(); 14 | pushMatrix(); 15 | translate(mouse.x, mouse.y, -500); 16 | rotateY(PI / 6); # Rotate around y-axis 17 | box(400, 100, 400); # Draw box 18 | pushMatrix(); 19 | popMatrix(); 20 | translate(0, -200, 0); # Position the sphere 21 | sphere(150); # Draw sphere on top of box 22 | popMatrix(); 23 | 24 | run() 25 | -------------------------------------------------------------------------------- /examples/reference/filter.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | 4 | def setup(): 5 | global i1,i2,i3,i4,i5,i6 6 | size(200,300) 7 | frameRate(30) 8 | i1 = loadImage("images/arch.jpg") 9 | i2 = loadImage("images/arch.jpg") 10 | i3 = loadImage("images/arch.jpg") 11 | i4 = loadImage("images/arch.jpg") 12 | i5 = loadImage("images/arch.jpg") 13 | i6 = loadImage("images/arch.jpg") 14 | i1.filter(GRAY) 15 | i2.filter(THRESHOLD,0.4) 16 | i3.filter(POSTERIZE,5) 17 | i4.filter(DILATE) 18 | i5.filter(INVERT) 19 | i6.filter(OPAQUE) 20 | 21 | 22 | 23 | def draw(): 24 | global i1,i2,i3,i4,i5,i6 25 | image(i1,0,0) 26 | image(i2,100,0) 27 | image(i3,0,100) 28 | image(i4,100,100) 29 | image(i5,0,200) 30 | image(i6,100,200) 31 | 32 | 33 | 34 | run() 35 | -------------------------------------------------------------------------------- /examples/handbook/05_waves.py: -------------------------------------------------------------------------------- 1 | """ 2 | Adapted from 3 | /** 4 | * Synthesis 1: Form and Code 5 | * Riley Waves by Casey Reas (www.processing.org) 6 | * p. 151 7 | * 8 | * Step 3, values are modified to create a new pattern. 9 | */ 10 | """ 11 | 12 | from pyprocessing import * 13 | 14 | size(1200, 280); 15 | background(255); 16 | smooth(); 17 | noStroke(); 18 | #fill(0); 19 | angle = PI; 20 | angle2 = PI; 21 | magnitude = 3; 22 | 23 | for i in range(-magnitude,height+magnitude,12): 24 | 25 | angle2 = angle; 26 | 27 | fill(0); 28 | beginShape(TRIANGLE_STRIP); 29 | for x in range(0,width+1,8): 30 | y = i + (sin(angle)* magnitude); 31 | angle += PI/24.0; 32 | y2 = i+4 + (sin(angle+PI/12)* magnitude); 33 | vertex(x, y); 34 | vertex(x, y2); 35 | endShape(); 36 | 37 | run() 38 | -------------------------------------------------------------------------------- /examples/reference/beziertangent.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | noFill() 4 | bezier(85, 20, 10, 10, 90, 90, 15, 80); 5 | steps = 6; 6 | fill(255); 7 | for i in range(steps+1): 8 | t = i / float(steps); 9 | # Get the location of the point 10 | x = bezierPoint(85, 10, 90, 15, t); 11 | y = bezierPoint(20, 10, 90, 80, t); 12 | # Get the tangent points 13 | tx = bezierTangent(85, 10, 90, 15, t); 14 | ty = bezierTangent(20, 10, 90, 80, t); 15 | # Calculate an angle from the tangent points 16 | a = math.atan2(ty, tx); 17 | a += PI; 18 | stroke(255, 102, 0); 19 | line(x, y, math.cos(a)*30 + x, math.sin(a)*30 + y); 20 | # This follwing line of code makes a line 21 | # inverse of the above line 22 | # line(x, y, cos(a)*-30 + x, sin(a)*-30 + y); 23 | stroke(0); 24 | ellipse(x, y, 5, 5); 25 | 26 | run() 27 | -------------------------------------------------------------------------------- /examples/reference/modelx.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | def setup(): 4 | size(500, 500); 5 | noFill(); 6 | 7 | def draw(): 8 | background(0); 9 | 10 | pushMatrix(); 11 | # start at the middle of the screen 12 | translate(width/2, height/2, -200); 13 | # some random rotation to make things interesting 14 | rotateY(1.0); #yrot); 15 | rotateZ(2.0); #zrot); 16 | # rotate in X a little more each frame 17 | rotateX(frame.count / 100.0); 18 | # offset from center 19 | translate(0, 150, 0); 20 | 21 | # draw a white box outline at (0, 0, 0) 22 | stroke(255); 23 | box(50); 24 | 25 | # the box was drawn at (0, 0, 0), store that location 26 | 27 | x = modelX(0, 0, 0); 28 | y = modelY(0, 0, 0); 29 | z = modelZ(0, 0, 0); 30 | 31 | # clear out all the transformations 32 | popMatrix(); 33 | 34 | # draw another box at the same (x, y, z) coordinate as the other 35 | pushMatrix(); 36 | translate(x, y, z); 37 | stroke(255, 0, 0); 38 | box(50); 39 | popMatrix(); 40 | 41 | 42 | run() 43 | -------------------------------------------------------------------------------- /pyprocessing/materials.py: -------------------------------------------------------------------------------- 1 | #************************ 2 | # MATERIAL PROPERTIES 3 | #************************ 4 | 5 | import ctypes 6 | from pyglet.gl import * 7 | from globs import * 8 | from constants import * 9 | from colors import _getColor 10 | 11 | __all__=['emissive', 'shininess', 'specular', 'ambient'] 12 | 13 | def emissive(*args): 14 | """Emission material Properties""" 15 | color = _getColor(*args) 16 | glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, (ctypes.c_float * 4)(*color)) 17 | 18 | def shininess(shine): 19 | """Specular reflection material properties.""" 20 | glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shine) 21 | 22 | def specular(*args): 23 | """Specular reflection material properties.""" 24 | color = _getColor(*args) 25 | glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, (ctypes.c_float * 4)(*color)) 26 | 27 | def ambient(*args): 28 | """Ambient reflection material properties.""" 29 | color = _getColor(*args) 30 | glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, (ctypes.c_float * 4)(*color)) 31 | 32 | -------------------------------------------------------------------------------- /examples/misc/triflower.py: -------------------------------------------------------------------------------- 1 | """ 2 | Adapted from the TriFlower sketch of Ira Greenberg 3 | """ 4 | 5 | # 6 | # Triangle Flower 7 | # by Ira Greenberg. 8 | # 9 | # Using rotate() and triangle() functions generate a pretty 10 | # flower. Uncomment the line "// rotate(rot+=radians(spin));" 11 | # in the triBlur() function for a nice variation. 12 | # 13 | 14 | from pyprocessing import * 15 | 16 | p = [None]*3 17 | shift = 1.0 18 | fade = 0 19 | fillCol = 0 20 | rot = 0 21 | spin = 0 22 | 23 | def setup(): 24 | size(200, 200); 25 | background(0); 26 | smooth(); 27 | global fade,spin 28 | fade = 255.0/(width/2.0/shift); 29 | spin = 360.0/(width/2.0/shift); 30 | p[0] = PVector (-width/2, height/2) 31 | p[1] = PVector (width/2, height/2) 32 | p[2] = PVector (0, -height/2) 33 | noStroke() 34 | translate(width/2, height/2) 35 | triBlur() 36 | 37 | def triBlur(): 38 | global fillCol,rot 39 | fill(fillCol) 40 | fillCol+=fade 41 | rotate(spin) 42 | # another interesting variation: uncomment the line below 43 | # rot+=radians(spin); rotate(rot) 44 | p[0].x+=shift; p[0].y-=shift; p[1].x-=shift; p[1].y-=shift; p[2].y+=shift; 45 | triangle (p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y) 46 | if p[0].x<0: 47 | # recursive call 48 | triBlur() 49 | 50 | run() 51 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding:utf-8 3 | 4 | from distutils.core import setup 5 | 6 | def get_version(): 7 | from os.path import dirname, join 8 | for line in open(join(dirname(__file__), 'pyprocessing/constants.py')): 9 | if 'version' in line: 10 | version = line.split('"')[1] 11 | return version 12 | 13 | long_description = ''' 14 | This Python package provides an environment for graphics applications that 15 | closely resembles that of the Processing system. 16 | 17 | The project mission is to implement Processing's friendly graphics 18 | functions and interaction model in Python. Not all of Processing is ported, 19 | though, since Python itself already provides alternatives for many features 20 | of Processing. 21 | 22 | The pyprocessing backend is built upon OpenGL and Pyglet, 23 | which provide the actual graphics rendering. Since these are multiplatform, 24 | so is pyprocessing. 25 | ''' 26 | 27 | # MAKE SURE THE VERSION BELOW IS THE SAME AS THAT IN CONSTANTS.PY! 28 | 29 | setup(name='pyprocessing', 30 | version=get_version(), 31 | description='A Processing-like environment for Python', 32 | long_description=long_description, 33 | author='Claudio Esperanca', 34 | author_email='claudio.esperanca@gmail.com', 35 | url='http://code.google.com/p/pyprocessing/', 36 | license='BSD', 37 | packages=['pyprocessing'], 38 | install_requires = ["pyglet>=1.1.4"], 39 | ) 40 | 41 | -------------------------------------------------------------------------------- /examples/misc/fpstest.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | from random import random 3 | 4 | # Choose the total number of bouncing balls 5 | nballs = 100 6 | balls = [] 7 | 8 | def setup(): 9 | hint('DOUBLE_FLIP_POLICY') 10 | size(400,400) 11 | smooth() 12 | noStroke() 13 | colorMode(HSB,1.0) 14 | ellipseMode(CENTER) 15 | # generate n balls with random positions, sizes, speeds and colors 16 | for i in range(nballs): 17 | # position 18 | x = int(random()*width) 19 | y = int(random()*height) 20 | # speed 21 | vel = random()*4+2 22 | ang = random()*TWO_PI 23 | dx = vel*cos(ang) 24 | dy = vel*sin(ang) 25 | # radius 26 | r = random()*20+4 27 | # color 28 | c = color(random(),random()*0.5+0.5,random()*0.5+0.5) 29 | balls.append([x,y,dx,dy,r,c]) 30 | colorMode(RGB,256) 31 | 32 | def draw(): 33 | # fade the last frame by drawing background in transparent color 34 | fill(255,50) 35 | rect(0,0,width,height) 36 | # draw/bounce balls 37 | for i,(x,y,dx,dy,r,c) in enumerate(balls): 38 | fill(c) 39 | x += dx 40 | newx = constrain(x,r,width-r) 41 | if newx != x: dx,x = -dx,newx 42 | y += dy 43 | newy = constrain(y,r,height-r) 44 | if newy != y: dy,y = -dy,newy 45 | balls[i][0:4] = x,y,dx,dy 46 | ellipse(x,y,r,r) 47 | fill(0) 48 | text("%3d"%frame.rate,0,20) 49 | 50 | run() 51 | -------------------------------------------------------------------------------- /examples/reference/texture.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | #TexturedCube 4 | #by Dave Bollinger. 5 | #Drag mouse to rotate cube. Demonstrates use of u/v coords in 6 | #vertex() and effect on texture(). 7 | 8 | rotx = PI/4; 9 | roty = PI/4; 10 | 11 | def setup(): 12 | global tex 13 | size(640, 360); 14 | tex = loadImage("images/tex.jpg"); 15 | textureMode(NORMALIZED); 16 | fill(255); 17 | stroke(color(44,48,32)); 18 | 19 | def draw(): 20 | background(0); 21 | noStroke(); 22 | translate(width/2.0, height/2.0, -100); 23 | rotateX(rotx); 24 | rotateY(roty); 25 | scale(90); 26 | TexturedCube(tex); 27 | 28 | def TexturedCube(tex): 29 | beginShape(QUADS); 30 | texture(tex); 31 | vertex(-1, -1, 1, 0, 0); 32 | vertex( 1, -1, 1, 1, 0); 33 | vertex( 1, 1, 1, 1, 1); 34 | vertex(-1, 1, 1, 0, 1); 35 | vertex( 1, -1, -1, 0, 0); 36 | vertex(-1, -1, -1, 1, 0); 37 | vertex(-1, 1, -1, 1, 1); 38 | vertex( 1, 1, -1, 0, 1); 39 | vertex(-1, 1, 1, 0, 0); 40 | vertex( 1, 1, 1, 1, 0); 41 | vertex( 1, 1, -1, 1, 1); 42 | vertex(-1, 1, -1, 0, 1); 43 | vertex(-1, -1, -1, 0, 0); 44 | vertex( 1, -1, -1, 1, 0); 45 | vertex( 1, -1, 1, 1, 1); 46 | vertex(-1, -1, 1, 0, 1); 47 | vertex( 1, -1, 1, 0, 0); 48 | vertex( 1, -1, -1, 1, 0); 49 | vertex( 1, 1, -1, 1, 1); 50 | vertex( 1, 1, 1, 0, 1); 51 | vertex(-1, -1, -1, 0, 0); 52 | vertex(-1, -1, 1, 1, 0); 53 | vertex(-1, 1, 1, 1, 1); 54 | vertex(-1, 1, -1, 0, 1); 55 | endShape(); 56 | 57 | def mouseDragged(): 58 | global rotx,roty 59 | rate = 0.01; 60 | rotx += (pmouse.y-mouse.y) * rate; 61 | roty += (mouse.x-pmouse.x) * rate; 62 | 63 | run() 64 | -------------------------------------------------------------------------------- /examples/handbook/centipede.py: -------------------------------------------------------------------------------- 1 | """ 2 | Adapted from 3 | 4 | /** 5 | * Synthesis 3: Motion and Arrays 6 | * Centipede by Ariel Malka (www.chronotext.org) 7 | * p. 372 8 | */ 9 | """ 10 | from pyprocessing import * 11 | 12 | node_length = 30 13 | node_size = node_length-1 14 | n_nodes = 70 15 | nodes = [] 16 | delay = 20.0 17 | col_head = color(255, 0, 0) 18 | col_body = color(0) 19 | 20 | def setup(): 21 | size(600, 600) 22 | smooth() 23 | noStroke() 24 | 25 | global x,y 26 | x = width/2 27 | y = height/2 28 | 29 | r1 = 10 30 | r2 = 100 31 | dr = r2-r1 32 | D = 0.0 33 | 34 | for i in range(n_nodes): 35 | r = sqrt(r1 * r1 + 2.0 * dr * D); 36 | d = (r - r1) / dr; 37 | 38 | nodes.append((x - sin(d) * r, y + cos(d) * r)) 39 | 40 | D += node_length; 41 | 42 | 43 | def draw(): 44 | background(204); 45 | 46 | # Set the position of the head 47 | setTarget(mouse.x, mouse.y) 48 | 49 | # Draw the head 50 | fill(col_head) 51 | ellipse(nodes[0][0], nodes[0][1], node_size, node_size); 52 | 53 | # Draw the body 54 | fill(col_body); 55 | for x,y in nodes[1:]: 56 | ellipse(x,y, node_size, node_size) 57 | 58 | 59 | def setTarget(tx, ty): 60 | # Motion interpolation for the head 61 | global x,y 62 | x += (tx - x) / delay; 63 | y += (ty - y) / delay; 64 | nodes[0] = (x,y) 65 | 66 | # Constrained motion for the other nodes 67 | for i in range(1,n_nodes): 68 | dx = nodes[i - 1][0] - nodes[i][0] 69 | dy = nodes[i - 1][1] - nodes[i][1] 70 | length = sqrt(sq(dx) + sq(dy)) 71 | nodes[i] = (nodes[i - 1][0] - (dx/length * node_length), 72 | nodes[i - 1][1] - (dy/length * node_length)) 73 | 74 | run() 75 | 76 | -------------------------------------------------------------------------------- /examples/handbook/3D_03.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | 3 | # Draw a cylinder centered on the y-axis, going down from y=0 to y=height. 4 | # The radius at the top can be different from the radius at the bottom, 5 | # and the number of sides drawn is variable. 6 | 7 | def setup() : 8 | size(400, 400); 9 | 10 | def draw(): 11 | background(0); 12 | lights(); 13 | translate(width / 2, height / 2); 14 | rotateY(mouse.x * PI / width); 15 | rotateZ(mouse.y * -PI / height); 16 | noStroke(); 17 | fill(255, 255, 255); 18 | translate(0, -40, 0); 19 | drawCylinder(10, 180, 200, 16); # Draw a mix between a cylinder and a cone 20 | #drawCylinder(70, 70, 120, 16); # Draw a cylinder 21 | #drawCylinder(0, 180, 200, 4); # Draw a pyramid 22 | 23 | def drawCylinder(topRadius, bottomRadius, tall, sides): 24 | angle = 0; 25 | angleIncrement = TWO_PI / sides; 26 | beginShape(QUAD_STRIP); 27 | for i in range(sides+1): 28 | #normal(cos(angle),sin(angle),0) 29 | vertex(topRadius*cos(angle), 0, topRadius*sin(angle)); 30 | vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle)); 31 | angle += angleIncrement; 32 | endShape(); 33 | 34 | # If it is not a cone, draw the circular top cap 35 | if (topRadius != 0): 36 | angle = 0; 37 | beginShape(TRIANGLE_FAN); 38 | 39 | # Center point 40 | vertex(0, 0, 0); 41 | for i in range(sides+1): 42 | vertex(topRadius * cos(angle), 0, topRadius * sin(angle)); 43 | angle += angleIncrement; 44 | endShape(); 45 | 46 | # If it is not a cone, draw the circular bottom cap 47 | if (bottomRadius != 0): 48 | angle = 0; 49 | beginShape(TRIANGLE_FAN); 50 | 51 | # Center point 52 | vertex(0, tall, 0); 53 | for i in range(sides+1): 54 | vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle)); 55 | angle += angleIncrement; 56 | 57 | endShape(); 58 | 59 | run() 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WHAT IS THIS? 2 | 3 | The pyprocessing project provides a Python package that creates an environment 4 | for graphics applications that closely resembles that of the Processing system. 5 | Usage is mostly restricted to importing the package and calling run(). 6 | 7 | The project mission is to implement Processing's friendly graphics functions and 8 | interaction model in Python. Not all of Processing is to be ported, though, 9 | since Python itself already provides alternatives for many features of 10 | Processing, such as XML parsing. 11 | 12 | The pyprocessing backend is built upon OpenGL and Pyglet, which provide the 13 | actual graphics rendering. Since these are multiplatform, so is pyprocessing. 14 | 15 | We hope that, much in the same spirit of the Processing project, pyprocessing 16 | will appeal to people who want to easily program and interact with computer 17 | generated imagery. It is also meant to help teaching computer programming by 18 | making it possible to write compact code with rich visual semantics. 19 | 20 | WHAT ARE THE REQUIREMENTS? 21 | 22 | In essence, all you need is the pyglet package (see www.pyglet.org) and its 23 | requirements, i.e., OpenGL and Python (2.5 or 2.6). If you are able to run 24 | pyglet's sample programs, you are in good shape to run pyprocessing. 25 | 26 | HOW TO INSTALL IT? 27 | 28 | Put the pyprocessing directory (the one which contains __init__.py, attribs.py, 29 | etc) in any place Python expects to find modules and packages. The simplest 30 | way of achieving this is to run the provided setup.py program: 31 | 32 | python setup.py install 33 | 34 | This will copy the files to the proper places. You might have to have 35 | administration privileges to do this, however. In most flavors of Linux, for 36 | instance, you might have to type: 37 | 38 | sudo python setup.py install 39 | 40 | HOW TO USE IT? 41 | 42 | There are several example programs in the examples folder that you may try. 43 | You may also take a look at the [project wiki](../../wiki) 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /tools/accumfliptest.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is a simple application intended to test the accumulation buffer flip 3 | policy of pyprocessing. If everything works as intended, you should see 4 | a rotating square... 5 | """ 6 | 7 | def usage(): 8 | print "Usage:", sys.argv[0], "--accum | --fbo | --single | --double" 9 | print "where --accum tests the accumulation flip policy (default)," 10 | print " --fbo tests the frame buffer object flip policy," 11 | print " --single tests the single buffer flip policy" 12 | print " --double tests the double buffer flip policy" 13 | 14 | import pyglet,sys 15 | from pyglet.gl import * 16 | from flippolicy import * 17 | fps_display = pyglet.clock.ClockDisplay(color=(1, 1, 1, 1),) 18 | 19 | if len(sys.argv)==1 or sys.argv[1]=="--accum": 20 | win = AccumWindow(200,200) 21 | elif sys.argv[1]=="--double": 22 | win = PyprocessingWindow(200,200) 23 | elif sys.argv[1]=="--fbo": 24 | win = FBOWindow(200,200) 25 | elif sys.argv[1]=="--single": 26 | win = SingleBufferWindow(200,200) 27 | else: 28 | print "Unrecognized argument:",sys.argv[1] 29 | usage() 30 | sys.exit(-1) 31 | 32 | ang = 0 33 | 34 | @win.event 35 | def on_draw(): 36 | glEnable(GL_BLEND) 37 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 38 | glMatrixMode(GL_PROJECTION) 39 | glLoadIdentity() 40 | glMatrixMode(GL_MODELVIEW) 41 | glLoadIdentity() 42 | glColor4f(0,0,0,0.05) 43 | glRectf(-1,-1,1,1) 44 | global ang 45 | ang += 1 46 | glRotatef(ang,0,0,1) 47 | glEnable(GL_POLYGON_SMOOTH) 48 | glEnable(GL_LINE_SMOOTH) 49 | glEnable(GL_POINT_SMOOTH) 50 | glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) 51 | pt = [(-0.5,-0.5,0),(0.5,-0.5,0),(0.5,0.5,0),(-0.5,0.5,0)] 52 | glColor4f(1,1,1,0.5) 53 | glBegin(GL_QUADS) 54 | for p in pt: glVertex3f(*p) 55 | glEnd() 56 | glColor4f(0,1,1,0.8) 57 | glPointSize(10) 58 | glBegin(GL_POINTS) 59 | for p in pt: glVertex3f(*p) 60 | glEnd() 61 | 62 | def dummy(t): pass 63 | 64 | pyglet.clock.schedule_interval(dummy,1.0/30) 65 | pyglet.app.run() 66 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | WHAT IS THIS? 2 | 3 | The pyprocessing project provides a Python package that creates an environment 4 | for graphics applications that closely resembles that of the Processing system. 5 | Usage is mostly restricted to importing the package and calling run(). 6 | 7 | The project mission is to implement Processing's friendly graphics functions and 8 | interaction model in Python. Not all of Processing is to be ported, though, 9 | since Python itself already provides alternatives for many features of 10 | Processing, such as XML parsing. 11 | 12 | The pyprocessing backend is built upon OpenGL and Pyglet, which provide the 13 | actual graphics rendering. Since these are multiplatform, so is pyprocessing. 14 | 15 | We hope that, much in the same spirit of the Processing project, pyprocessing 16 | will appeal to people who want to easily program and interact with computer 17 | generated imagery. It is also meant to help teaching computer programming by 18 | making it possible to write compact code with rich visual semantics. 19 | 20 | WHAT ARE THE REQUIREMENTS? 21 | 22 | In essence, all you need is the pyglet package (see www.pyglet.org) and its 23 | requirements, i.e., OpenGL and Python (2.5 or 2.6). If you are able to run 24 | pyglet's sample programs, you are in good shape to run pyprocessing. 25 | 26 | HOW TO INSTALL IT? 27 | 28 | Put the pyprocessing directory (the one which contains __init__.py, attribs.py, 29 | etc) in any place Python expects to find modules and packages. The simplest 30 | way of achieving this is to run the provided setup.py program: 31 | 32 | python setup.py install 33 | 34 | This will copy the files to the proper places. You might have to have 35 | administration privileges to do this, however. In most flavors of Linux, for 36 | instance, you might have to type: 37 | 38 | sudo python setup.py install 39 | 40 | Alternatively, if you are running some flavor of MS-Windows, there is a binary 41 | installation file which you will find in the pyprocessing site 42 | (http://code.google.com/p/pyprocessing/downloads). 43 | 44 | HOW TO USE IT? 45 | 46 | There are several example programs in the examples folder that you may try. 47 | You may also take a look at the project wiki for simple usage instructions 48 | (http://code.google.com/p/pyprocessing/wiki/UsageInstructions) 49 | 50 | 51 | -------------------------------------------------------------------------------- /pyprocessing/config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Holds system wide configuration options. 3 | """ 4 | 5 | from constants import * 6 | import os 7 | 8 | 9 | """"The preferences below are used as defaults if none of the configuration 10 | files exist. Being defaults, they have the lowest priority of the importing 11 | procedure.""" 12 | 13 | # Whether or not to try to obtain an OpenGL context supporting multisampling. 14 | # This usually produces nicer results but is unsupported in older hardware. 15 | # Even if this is set to false, however, pyprocessing will fallback to 16 | # a non-multisampled config if it is not supported. 17 | multisample = True 18 | 19 | # Whether or not to invert the y axis. This is required for strict conformity 20 | # with Processing. Beyond altering the modelview matrix, this also implies that 21 | # the drawing of some primitives such as arc or text be modified. 22 | coordInversionHack = True 23 | 24 | # Since OpenGL actually addresses lines between pixels, in some cases 25 | # shifting the drawing by half a pixel makes lines sharper. 26 | halfPixelShiftHack = False # off by default 27 | 28 | # try to get around the artifacts when drawing filled polygons in smooth mode 29 | smoothFixHack = False # off by default 30 | smoothTurnedOn = False # Used internally to tell whether smooth was on 31 | 32 | # flipping policy: uncomment only one of the assignments below 33 | # flipPolicy = DOUBLE_FLIP_POLICY # this should work for modern boards/drivers 34 | # flipPolicy = SINGLE_FLIP_POLICY # use this for Intel 945 under Windows or other cheap boards 35 | # flipPolicy = FBO_FLIP_POLICY # use this for modern boards/drivers where flip uses swap and not copy 36 | # flipPolicy = ACCUM_FLIP_POLICY # use this for cheap boards where 'SINGLE' produces too much flickering 37 | flipPolicy = BACKUP_FLIP_POLICY # this is the default and should work on all boards 38 | 39 | 40 | 41 | 42 | """Tries to import the global preferences from the globalconfig.txt file 43 | located inside the pyprocessing installation folder. These preferences 44 | have higher priority than defaults, but will be overriden by the user 45 | preferences if they exist.""" 46 | 47 | try: 48 | f = open(os.path.dirname(__file__)+"/globalconfig.txt","r") 49 | contents = f.read() 50 | contents = contents.split("\n") 51 | for i in contents: 52 | if i != "": vars()[i.split(":")[0]] = eval(i.split(":")[1]) 53 | except: 54 | None 55 | 56 | 57 | 58 | 59 | """Loads the user configuration preferences from the userconfig.txt file situated 60 | on the user's home path. Like the global preferences, they can be changed manually 61 | with a text editor. User preferences have the highest priority, meaning that if 62 | the import from userconfig.txt is successful, then the global preferencesill 63 | be overriden.""" 64 | 65 | try: 66 | f = open(os.path.expanduser("~/.pyprocessing/userconfig.txt"),"r") 67 | contents = f.read() 68 | contents = contents.split("\n") 69 | for i in contents: 70 | if i != "": vars()[i.split(":")[0]] = eval(i.split(":")[1]) 71 | except: 72 | None 73 | -------------------------------------------------------------------------------- /tools/flip_setup.py: -------------------------------------------------------------------------------- 1 | from pyprocessing import * 2 | from random import random 3 | import sys 4 | import os 5 | 6 | nballs = 100 7 | balls = [] 8 | 9 | 10 | """This script is aimed at users who don't know which Flip Policy is 11 | best suited for their hardware setup. It will automatically display a 12 | simple pyprocessing example and give the user options to say if the 13 | graphics are displayed correctly: if not, then the setup will change 14 | the Flip Policy automatically and run itself again.""" 15 | 16 | 17 | 18 | 19 | def setup(): 20 | global policy 21 | if '-nodouble' not in sys.argv: 22 | hint(DOUBLE_FLIP_POLICY) 23 | policy = DOUBLE_FLIP_POLICY 24 | size(400,400) 25 | smooth() 26 | noStroke() 27 | colorMode(HSB,1.0) 28 | ellipseMode(CENTER) 29 | for i in range(nballs): 30 | x = int(random()*width) 31 | y = int(random()*height) 32 | vel = random()*4+2 33 | ang = random()*TWO_PI 34 | dx = vel*cos(ang) 35 | dy = vel*sin(ang) 36 | r = random()*20+4 37 | c = color(random(),random()*0.5+0.5,random()*0.5+0.5) 38 | balls.append([x,y,dx,dy,r,c]) 39 | colorMode(RGB,256) 40 | 41 | def draw(): 42 | fill(255,50) 43 | rect(0,0,width,height-100) 44 | for i,(x,y,dx,dy,r,c) in enumerate(balls): 45 | fill(c) 46 | x += dx 47 | newx = constrain(x,r,width-r) 48 | if newx != x: dx,x = -dx,newx 49 | y += dy 50 | newy = constrain(y,r,height-r-100) 51 | if newy != y: dy,y = -dy,newy 52 | balls[i][0:4] = x,y,dx,dy 53 | ellipse(x,y,r,r) 54 | fill(10,200,10) 55 | rect(0,height-100,width/2,100) 56 | fill(200,10,10) 57 | rect(width/2,height-100,width/2,100) 58 | fill(0) 59 | text("Yes, this config is ok",width/30,height-50) 60 | text("I'm seeing glitches",5*width/9,height-50) 61 | text("%3d"%frame.rate,0,20) 62 | 63 | def mouseClicked(): 64 | global contents, policy 65 | if (height - 100 < mouse.y < height): 66 | for i in range(len(contents)-1,-1,-1): 67 | if contents[i].find("flip") != -1 or contents[i] == "": 68 | del contents[i] 69 | if (mouse.x > width/2): 70 | if fbo.FBO.supported(): policy = FBO_FLIP_POLICY 71 | else: policy = BACKUP_FLIP_POLICY 72 | f = open(os.path.expanduser("~/.pyprocessing/userconfig.txt"),"w") 73 | contents.append("flipPolicy:"+policy) 74 | contents = '\n'.join(contents) 75 | f.write(contents) 76 | f.close() 77 | os.system('python %s -nodouble'%sys.argv[0]) 78 | sys.exit() 79 | else: 80 | if '-nodouble' in sys.argv: sys.exit() 81 | f = open(os.path.expanduser("~/.pyprocessing/userconfig.txt"),"w") 82 | contents.append("flipPolicy:"+policy) 83 | contents = '\n'.join(contents) 84 | f.write(contents) 85 | f.close() 86 | sys.exit() 87 | 88 | try: 89 | f = open(os.path.expanduser("~/.pyprocessing/userconfig.txt"),"r") 90 | contents = f.read() 91 | f.close() 92 | contents = contents.split('\n') 93 | except IOError: 94 | try: 95 | os.mkdir(os.path.expanduser("~/.pyprocessing")) 96 | except OSError: None 97 | contents = [] 98 | 99 | 100 | 101 | 102 | 103 | 104 | run() 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /pyprocessing/globs.py: -------------------------------------------------------------------------------- 1 | from constants import * 2 | import pyglet,os 3 | 4 | __all__ = ['mouse', 'pmouse', 'attrib', 'frame', 'key', 'canvas', 'shape', 5 | 'screen', 'callback'] 6 | 7 | #************************ 8 | # GLOBALS 9 | #************************ 10 | 11 | class mouse: 12 | """Stores mouse state""" 13 | pressed = False # Tells if any mouse button is pressed 14 | x = 0 # x coordinate of mouse 15 | y = 0 # y coordinate of mouse 16 | button = None # state of mouse buttons 17 | 18 | class pmouse: 19 | """Store previous position of mouse""" 20 | pressed = False # Tells if any mouse button is pressed 21 | x = 0 # x coordinate of mouse 22 | y = 0 # y coordinate of mouse 23 | savex = 0 # saved x from the previous frame 24 | savey = 0 # saved y from the previous frame 25 | button = None # state of mouse buttons 26 | 27 | class key: 28 | """Stores keyboard state""" 29 | char = "" 30 | code = 0 31 | modifiers = None 32 | pressed = False 33 | 34 | class canvas: 35 | """Stores the drawing window attributes""" 36 | window = None 37 | # These two symbols were relocated to the __builtin__ namespace 38 | #width = 100 39 | #height = 100 40 | 41 | class screen: 42 | """Current window properties.""" 43 | co = 2 44 | pixels = [] 45 | width = None 46 | height = None 47 | 48 | class attrib: 49 | """Drawing attributes""" 50 | strokeJoin = MITER 51 | strokeCap = SQUARE 52 | textureMode = IMAGE 53 | strokeColor = (0,0,0,1) 54 | fillColor = (1,1,1,1) 55 | tintColor = None 56 | strokeWeight = 1 57 | font = {} 58 | location = pyglet.resource.FileLocation(os.path.dirname(__file__)) 59 | rectMode = CORNER 60 | ellipseMode = CENTER 61 | imageMode = CORNER 62 | textAlign = (LEFT,BASELINE) 63 | # color attribs 64 | colorMode = RGB 65 | colorRange = (255.0,255.0,255.0,255.0) 66 | # light attribs 67 | lights = False 68 | lightCount = 0 69 | lightSpecular = (0,0,0,1) 70 | lightFalloff = (1, 0, 0) # constant, linear, quadratic 71 | # depth testing 72 | depthTest = True 73 | texture = False 74 | 75 | class frame: 76 | """Frame rate and the like.""" 77 | loop=True 78 | rate=10 # estimated frame rate 79 | targetRate = 60 # the target frame rate 80 | count=0 # number of frames displayed since the application started 81 | 82 | class shape: 83 | """Attributes for shapes.""" 84 | quadric = None # Stores a gluQuadricObject 85 | tess = None # Stores a gluTesselatorObject 86 | ellipseFillDL = None # Stores a display list for a filled ellipse 87 | ellipseStrokeDL = None # Stores a display list for an outline ellipse 88 | cubeFillVL = None # Stores a vertex list for drawing a cube with quads 89 | cubeStrokeVL = None # Stores a vertex list for drawing a cube with line segments 90 | type = None # stores the type of the shape as passed to function beginShape 91 | sphereDetail = (20,10) 92 | bezierDetail = 40 93 | curveDetail = 20 94 | ellipseDetail = 100 95 | tension = 0.5 96 | bezierBlend = [] 97 | vtx = [] 98 | nrm = [] 99 | 100 | 101 | class callback: 102 | """Call back functions.""" 103 | 104 | @staticmethod 105 | def dummy(*args): 106 | """A callback function that does nothing.""" 107 | pass 108 | 109 | """All of these are imported from the user space 110 | by the 'run' function or else fall back to dummy""" 111 | draw = mousePressed = mouseReleased = mouseClicked = mouseDragged = \ 112 | mouseMoved = keyPressed = keyReleased = keyTyped = exit = \ 113 | screenResized = dummy 114 | 115 | -------------------------------------------------------------------------------- /pyprocessing/attribs.py: -------------------------------------------------------------------------------- 1 | #************************ 2 | # ATTRIBUTES 3 | #************************ 4 | 5 | from globs import * 6 | from constants import * 7 | from pyglet.gl import * 8 | from colors import _getColor 9 | import config 10 | 11 | __all__=['stroke', 'noStroke', 'strokeWeight', 'fill', 'noFill', 'tint', 'noTint', 12 | 'smooth', 'noSmooth', 'ellipseMode', 'rectMode', 'imageMode', 'hint', 13 | 'texture', 'textureMode', 'strokeJoin', 'strokeCap'] 14 | 15 | def stroke(*color): 16 | """Sets color as color for drawing lines and shape borders.""" 17 | attrib.strokeColor = _getColor(*color) 18 | 19 | def noStroke(): 20 | """Omits line drawings""" 21 | attrib.strokeColor = None 22 | 23 | def strokeWeight (weight): 24 | """Sets line width for drawing outline objects""" 25 | if weight<=0: weight=0.001 26 | attrib.strokeWeight = weight 27 | 28 | def strokeCap(mode): 29 | attrib.strokeCap = mode 30 | 31 | def strokeJoin(mode): 32 | attrib.strokeJoin = mode 33 | 34 | def fill(*color): 35 | """Sets color as color for drawing filled shapes.""" 36 | attrib.fillColor = _getColor(*color) 37 | 38 | def tint(*color): 39 | """Sets color as a tint for drawing images.""" 40 | attrib.tintColor = _getColor(*color) 41 | 42 | def noTint(): 43 | """Undefines tint for drawing images.""" 44 | attrib.tintColor = None 45 | 46 | def noFill(): 47 | """Omits filled drawings""" 48 | attrib.fillColor = None 49 | 50 | def texture(filename): 51 | attrib.texture = filename 52 | 53 | def smooth(): 54 | """Sets state so that lines are rendered antialiased.""" 55 | attrib.smooth = True 56 | glEnable(GL_BLEND) 57 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 58 | glEnable(GL_LINE_SMOOTH) 59 | glEnable(GL_POINT_SMOOTH) 60 | glEnable(GL_POLYGON_SMOOTH) 61 | glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) 62 | 63 | def noSmooth(): 64 | """Sets state so that lines are rendered quickly.""" 65 | attrib.smooth = False 66 | glEnable(GL_BLEND) 67 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 68 | glDisable(GL_LINE_SMOOTH) 69 | glDisable(GL_POINT_SMOOTH) 70 | glDisable(GL_POLYGON_SMOOTH) 71 | 72 | def textureMode(mode): 73 | """Alters the meaning of the arguments of the ellipse function""" 74 | attrib.textureMode = mode 75 | 76 | def ellipseMode(mode): 77 | """Alters the meaning of the arguments of the ellipse function""" 78 | attrib.ellipseMode = mode 79 | 80 | def rectMode(mode): 81 | """Alters the meaning of the arguments of the rectangle function""" 82 | attrib.rectMode = mode 83 | 84 | def imageMode(mode): 85 | """Alters the meaning of the arguments of the image function""" 86 | attrib.imageMode = mode 87 | 88 | def hint(hintconst): 89 | """Sets/unsets configuration settings. 90 | * Depth testing can be set or unset using constants DISABLE_DEPTH_TEST and 91 | ENABLE_DEPTH_TEST (default=ON). 92 | * Polygon antialiasing can be turned on or off using ENABLE_POLYGON_SMOOTH 93 | and DISABLE_POLYGON_SMOOTH (default=OFF). 94 | * Flip policy can be selected using the constants DOUBLE_FLIP_POLICY, 95 | SINGLE_FLIP_POLICY, FBO_FLIP_POLICY and ACCUM_FLIP_POLICY 96 | """ 97 | if hintconst==ENABLE_DEPTH_TEST: 98 | attrib.depthTest = True 99 | glDepthFunc(GL_LEQUAL) 100 | glEnable(GL_DEPTH_TEST) 101 | elif hintconst==DISABLE_DEPTH_TEST: 102 | attrib.depthTest = False 103 | glDisable(GL_DEPTH_TEST) 104 | elif hintconst in (DOUBLE_FLIP_POLICY,SINGLE_FLIP_POLICY, 105 | FBO_FLIP_POLICY, ACCUM_FLIP_POLICY,BACKUP_FLIP_POLICY): 106 | config.flipPolicy=hintconst 107 | else: 108 | raise ValueError,"Unknown hint" 109 | 110 | -------------------------------------------------------------------------------- /tools/takesnapshot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Usage: takesnapshot.py [options] script.py 4 | 5 | This program is used to take snapshots of a pyprocessing 6 | application called script.py. 7 | 8 | Essentially, it runs a modified version of the given script which 9 | includes a call to save(). Command line arguments select one 10 | of the two supported modes of operation: 11 | 12 | --single=