Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
NumPy Beginner's Guide

You're reading from   NumPy Beginner's Guide An action packed guide using real world examples of the easy to use, high performance, free open source NumPy mathematical library.

Arrow left icon
Product type Paperback
Published in Apr 2013
Publisher Packt
ISBN-13 9781782166085
Length 310 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ivan Idris Ivan Idris
Author Profile Icon Ivan Idris
Ivan Idris
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Numpy Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. NumPy Quick Start FREE CHAPTER 2. Beginning with NumPy Fundamentals 3. Get in Terms with Commonly Used Functions 4. Convenience Functions for Your Convenience 5. Working with Matrices and ufuncs 6. Move Further with NumPy Modules 7. Peeking into Special Routines 8. Assure Quality with Testing 9. Plotting with Matplotlib 10. When NumPy is Not Enough – SciPy and Beyond 11. Playing with Pygame Pop Quiz Answers Index

Time for action – drawing the Sierpinski gasket


For the purpose of demonstration we will draw a Sierpinski gasket, also known as Sierpinski triangle or Sierpinski Sieve with OpenGL. This is a fractal pattern in the shape of a triangle created by the mathematician Waclaw Sierpinski. The triangle is obtained via a recursive and, in principle, infinite procedure. Perform the following steps to draw the Sierpinski gasket:

  1. First, we will start out by initializing some of the OpenGL-related primitives. This includes setting the display mode and background color. A line-by-line explanation is given at the end of this section.

    def display_openGL(w, h):
      pygame.display.set_mode((w,h), pygame.OPENGL|pygame.DOUBLEBUF)
    
      glClearColor(0.0, 0.0, 0.0, 1.0)
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
      
      gluOrtho2D(0, w, 0, h)
  2. The algorithm requires us to display points, the more the better. First, we set the drawing color to red. Second, we define the vertices (I call them points myself) of a triangle...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime