This is a drawing program for the raspberry pi that uses pygame. It's designed to be compatable with the Adafruit TFT.
You can make a game without making classes, but since pygame use objects like Surface you'd probably want some understanding about them. To answer your question however, the pygame.transform module do offer functions to manipulate (resize, flip, rotate and more) images. Pygame.transform.rotate(image, angle) will return the image rotated by the. This function takes two coordinates and draws a colored dashed line from the first to the second coordinate. Line a = abs(x2 - x1) to line dy = dl. b / c calculates the amount x and y change for dl (dashlength). Because dx and dy are floats, I had to use numpy.arange (built-in.
Step by Step Guide
Open Idle (2.7, not 3)
Justin bieber acoustic songs. Click
File > New Windowor hit
Ctrl + N
Next we'll set up the mouse and the frames per second clock.
Now we'll set up our two displays:
- and canvas
Next we'll set up some colors, for now we'll just use black and white but feel free to add more, you can do this by using an RGB color code, you can find these by using this tool
note: you'll need to use the american spelling of color..unfortunately it will break if you spell it the corect way with a
Now we'll build our window. Set up a forever loop and udate the display and add in an exit loop
Save your code using
ctrl + sand then press
F5, a small black window should apear. Press the x to close it.
Now we're going to fill in our window with a background colour, in this case it will be the white color we set up earlier. In the while True we created earlier enter the following line of code before
Save your code and run it again, you should now see that your screen is filled with your background color.
Next we're going to make a circle follow your mouse so as you can see where you'll draw. So we're going to find out where your mouse is using
pygame.mouse.get_pos(). Inside the
while Trueafter the
window.fill(WHITE)line add in the code that draws the circle at the cursor's position.
Now if you save and run your code you should see a small black circle following your cursor around.
Now we need to give your program the ablility to check that your mouse is held down or not. To do this we going to add the following lines at the top of our
and in order to draw a circle when your mouse click is detected you'll have to add this code on to the end of our
for event in pygame.event.get()loop, which can otherwize be known as an event handler.
Note: you must ensure it has the same level of indentation as your previous
And you'll also need to blit the canvas ontp the window, so after
window.fill(WHITE)add in the following line:
And before the
while Trueloop add a line that fills in the background of the the canvas in white.
If you save and run now you should be able to draw!
Finally we're going to give your window a title. Below
pygame.init()add in the following line of code, you can replace paintme with whatever title for your game you want!
How to Extend your project.
- You could add the ability to change colors
- Or use the arrow keys to make the brush change size
- You could add in a clear button
- Or introduce the ability to save the image you have created
- Allow the user to import a picture, draw on top of it, and resave the image
And much much more!You can find the codes for different key presses here and other pygame functionality here.