Importing modules + pygame intro

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Introduction to Computer Graphics Raster Vs. Vector COMMUNICATION TECHNOLOGY.
sample text 14pt Helvetica Instructions 1.Use mouse to select an object (icon, arrow or sample text box) 2.Copy the object (Edit > Copy) then paste.
CHAPTER 3 (P.49-53) Importing modules + pygame intro.
L.Ghadah R. Hadba CT1514-L1.  Computer Graphics :refers to processing of creating a new image from Geometry, Lighting parameters, Materials and Textures.Using.
Raster graphics. Colour depth 01 1 bit pr pixel = 2 combinations (2 1 ): 2 bits pr pixel = 4 combinations (2 2 ): bits pr pixel = 16 combinations(2.
Raster Graphics vs. Vector Graphics
Graphics. Image format's GIF Format: Use a maximum of 256 colors, and are recommendable for big areas of one color or non- continuous images. They are.
Multimedia for the Web: Creating Digital Excitement Multimedia Element -- Graphics.
OpenCV Stacy O’Malley CS-590 Summer, What is OpenCV? Open source library of functions relating to computer vision. Cross-platform (Linux, OS X,
Digital Still Images ETT June Multimedia Assets Still Images Audio Video.
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
Introduction to Computer Graphics Raster Vs. Vector TGJ 2OI St. Christopher C.S.S. 4 Introduction to Computer Graphics.ppt.
Guide to Programming with Python
Antigone Engine Kevin Kassing – Period
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
SDL Programming Introduction. Initialization 2  The first thing you must do is initialize SDL  int SDL_Init( SDL_INIT_EVERYTHING )  This will return.
Multimedia Specification Design and Production 2012 / Semester 1 / L4 Lecturer: Dr. Nikos Gazepidis
Module Code: CU0001NI Technical Information on Digital Images Week -2.
File Name Extensions Computer Applications 7th grade.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Computer Graphics Bitmaps & Sprites CO2409 Computer Graphics Week 3.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics I, Fall 2008 Introduction to Computer Graphics.
File Formats and Vector Graphics. File Types Images and data are stored in files. Each software application uses different native file types and file.
By Courtney Field Creative digital graphics. Types of graphics and examples There are a number of different types of graphics file formats. Each type.
FILE TYPES FOR WEB DESIGN 1 HOW SHOULD I SAVE?. GRAPHICS INTERCHANGE FORMAT (GIF) Best used for flat-color, sharp-edged art or text Clip art, logos Compression.
CHAPTER 3 (P.49-53) Importing modules + pygame intro.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
PyGame - Unit 2 PyGame Unit – – Animation.
Active Matrix LCD Panel ProMax® Interactive LCD Writing Panel Active Matrix LCD Panel ProMax® Interactive LCD Writing Panel.
1 MIT 5316 Web-Based Computing Lecture 1. 2 Welcome Introduction Syllabus.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
2D Graphics CMT3311. This covers... How to make a transparent sprite How to add a sprite to your project and draw it Properties of sprites and how to.
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
●Cross-platform multimedia devlopment library for games (thats what we talk about), demos, MPEG players.... anything multimedia you can think of. ●SDL.
2.01 Understand Digital Raster Graphics
File Formats Different applications (programs) store data in different formats. Applications support some file formats and not others. Open…, Save…, Save.
2.01 Understand Digital Raster Graphics
Sprites (Images) and Sounds
Digital Illustration Chapter 6 File format.
Pixels, Colors and Shapes
A look ahead: At the end of your project, you’ll be given an opportunity to make a standalone (.exe) version of your project. For this to work, you’ll.
Textures, Sprites, and Fonts
Hardware research By Hollie Willis.
Introduction to Graphics
Part II Reference:
PYGAME.
Let’s Learn 2. Installing Pygame
8. Installing Pygame
Binary Representation in Audio and Images
9. Drawing.
2.01 Understand Digital Raster Graphics
Chapter 3 Image Files © 2017 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
9. Drawing Let's Learn Python and Pygame
A lap around DirectX game development tools
Chapter 3:- Graphics Eyad Alshareef Eyad Alshareef.
Chapter 5 Working with Images
Intro to GML.
2.01 Understand Digital Raster Graphics
8. Starting Pygame Let's Learn Python and Pygame
PLACE YOUR TITLE HERE **Poster Author(s) Go Here
File Extension Mini-Lesson
Introduction to Computer Graphics
Introduction to Computer Graphics
Working with Symbols and Interactivity
2.01 Understand Digital Raster Graphics
Lesson 5: Multimedia on the Web
L L Line CSE 420 Computer Games Lecture #6 Game Foundations.
Presentation transcript:

Importing modules + pygame intro Chapter 3 (p.49-53) (the book doesn’t have pygame material )

modules core language vs modules. millions of modules. Networking Graphics computer vision … To use these, you need to import them (usually at the top of your script) import math import pygame

modules, cont. Example Sources of modules: Accessing module contents: shipped with python distribution downloaded modules Modules that you write yourself. Accessing module contents: module_name.item_in_the_module. Example

random Module random.randint(low_num, high_num) random.uniform(low_num, high_num) random.gauss(center_num, std_dev) A "rookie" mistake: Often, people see a line like this: x = random.randint(5, 10) And think we're making x a variable which changes all the time – we're not. x gets its value (which will be different on each run) But…it never changes, until we assign a new value to it. print(x) # Let's say it was 7 this time print(x) # still 7 print(x) # STILL 7 …

time module time.sleep(num_seconds) time.time() Example use

Part I Reference: www.pygame.org

What is it? A multimedia python library Window Management Graphics geometric shapes bitmaps (sprites) Input Mouse Keyboard Gamepad / Joystick Sound SoundFX Music

Overview Pygame (sub-)module organization Connection to documentation Pygame <= SDL <= [DirectX / OpenGL / …]

Surfaces A 2d array of (RGB) pixels Double Buffering An image (sprite) Rendered (at run-time) text A mini-map A HUD An interface to the window’s contents. In pygame, Surfaces are objects. Look up the methods in the “Surfaces” section of pygame docs. Double Buffering Monitor refreshes Life without D.B. D.B. in pygame

Examples [Basic window] [Drawing] [Look at the pygame docs]

Sprites / Images Images (in pygame) are Surface objects File formats loadable by pygame: JPG, BMP, PCX, TGA, TIF, PBM, PGM, XPM GIF, PNG # Support transparency Loading: s = pygame.image.load("img.jpg") s = pygame.image.load("sprites\\img.jpg") s = pygame.image.load("..\\..\\media\\img.jpg") s = pygame.image.load("c:\\game\\img.jpg") s = pygame.image.load("/usr/bin/img.jpg") import os print(os.sep) # '\\' on Windows, '/' on *nix

Sprites / Images, cont. Converting: Color / bit encoding… Why it's good to convert… Command: s = pygame.image.load("img.jpg") s = s.convert() t = pygame.image.load("img2.png").convert_alpha()

Blitting Copies contents of one (part of) a surface to another. ant_img (150x180) (75,0) screen (600x600) 100 (100,0) 50 dest_surf.blit(src_surf, pos) (20,100) dest_surf.blit(src_surf, pos, src_rect) screen.blit(ant_img, (20,100)) screen.blit(ant_img, (100,0), (75,0,50,100))

Transforming surfaces pygame.transform.scale(orig_surf, (new_width, new_height)) pygame.transform.rotate(orig_surf, degrees) Returns a new surface Must be blitted to screen to be seen Original surface is unchanged! [Example] Rotating "in-place"

Fonts Rendering text in pygame Two steps: [Example] As opposed to the print statement Two steps: Create a font object (just done once) From a .ttf file From a built-in font Render text Creates a new surface …which must be blitted to the screen. [Example]