The shadow is done using a circle with radial fading black gradient whose intensity diminishes when the ball is higher, for more realism (?). write_gif ( "balls.gif", fps = 15, opt = "OptimizePlus" ) VideoClip ( make_frame, duration = D ) clip. ColorGradient ( type = "radial", stops_colors =, xy1 =, xy2 =, x圓 = ) ball = gz. polar2cart ( W / 5, angle ) # center of the ball gradient = gz. Surface ( W, H ) for r, color, center in zip ( radii, colors, centers ): angle = 2 * np. randint ( 0, W, ( nballs, 2 )) def make_frame ( t ): surface = gz. Import gizeh as gz import numpy as np import moviepy.editor as mpy W = H = 150 D = 2 # duration nballs = 60 # generate random values of radius, color, center radii = np. I'm having a little trouble with the slide joint, but you can check out my code if you're curious: slide_and_pinjoint_example.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 The following screenshot shows the Slide and Pin Joint demo within NodeBox using my take on porting it. The example is written for PyGame so you'll be doing a little rewriting to bring it into NodeBox. If you're new to pymunk (as I was until this week) head over to the Slide and Pin Joint tutorial to see how it works. If you don't see any error messages, you're good to go. We should be done! Fire up NodeBox and try an include pymunk to see if it loads. > ln -s ~/Library/Application\ Support/NodeBox/pymunk/libchipmunk.dylib. > cd /Applications/NodeBox/NodeBox.app/Contents/MacOS/ įinally, NodeBox needs access to libchipmunk. > cd ~/Library/Application\ Support/NodeBox My pymunk is in /Library/Python/2.5/site-packages/, so I'll: This will install an egg (which I normally hate dealing with, but that's another story.) If you don't want the egg, just copy the pymunk directory into your site-packages. Once you've downloaded and uncompressed the pymunk source, cd into it's directory and build chipmunk using: Pymunk (at the time of writing) includes it's own copy of the Chipmunk source code, making this whole process rather easy. This may not always be the best solution, so you'll have to pick what's right for your needs. This allows me to run the pymunk examples from the command-line (which use PyGame and Pyglet) but still use it from NodeBox. You can make NodeBox use your system packages instead of it's own by sym-linking ~/Library/Application\ Support/NodeBox to your site-packages directory of choice (ex., /Library/Python/2.5/site-packages)įor this exercise, I'll be adding pymunk (Python bindings for the Chipmonk physics library) to NodeBox using option #3: Installing pymunk globally and sym-linking from NodeBox's package directory.You can install packages into your system site-packages directory and sym-link them from NodeBox's directory.You can import sys in your NodeBox code and manually modify the sys.path value to add your existing packages.You can install your packages into NodeBox's path, ie., ~/Library/Application\ Support/NodeBox/ - meaning that you can use them from NodeBox, but not from other scripts.NodeBox includes it's own Python build, which is nice for portability and reliability, but it uses a custom sys.path that doesn't look for Python packages you might already have installed on your system. For a quick look at what it can do, check out the NodeBox gallery. It's a bit slow to run complex animations in, but you're coding in Python, you get the gorgeous fonts and anti-aliasing you'd expect on OS X, and it provides easy access to some OS X native libraries, like Core Image. It uses PyObjC to embed a Python runtime into an OS X native application, and fits into the same toolbox as Processing and maybe openFrameworks. "NodeBox is a Mac OS X application that lets you create 2D visuals (static, animated or interactive) using Python programming code and export them as a PDF or a QuickTime movie." When you're ready for more, it's not too difficult to bring in external Python libraries to connect NodeBox to other systems or add physics and particle simulation to spice up your visuals. It's easy to get started in and you get basic drawing, type, and image manipulation. NodeBox makes a great environment for data visualizations and generative art.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |