alexspy Alex's .py alexspy

Hi, I'm Alex. I created this Python blog to show people the latest games and code I'm working on, along with explanations and examples for anyone looking to learn more about Python, CGI / server-side programming, or just internet game development in general. Let me know what you think, and thanks for visiting!



Jan 14, 2012 : rand_pool.py

Here's a breakdown of how the rand_pool.py source code works, in 8 easy steps...
  1. Import the PIL module. (Note: this requires Python v2.7)...



  2. Create a 550 x 1000 pixel drawing object...



  3. Define variables for the widths and colors of the pool table geometry...



  4. Draw the pool table, the rails and the pockets...



  5. Define random positions for the cue ball and object ball then draw them onto the main image...



  6. Determine which pocket has the easiest angle to shoot into and draw a line to it...



  7. Calculate the difficulty of the shot based on its angle and how far it had to go...



  8. Save changes to the drawing object and print its JPEG binary code back to the browser seeking to retrieve and render the image...






Here's some other great python blogs I like to check out:

Nadia Alramli's Blog
The "Invent with Python" Blog
Carter Sande's Blog