L05- Graphics.pdf - Pygame and Computer Graphics Objectives...

This preview shows page 1 - 13 out of 50 pages.

Pygame and Computer Graphics
Objectives Computer Graphics Intro What is Pygame Installing Pygame Basics of Pygame Drawing on a Surface Drawable Objects Animation Collision detection 2 4/22/2019
Reading Readings from “Making Games with Python & Pygame” Chapters 1 and 2 3 4/22/2019
CLI vs. GUI CLI: Command Line Interface: User interacts with the program via text Displayed on the screen / Entered via keyboard No graphics, colors, or mouse input GUI: Graphical User Interface: Windows with graphics, colors, images, sounds User can interact with the program via the mouse, keyboard, and other devices. 4 4/22/2019
Computer Graphics Going from a command-line interface (CLI) to a graphical user interface (GUI) is non-trivial! It involves things like: Determining how to render pixels on a screen given primitive representation i.e. How to make the pixels of a line given its endpoints Covered in CS 430 How to respond to events Where was a mouse clicked? And on what? And a lot of these things are hardware and software dependent Graphics card capabilities Operating System 5 4/22/2019
Computer Graphics As computers became more mainstream in the 1980’s, the desire for a more graphical interface became necessary Graphics APIs (application programming interface) try to take away some of the “under the hood” details of graphics at different levels of abstraction Covered in CS 432 – OpenGL Programming 6 4/22/2019
Computer Graphics Computer Graphics are a great application of object oriented programming since intrinsically there are various “objects” on the screen. As a sort of case study for this course, we’ll look at making graphic applications using a Python 2D graphics API, Pygame 7 4/22/2019
What is Pygame? Pygame is a Free and Open Source Python library for making multimedia applications like games and animations. Includes several modules with functions for drawing graphics, playing sounds, handling mouse input, etc. 8 4/22/2019
Pygame - Installation To install pygame we’ll use the python-supplied pip3 program, run from the command line: pip3 install pygame Note: You may have to navigate to where you installed Python to find the pip executable and run the command from in there. 9 4/22/2019
Pygame The following lecture material is based on the online book: In addition the official Pygame website: 10 4/22/2019
The Imports The first step to use Pygame will be to import Pygame. We could just import sub-packages of Pygame, but for simplicity lets just import everything: import pygame 11 4/22/2019
Initialization Once we have our imports set, we need to do some initialization.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture