Python Programming in Opengl

Total Page:16

File Type:pdf, Size:1020Kb

Python Programming in Opengl Python Programming in OpenGL A Graphical Approach to Programming Stan Blank, Ph.D. Wayne City High School Wayne City, Illinois 62895 October 6, 2009 Copyright 2009 2 Table of Contents Chapter 1 Introduction......................................................................................6 Chapter 2 Needs, Expectations, and Justifications ..........................................8 Section 2.1 What preparation do you need? ...............................................8 Section 2.2 What hardware and software do you need?.............................8 Section 2.3 My Expectations.......................................................................9 Section 2.4 Your Expectations ....................................................................9 Section 2.5 Justifications...........................................................................10 Section 2.6 Python Installation..................................................................11 Exercises .....................................................................................................12 Chapter 3 Your First Python Program ............................................................13 Section 3.1 Super-3 Numbers...................................................................13 Section 3.2 Conclusion .............................................................................21 Exercises .....................................................................................................21 Chapter 4 Your First OpenGL Program..........................................................23 Section 4.1 The Interactive Python Interpreter..........................................23 Section 4.2 Introducing Python OpenGL...................................................24 Section 4.3 Odds, Ends, and Terminology................................................29 Section 4.4 Conclusion .............................................................................31 Exercises .....................................................................................................31 Chapter 5 2 Dimensional Graphics ................................................................33 Section 5.1 Plotting Points ........................................................................33 Exercises .....................................................................................................37 Section 5.2 Plotting 2D Functions .............................................................41 Exercises .....................................................................................................44 Sections 5.3 Parametric Equations .............................................................50 Exercises .....................................................................................................53 Section 5.4 An Example from Physics ......................................................65 Exercises .....................................................................................................74 Section 5.5 Polar Coordinates...................................................................80 Section 5.6 Conclusion .............................................................................89 Exercises .....................................................................................................90 Figures for Exercises 2-15...........................................................................95 Chapter 6 Patterns and Chaos in 2 Dimensions ............................................99 Section 6.1 PySkel ....................................................................................99 Section 6.2 Some Interesting Patterns....................................................101 Exercises ...................................................................................................106 Figures for exercises 7, 8, 9, and 10..........................................................111 Section 6.3 The Chaos Game.................................................................112 Exercises ...................................................................................................124 Section 6.4 The Barnsley Fern...............................................................129 Exercises ...................................................................................................133 Section 6.5 Chaos and the Logistic Map................................................136 Exercises ...................................................................................................143 Section 6.6 Predator-prey Relationships.................................................148 Exercises ...................................................................................................152 3 Chapter 7 Strange Attractors and Beautiful Fractals ....................................154 Section 7.1 Lorenz and the Weather.......................................................154 Exercises ...................................................................................................162 Section 7.2 Phase Portraits and Paint Swirls ..........................................167 Exercises ...................................................................................................170 Section 7.3 Mira (Look?) .........................................................................172 Exercises ...................................................................................................174 Section 7.4 The 3-Body Problem ............................................................175 Exercises ...................................................................................................178 Section 7.5 Newton’s Method and the Complex Plane ...........................183 Exercises ...................................................................................................193 Addendum: ................................................................................................203 Addendum II: .............................................................................................203 Section 7.6 The Julia Set .......................................................................205 Exercises ...................................................................................................211 Section 7.7 Explorations with the Mandelbrot Set ...................................222 Exercises ...................................................................................................240 Chapter 8 2D Animation...............................................................................246 Section 8.1 Follow the Bouncing Ball ......................................................246 Exercises ...................................................................................................255 Section 8.2 A Little Gravity!.....................................................................261 Exercises ...................................................................................................264 Section 8.3 A Little MORE Gravity... a 2-Body Simulation ......................265 Exercises ...................................................................................................279 Section 8.4 The REAL 3 Body Problem ..................................................281 Exercises ...................................................................................................291 Section 8.5 From 3Body to NBody Using Arrays.....................................294 Exercises ...................................................................................................307 Section 8.6 Navigating the Stars............................................................309 Exercises ...................................................................................................320 Chapter 9 3D and 3D Animation .................................................................322 Section 9.1 Rotating Objects in Space...................................................322 Exercises ...................................................................................................330 Section 9.2 Real Time Interactive Computer Animator (RTICA) ............336 The German Bell........................................................................................345 Exercises ...................................................................................................350 illiTorus ......................................................................................................353 Exercises ...................................................................................................359 Chapter 10 Animation and Display Lists .......................................................370 Electron Orbitals ........................................................................................370 The Quaternion Julia Set ...........................................................................375 Alternate Quaternion Julia Set and Mandelbrot Set...................................381 Chapter 11 Miscellaneous Programs ............................................................388 The Random Walk .....................................................................................388 The 3D Sierpinski Sponge .........................................................................391 Rendering Teapots ....................................................................................393 4 A Midpoint Conjecture ...............................................................................397
Recommended publications
  • Fractals.Pdf
    Fractals Self Similarity and Fractal Geometry presented by Pauline Jepp 601.73 Biological Computing Overview History Initial Monsters Details Fractals in Nature Brownian Motion L-systems Fractals defined by linear algebra operators Non-linear fractals History Euclid's 5 postulates: 1. To draw a straight line from any point to any other. 2. To produce a finite straight line continuously in a straight line. 3. To describe a circle with any centre and distance. 4. That all right angles are equal to each other. 5. That, if a straight line falling on two straight lines make the interior angles on the same side less than two right angles, if produced indefinitely, meet on that side on which are the angles less than the two right angles. History Euclid ~ "formless" patterns Mandlebrot's Fractals "Pathological" "gallery of monsters" In 1875: Continuous non-differentiable functions, ie no tangent La Femme Au Miroir 1920 Leger, Fernand Initial Monsters 1878 Cantor's set 1890 Peano's space filling curves Initial Monsters 1906 Koch curve 1960 Sierpinski's triangle Details Fractals : are self similar fractal dimension A square may be broken into N^2 self-similar pieces, each with magnification factor N Details Effective dimension Mandlebrot: " ... a notion that should not be defined precisely. It is an intuitive and potent throwback to the Pythagoreans' archaic Greek geometry" How long is the coast of Britain? Steinhaus 1954, Richardson 1961 Brownian Motion Robert Brown 1827 Jean Perrin 1906 Diffusion-limited aggregation L-Systems and Fractal Growth
    [Show full text]
  • Fractal 3D Magic Free
    FREE FRACTAL 3D MAGIC PDF Clifford A. Pickover | 160 pages | 07 Sep 2014 | Sterling Publishing Co Inc | 9781454912637 | English | New York, United States Fractal 3D Magic | Banyen Books & Sound Option 1 Usually ships in business days. Option 2 - Most Popular! This groundbreaking 3D showcase offers a rare glimpse into the dazzling world of computer-generated fractal art. Prolific polymath Clifford Pickover introduces the collection, which provides background on everything from Fractal 3D Magic classic Mandelbrot set, to the infinitely porous Menger Sponge, to ethereal fractal flames. The following eye-popping gallery displays mathematical formulas transformed into stunning computer-generated 3D anaglyphs. More than intricate designs, visible in three dimensions thanks to Fractal 3D Magic enclosed 3D glasses, will engross math and optical illusions enthusiasts alike. If an item you have purchased from us is not working as expected, please visit one of our in-store Knowledge Experts for free help, where they can solve your problem or even exchange the item for a product that better suits your needs. If you need to return an item, simply bring it back to any Micro Center store for Fractal 3D Magic full refund or exchange. All other products may be returned within 30 days of purchase. Using the software may require the use of a computer or other device that must meet minimum system requirements. It is recommended that you familiarize Fractal 3D Magic with the system requirements before making your purchase. Software system requirements are typically found on the Product information specification page. Aerial Drones Micro Center is happy to honor its customary day return policy for Aerial Drone returns due to product defect or customer dissatisfaction.
    [Show full text]
  • Copyright by Timothy Alexander Cousins 2016
    Copyright by Timothy Alexander Cousins 2016 The Thesis Committee for Timothy Alexander Cousins Certifies that this is the approved version of the following thesis: Effect of Rough Fractal Pore-Solid Interface on Single-Phase Permeability in Random Fractal Porous Media APPROVED BY SUPERVISING COMMITTEE: Supervisor: Hugh Daigle Maša Prodanović Effect of Rough Fractal Pore-Solid Interface on Single-Phase Permeability in Random Fractal Porous Media by Timothy Alexander Cousins, B. S. Thesis Presented to the Faculty of the Graduate School of The University of Texas at Austin in Partial Fulfillment of the Requirements for the Degree of Master of Science in Engineering The University of Texas at Austin August 2016 Dedication I would like to dedicate this to my parents, Michael and Joanne Cousins. Acknowledgements I would like to thank the continuous support of Professor Hugh Daigle over these last two years in guiding throughout my degree and research. I would also like to thank Behzad Ghanbarian for being a great mentor and guide throughout the entire research process, and for constantly giving me invaluable insight and advice, both for the research and for life in general. I would also like to thank my parents for the consistent support throughout my entire life. I would also like to acknowledge Edmund Perfect (Department of Earth and Planetary, University of Tennessee) and Jung-Woo Kim (Radioactive Waste Disposal Research Division, Korea Atomic Energy Research Institute) for providing Lacunarity MATLAB code used in this study. v Abstract Effect of Rough Fractal Pore-Solid Interface on Single-Phase Permeability in Random Fractal Porous Media Timothy Alexander Cousins, M.S.E.
    [Show full text]
  • Python Programming
    Python Programming Wikibooks.org June 22, 2012 On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An URI to this license is given in the list of figures on page 149. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 143. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 153, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of figures on page 149. This PDF was generated by the LATEX typesetting software. The LATEX source code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the PDF file, we recommend the use of http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting Save Attachment. After extracting it from the PDF file you have to rename it to source.7z. To uncompress the resulting archive we recommend the use of http://www.7-zip.org/.
    [Show full text]
  • POV-Ray Reference
    POV-Ray Reference POV-Team for POV-Ray Version 3.6.1 ii Contents 1 Introduction 1 1.1 Notation and Basic Assumptions . 1 1.2 Command-line Options . 2 1.2.1 Animation Options . 3 1.2.2 General Output Options . 6 1.2.3 Display Output Options . 8 1.2.4 File Output Options . 11 1.2.5 Scene Parsing Options . 14 1.2.6 Shell-out to Operating System . 16 1.2.7 Text Output . 20 1.2.8 Tracing Options . 23 2 Scene Description Language 29 2.1 Language Basics . 29 2.1.1 Identifiers and Keywords . 30 2.1.2 Comments . 34 2.1.3 Float Expressions . 35 2.1.4 Vector Expressions . 43 2.1.5 Specifying Colors . 48 2.1.6 User-Defined Functions . 53 2.1.7 Strings . 58 2.1.8 Array Identifiers . 60 2.1.9 Spline Identifiers . 62 2.2 Language Directives . 64 2.2.1 Include Files and the #include Directive . 64 2.2.2 The #declare and #local Directives . 65 2.2.3 File I/O Directives . 68 2.2.4 The #default Directive . 70 2.2.5 The #version Directive . 71 2.2.6 Conditional Directives . 72 2.2.7 User Message Directives . 75 2.2.8 User Defined Macros . 76 3 Scene Settings 81 3.1 Camera . 81 3.1.1 Placing the Camera . 82 3.1.2 Types of Projection . 86 3.1.3 Focal Blur . 88 3.1.4 Camera Ray Perturbation . 89 3.1.5 Camera Identifiers . 89 3.2 Atmospheric Effects .
    [Show full text]
  • Connectivity Calculus of Fractal Polyhedrons
    Pattern Recognition 48 (2015) 1150–1160 Contents lists available at ScienceDirect Pattern Recognition journal homepage: www.elsevier.com/locate/pr Connectivity calculus of fractal polyhedrons Helena Molina-Abril a,n, Pedro Real a, Akira Nakamura b, Reinhard Klette c a Universidad de Sevilla, Spain b Hiroshima University, Japan c The University of Auckland, New Zealand article info abstract Article history: The paper analyzes the connectivity information (more precisely, numbers of tunnels and their Received 27 December 2013 homological (co)cycle classification) of fractal polyhedra. Homology chain contractions and its combi- Received in revised form natorial counterparts, called homological spanning forest (HSF), are presented here as an useful 6 April 2014 topological tool, which codifies such information and provides an hierarchical directed graph-based Accepted 27 May 2014 representation of the initial polyhedra. The Menger sponge and the Sierpiński pyramid are presented as Available online 6 June 2014 examples of these computational algebraic topological techniques and results focussing on the number Keywords: of tunnels for any level of recursion are given. Experiments, performed on synthetic and real image data, Connectivity demonstrate the applicability of the obtained results. The techniques introduced here are tailored to self- Cycles similar discrete sets and exploit homology notions from a representational point of view. Nevertheless, Topological analysis the underlying concepts apply to general cell complexes and digital images and are suitable for Tunnels Directed graphs progressing in the computation of advanced algebraic topological information of 3-dimensional objects. Betti number & 2014 Elsevier Ltd. All rights reserved. Fractal set Menger sponge Sierpiński pyramid 1. Introduction simply-connected sets and those with holes (i.e.
    [Show full text]
  • Fractals and the Chaos Game
    University of Nebraska - Lincoln DigitalCommons@University of Nebraska - Lincoln MAT Exam Expository Papers Math in the Middle Institute Partnership 7-2006 Fractals and the Chaos Game Stacie Lefler University of Nebraska-Lincoln Follow this and additional works at: https://digitalcommons.unl.edu/mathmidexppap Part of the Science and Mathematics Education Commons Lefler, Stacie, "Fractals and the Chaos Game" (2006). MAT Exam Expository Papers. 24. https://digitalcommons.unl.edu/mathmidexppap/24 This Article is brought to you for free and open access by the Math in the Middle Institute Partnership at DigitalCommons@University of Nebraska - Lincoln. It has been accepted for inclusion in MAT Exam Expository Papers by an authorized administrator of DigitalCommons@University of Nebraska - Lincoln. Fractals and the Chaos Game Expository Paper Stacie Lefler In partial fulfillment of the requirements for the Master of Arts in Teaching with a Specialization in the Teaching of Middle Level Mathematics in the Department of Mathematics. David Fowler, Advisor July 2006 Lefler – MAT Expository Paper - 1 1 Fractals and the Chaos Game A. Fractal History The idea of fractals is relatively new, but their roots date back to 19 th century mathematics. A fractal is a mathematically generated pattern that is reproducible at any magnification or reduction and the reproduction looks just like the original, or at least has a similar structure. Georg Cantor (1845-1918) founded set theory and introduced the concept of infinite numbers with his discovery of cardinal numbers. He gave examples of subsets of the real line with unusual properties. These Cantor sets are now recognized as fractals, with the most famous being the Cantor Square .
    [Show full text]
  • The Kilobot Gym
    The Kilobot Gym Gregor H.W. Gebhardt1 and Gerhard Neumann2 Abstract— Simulation is a crucial tool when learning control policies for robotic systems. The evaluation of a control policy is a recurring task in most learning algorithms which can be significantly sped up when using a simulation instead of the real system. This improvement in learning speed becomes even more significant when working with robot swarms which usually operate rather slow and need to be tediously initialized by hand. In this paper, we present a novel simulator for swarm Fig. 1. Left: a scene with a small swarm of Kilobots with an object in the robotics. Our simulator is inspired by the Kilobot platform and background. Right: a swarm of Kilobots in our simulation framework with builds on the OpenAI gym. This allows to evaluate a wide range with four square objects. of learning algorithms using a unified interface for controlling the swarm. The code of our simulation framework is available at [3]. time step. The implementation uses JavaScript embedded in HTML files which results in code that is hard to use for I. INTRODUCTION programmatic evaluations and, furthermore, the reusability Learning the parameters of a control policy is usually of JavaScripts without any modularity goes towards zero. an iterative process of evaluating the parameters on the Another approach to simulate a swarm of Kilobots is to system and improving the parameters based on the evaluation use the robot simulator V-REP [6]. The simulations are results. In robotics, the most time consuming task is often the performed in 3D, where the user can select between different evaluation of the parameters on a real robotic system.
    [Show full text]
  • Exploiting Traditional Gameplay Characteristics to Enhance Digital Board Games
    Exploiting traditional gameplay characteristics to enhance digital board games Fulvio Frapolli∗, Apostolos Malatras∗ and Beat´ Hirsbrunner∗ ∗Department of Informatics University of Fribourg, Switzerland Email: name.surname @unifr.ch { } Abstract—Computer enhanced board and card games consti- population of board game players and human-computer inter- tute a highly engaging and entertaining activity as attested by action experts [7]. Additionally, the key role that the players their widespread popularity and the large amount of dedicated have in the physical environment in modifying game aspects players. Nonetheless, when considering these digital counterparts of traditional board games it becomes evident that certain to increase their level of enjoyment, as highlighted in [8], features of the latter, such as the flexibility of games and the should not be neglected. In this respect, when shifting to the inherent social interactions that regard the player as an active digital environment end-user involvement, namely the ability participant and not merely as the end-user of a product, have of players with basic programming skills (i.e. understanding been in general neglected. In particular, the ability to customize of fundamental concepts of algorithmics, such as if . then and adapt games according to the players’ needs is one of the key factors of their success and should thus not be ignored when . else constructs or for loops) to customize a board game, porting them to the digital environment. In this paper we present should be strongly promoted. our work on a holistic framework titled FLEXIBLERULES that In order to achieve these goals, we present here the FLEXI- addresses these limitations by bringing the intrinsic flexibility BLERULES framework which enables runtime modification of of board games played in the traditional environment into the all aspects of a game in a straightforward manner.
    [Show full text]
  • Strictly Self-Similar Fractals Composed of Star-Polygons That Are Attractors of Iterated Function Systems
    Strictly self-similar fractals composed of star-polygons that are attractors of Iterated Function Systems. Vassil Tzanov February 6, 2015 Abstract In this paper are investigated strictly self-similar fractals that are composed of an infinite number of regular star-polygons, also known as Sierpinski n-gons, n-flakes or polyflakes. Construction scheme for Sierpinsky n-gon and n-flake is presented where the dimensions of the Sierpinsky -gon and the -flake are computed to be 1 and 2, respectively. These fractals are put1 in a general context1 and Iterated Function Systems are applied for the visualisation of the geometric iterations of the initial polygons, as well as the visualisation of sets of points that lie on the attractors of the IFS generated by random walks. Moreover, it is shown that well known fractals represent isolated cases of the presented generalisation. The IFS programming code is given, hence it can be used for further investigations. arXiv:1502.01384v1 [math.DS] 4 Feb 2015 1 1 Introduction - the Cantor set and regular star-polygonal attractors A classic example of a strictly self-similar fractal that can be constructed by Iterated Function System is the Cantor Set [1]. Let us have the interval E = [ 1; 1] and the contracting maps − k k 1 S1;S2 : R R, S1(x) = x=3 2=3, S2 = x=3 + 2=3, where x E. Also S : S(S − (E)) = k 0 ! − 2 S (E), S (E) = E, where S(E) = S1(E) S2(E). Thus if we iterate the map S infinitely many times this will result in the well known Cantor[ Set; see figure 1.
    [Show full text]
  • FACTA UNIVERSITATIS UNIVERSITY of NIŠ ISSN 0354-4605 (Print) ISSN 2406-0860 (Online) Series Architecture and Civil Engineering COBISS.SR-ID 98807559 Vol
    CMYK K Y M C FACTA UNIVERSITATIS UNIVERSITY OF NIŠ ISSN 0354-4605 (Print) ISSN 2406-0860 (Online) Series Architecture and Civil Engineering COBISS.SR-ID 98807559 Vol. 16, No 2, 2018 Contents Milena Jovanović, Aleksandra Mirić, Goran Jovanović, Ana Momčilović Petronijević NIŠ OF UNIVERSITY EARTH AS A MATERIAL FOR CONSTRUCTION OF MODERN HOUSES ..........175 FACTA UNIVERSITATIS Đorđe Alfirević, Sanja Simonović Alfirević CONSTITUTIVE MOTIVES IN LIVING SPACE ORGANISATION .......................189 Series Ivana Bogdanović Protić, Milena Dinić Branković, Milica Igić, Milica Ljubenović, Mihailo Mitković ARCHITECTURE AND CIVIL ENGINEERING MODALITIES OF TENANTS PARTICIPATION IN THE REVITALIZATION Vol. 16, No 2, 2018 OF OPEN SPACES IN COMPLEXES WITH HIGH-RISE HOUSING ......................203 Biljana Arandelovic THE NEUKOELLN PHENOMENON: THE RECENT MOVE OF AN ART SCENE IN BERLIN ...........................................213 2, 2018 Velimir Stojanović o THE NATURE, QUANTITY AND QUALITY OF URBAN SEGMENTS.................223 Maja Petrović, Radomir Mijailović, Branko Malešević, Đorđe Đorđević, Radovan Štulić Vol. 16, N Vol. THE USE OF WEBER’S FOCAL-DIRECTORIAL PLANE CURVES AS APPROXIMATION OF TOP VIEW CONTOUR CURVES AT ARCHITECTURAL BUILDINGS OBJECTS ........................................................237 Ana Momčilović-Petronijević, Predrag Petronijević, Mihailo Mitković DEGRADATION OF ARCHEOLOGICAL SITES – CASE STUDY CARIČIN GRAD .................................................................................247 Vesna Tomić, Aleksandra Đukić
    [Show full text]
  • Ergodic Theory, Fractal Tops and Colour Stealing 1
    ERGODIC THEORY, FRACTAL TOPS AND COLOUR STEALING MICHAEL BARNSLEY Abstract. A new structure that may be associated with IFS and superIFS is described. In computer graphics applications this structure can be rendered using a new algorithm, called the “colour stealing”. 1. Ergodic Theory and Fractal Tops The goal of this lecture is to describe informally some recent realizations and work in progress concerning IFS theory with application to the geometric modelling and assignment of colours to IFS fractals and superfractals. The results will be described in the simplest setting of a single IFS with probabilities, but many generalizations are possible, most notably to superfractals. Let the iterated function system (IFS) be denoted (1.1) X; f1, ..., fN ; p1,...,pN . { } This consists of a finite set of contraction mappings (1.2) fn : X X,n=1, 2, ..., N → acting on the compact metric space (1.3) (X,d) with metric d so that for some (1.4) 0 l<1 ≤ we have (1.5) d(fn(x),fn(y)) l d(x, y) ≤ · for all x, y X.Thepn’s are strictly positive probabilities with ∈ (1.6) pn =1. n X The probability pn is associated with the map fn. We begin by reviewing the two standard structures (one and two)thatare associated with the IFS 1.1, namely its set attractor and its measure attractor, with emphasis on the Collage Property, described below. This property is of particular interest for geometrical modelling and computer graphics applications because it is the key to designing IFSs with attractor structures that model given inputs.
    [Show full text]