Latest Awards
Complete 10 python programs which focus on loops.

morgan

Score over 100 points in total

vincebanter10

Complete any 5 python programs

vincebanter10

Complete 3 python list based tasks

vincebanter10

Complete 5 python list based tasks

vincebanter10

Complete 10 python list based tasks

dman12

Score over 1000 points in total

april-logan

Complete any pygame task

april-logan

Complete any 3 pygame tasks

april-logan

You have to complete 5 pygame tasks

april-logan

Score over 500 points in total

sam-edmund

Complete any pygame task

sam-edmund

Complete any 3 pygame tasks

sam-edmund

You have to complete 5 pygame tasks

sam-edmund

Complete any pygame task

12wrigleyf

Complete any 3 pygame tasks

12wrigleyf

You have to complete 5 pygame tasks

12wrigleyf

Score over 500 points in total

jhoughton12

Complete any 10 python prograns

jhoughton12

Complete 10 python programs which focus on loops.

jhoughton12

Python Score
tasks = 0
achivements = 0
freestyle = 0
Total = 0
Top 5 Scores
114gilo 3400
2joss-nolan-2 2470
3alexdawkins 2445
4byrnebrian 1980
512wattsl 1690
Click to view all scores
Who else completed this task?
No one has completed this task yet. Be the first!

Basic drawing

Syntax

screen
=
display.
set_mode
((640,480))
draw.
rect(
screen,
(255,0,0),
(10,
10,
100,
100),
4)

Drawing in pygame revolves around the idea of a surface. A surface is a block of memory which can be updated by the draw commands and then, when drawing is complete, be sent to the graphics card. When doing any command using the draw object, you must always pass through a surface.

Some sample code to try –

from pygame import *

init()
# we only need a screen to get access to the events!
screen = display.set_mode((640, 480)) # tuple
display.set_caption('Graphics')

endProgram = False

while not endProgram:
	# pygame event loop
	for e in event.get():
		if e.type == QUIT:
			endProgram = True
	# draw stuff
	# Red Green Blue (RGB)
	# 0 - 254
	screen.fill((100,100,200))
	# rectangle
	# X, Y, Width, Height
	draw.rect(screen,(255,0,0), (10,10,100,100), 4)
	# fill rectangle
	draw.rect(screen,(255,0,0), (200,10,100,100))
	# circle
	draw.ellipse(screen, (0,255,0), (10, 200, 80, 80) , 4)
	# circle
	draw.ellipse(screen, (0,255,0), (200, 200, 80, 80))
	# update the screen!
	display.update()

Rectangles form a large part of pygame and it is worth learning more about them. Also, it is also important to learn about surfaces as they provide a lot of the depth that pygame provides.

Helpful links

http://pygametutorials.wikidot.com/book-surf – Introduction to surfaces

http://www.pygame.org/docs/tut/newbieguide.html  Newbie guide to pygame

 






                  

Leave a Reply

You must be logged in to post a comment.