The MagPi Issue 1 A Magazine for Raspberry Pi Users.pdf - Google ...

1 downloads 126 Views 11MB Size Report
The MagPi Issue 1 A Magazine for Raspberry Pi Users.pdf. The MagPi Issue 1 A Magazine for Raspberry Pi Users.pdf. Open.
ISSUE 01 MAY 2012

A Magazine for Raspberry Pi Users

Debian

Introducing... The Raspberry Pi

Scratch

A new breed of computer

RacyPy

Python

QR Code:

NO MORE APPLES FOR TEACHER!

http://www.themagpi.com Raspberry Pi is a trademark of The Raspberry Pi Foundation. Front Cover and Feedback Images were created using http://photoFunia.com

Over the coming issues, The MagPi will explore the exciting things that can be done with this very special computer. We will introduce you to the various Raspberry Pi operating systems, how to program in a range of languages, and start your own interesting projects. We aim to help experts and beginners get the most out of the Raspberry Pi hardware and more importantly help build a fun and friendly community for everyone to get involved with.

2

Fresh fruit If you like your apples to be white

Interest in the Raspberry Pi is already

and shiny, your apricots made

incredible, and demand

from silicon, and you'd rather talk

expectations.

has far exceeded

IT professionals, electronics

experts and newcomers are all eager to get

to your blackberries, then you

their hands on the small device which

may be in for a treat...

everybody agrees 'is going to be huge'.

The Raspberry Pi computer is the size of a

Article by Jaseman & Meltwater

credit card, completely silent and costs under The operating system runs from an SD flash card, allowing its personality to instantly be switched by swapping cards. Its potential uses are staggering, and as yet, not fully explored, but it has already been tested as a multimedia player with streaming capabilities, a games machine, an internet browser and a hardware development board. It is intended to be used as an educational device for people of all ages and skill levels. Lucky Element 14 Road Test Prize Winner 'GizmoB73' unboxed this late 'R&D' prototype.

Contents

Affordable Computing

P.04

Debian VirtualBox

P.16

The Fall Of Programming

P.05

Programming

P.18

The Pioneers

P.06

The Scratch Patch

P.20

Hardware Development

P.09

The Python Pit

P.23

Skutter

P.10

Feedback

P.30

RacyPy LiveCD & Virtual Machine

P.12

Web Links & Credits

P.32

3

The Dawn Of Affordable Computing The ZX81 and Spectrum by Sinclair Research,

were

among

the

first

affordable home computers available during the early 1980's. Although these 8-bit computers were crude by today's standards, they gave ordinary people the opportunity to write computer programs and games. The

BBC

Acorn

computer

was

backed by the British Government for use in education and subsidies were granted to schools.

These

computers were a little too expensive for most families to have at home. The 'Electron' was Acorn's attempt at addressing the price issue. They sold a number of units, however despite being more powerful on the hardware side, the range of game titles was significantly

smaller

than

rivals

Sinclair and Commodore.

4

The MagPi

Issue 01 MAY 2012

The Fall Of Programming Home computer users were becoming less interested in writing their own programs. Slick-looking, professionally made games that were

coming

out

of

software

publishing

companies were compelling. Ocean Software for example, an

boasted

impressive

library of hit game titles

such

as

'Daley Thompson's Decathlon', 'Chase HQ' and 'New Zealand Story'. The trend of moving away from programming followed within the education sector. Early software packages like Wordstar, and Lotus 123 were difficult to use before the days of the graphical interface, but typing skills, word processing, spreadsheet and I", "Love", "My","Raspberry","Pi"]

for n in range(0,5): print (mytext[n])

print()

PYTHON VERSION: 2.6.6 / 2.7.2 / 3.2.2 PYGAME VERSION: N/A O.S.: Debian / RacyPy / Win7

TE

E ST

D!

(continued over page...)

27

This game will take a bit more typing, but it is a good example of what the Pygame library can do. Don't worry if you do not understand all of the commands. We will be covering these in more detail in the next issue. Note: You will need a mouse connected to your computer to control the bat. # BAT AND BALL # By antiloquax - 28th April 2012 import pygame from pygame.locals import * pygame.init() # set the width and height of the screen size = [400, 400] screen = pygame.display.set_mode(size) # give the window a title pygame.display.set_caption("Bat and Ball") # This makes the normal mouse pointer invisible in graphics window pygame.mouse.set_visible(0) # create surfaces for the bat and ball bat_surf = pygame.Surface((64,12)) bat_surf.fill((0,255,0)) batrect = bat_surf.get_rect() ball_surf = pygame.Surface((30,30)) ballrect = ball_surf.get_rect() ball = pygame.draw.circle(ball_surf, (0,0,255),[15, 15], 15) # set speed of ball speed = [3, 3] # puts the bat center of screen, near the bottom batrect.center = ((size[0]/2), (size[1] - 50)) # make a text object font = pygame.font.Font(None, 36) text = font.render("Game Over", True, (255,0,0)) textRect = text.get_rect() textRect.centerx = (size[0]/2) textRect.centery = (size[1]/2) # loop until the user clicks the close button done=0 # create a timer to control how often the screen updates clock = pygame.time.Clock() # main game loop while done == 0: screen.fill((0,0,0)) # event handling for event in pygame.event.get(): # if we click something ... if event.type == pygame.QUIT: # if we click close ... done=1 # this will cause the loop to finish.

