Reader small image

You're reading from  Mathematics for Game Programming and Computer Graphics

Product typeBook
Published inNov 2022
PublisherPackt
ISBN-139781801077330
Edition1st Edition
Tools
Right arrow
Author (1)
Penny de Byl
Penny de Byl
author image
Penny de Byl

Penny de Byl is a full stack developer with an honors in graphics and Ph.D. in artificial intelligence for games. She has a passion for teaching, teaching games development and computer graphics for over 25 years in universities in Australia and Europe. Her best-selling textbooks, including Holistic Game Development with Unity, are used in over 100 institutions. She has won numerous awards for teaching, including an Australian Government Excellence in Teaching Award and the Unity Mobile Game Curriculum Competition. Her approach to teaching computer science and related fields is project-based giving you hands-on workshops you can immediately get your teeth into. The full range of her teaching interests can be found at H3D Learn.
Read more about Penny de Byl

Right arrow

Summary

You are now an expert at opening graphics windows and have new-found skills at plotting pixels in that window using Cartesian coordinates. This skill is the essential underpinning of everything that gets drawn on a computer screen; it’s through the understanding of mathematics that you will gain throughout this book that you will be able to expand that single pixel into a world of complex 3D structures, colors, and animations. Some of these basic graphics primitives will be explored in the following chapter.

Answers

Exercise A:

import pygame
pygame.init()
screen_width = 900
screen_height = 500
screen = pygame.display.set_mode((screen_width, screen_height))
done = False
white = pygame.Color(255, 255, 255)
def draw_star(x, y, size):
  pygame.draw.rect(screen, white, (x, y, size, size))
while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
  draw_star (121, 320, 15)
  draw_star (327, 324, 15)
  draw_star (691, 431, 20)
  draw_star (697, 317, 10)
  draw_star (626, 246, 30)
  draw_star (343, 212, 10)
  draw_star (653, 165, 10)
  draw_star (773, 102, 10)
  draw_star (822, 153, 10)
  pygame.display.update()
pygame.quit()
Previous PageNext Chapter
You have been reading a chapter from
Mathematics for Game Programming and Computer Graphics
Published in: Nov 2022Publisher: PacktISBN-13: 9781801077330
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Penny de Byl

Penny de Byl is a full stack developer with an honors in graphics and Ph.D. in artificial intelligence for games. She has a passion for teaching, teaching games development and computer graphics for over 25 years in universities in Australia and Europe. Her best-selling textbooks, including Holistic Game Development with Unity, are used in over 100 institutions. She has won numerous awards for teaching, including an Australian Government Excellence in Teaching Award and the Unity Mobile Game Curriculum Competition. Her approach to teaching computer science and related fields is project-based giving you hands-on workshops you can immediately get your teeth into. The full range of her teaching interests can be found at H3D Learn.
Read more about Penny de Byl