28

# moves bat in accordance with the mouse position position = pygame.mouse.get_pos() batrect.centerx = position[0] # move the ball ballrect.left += speed[0] ballrect.top += speed[1] # collision detection if ballrect.colliderect(batrect): speed[1] = -speed[1] # check if the ball is going off screen if ballrect.left < 0 or ballrect.right > size[0]: speed[0] = -speed[0] if ballrect.top < 0: speed[1] = -speed[1] # print "Game Over" if the ball leaves screen if ballrect.top > size[1]: screen.blit(text, textRect) pygame.display.flip() pygame.time.wait(2000) # 2000 milliseconds pause ballrect.top=0; ballrect.left=(size[0]/2) # reset the ball position screen.blit(ball_surf, ballrect) screen.blit(bat_surf, batrect)

# set the loop to 60 cycles per second clock.tick(60) # update the display pygame.display.flip()

Make sure to observe UPPER and lower case text, for example: .font.Font .Surface .Clock Try altering the '# set speed of ball' section: EG: speed = [5,5] You can also alter the width and height of the screen. Let us know how you get on with these programs. We will bring you some more Python and Pygame examples in Issue 2. PYTHON VERSION: 3.2.2 PYGAME VERSION: Pygame 1.9.2a0 O.S.: Win7

TE

E ST

D!

29

Feedback 'Magazine has to be

'Group effort PDF mag,

'The magazine is looking

done.'

but it would be nice to

great. There is certainly

see one of those monthly

a need for this sort of

online flash page turn

'step

'I would love to see a

magazines with pictures n

Keep up the good work!'

magazine, but I'd also like

stuff.'

SN

to see it be a community

Abishur'

step'

guide. Montala

monkeyra

led effort that is free for download.'

by

'Hi

I'm education

'A mag would be great.

coordinator

Especially if there was

Foundation and (at the

plenty of programming

moment)

tutorials/simple apps.'

employee. The MagPi is

fastkat

for the

the only

a great idea!.' Myra 'Exciting!

We're

very

happy to see you guys doing this, and we're looking forward to seeing what you come up with. Thanks for letting me know about it.' Liz

30

Raspberry Pi is a trademark of the Raspberry Pi foundation. The MagPi magazine is collaboratively produced by an independent group of Raspberry Pi owners, and is not affiliated in any way with the Raspberry Pi Foundation. The Magpi does not accept ownership or responsibility for the content or opinions expressed in any of the articles included in this issue. All articles are checked and tested before the release deadline is met but some faults may remain. The reader is responsible for all consequences, both to software and hardware, following the implementation of any of the advice or code printed. The MagPi does not claim to own any copyright licenses and all content of the articles are submitted with the responsibility lying with that of the article writer.

Other Resources and Weblinks http://www.themagpi.com Official website of The MagPi magazine.

Tandy have generously provided The MagPi with a Domain name.

http://www.raspberrypi.org

A great big 'THANK YOU' from The MagPi Team.

http://www.youtube.com/RaspberryPiTutorials

Official home of the Raspberry Pi Foundation.

http://elinux.org/R-Pi_Hub Wiki hub for the Raspberry Pi computer.

Video tutorials and python / pygame programming examples by Liam Fraser.

http://www.raspberrypi.org/forum/educational-applications/jasemans-python-lessons Python / Pygame tutorials by Jaseman.

Look out for some interesting news about Tandy in next month's issue.

http://www.python.org Official site for the Python programming language.

http://www.debian.org Homepage for the Linux Debian Operating System.

[email protected] The MagPi

Issue 01 MAY 2012

Team:

Ash Stone Chief Editor / Administrator / Website / Header

Jason 'Jaseman' Davies Page Designs / Writer

Meltwater Writer / Editor / Photographer

Chris 'tzj' Stagg Photographer / Graphics

Bodge N Hackitt Writer

antiloquax Python Tutor

Additional help and support: tzj

GizmoB73, Darren Grant, Mike Clements, Russell Davis, Rudi Kuin, Deep Thought, Liz Upton & Myra Raspberry Pi is a trademark of The Raspberry Pi Foundation,