Home > other >  Pygame mobile graphics problem
Pygame mobile graphics problem

Time:09-16

Lead the code

` ` `
# setup
Import the random
The import pygame
Pygame. The init ()
Screen=pygame. Display. Set_mode ((640, 480))


Def random_color () :
Red=random. Randint (0, 255)
Green=random. Randint (0, 255)
Blue=random. Randint (0, 255)
Return (red, green, blue)


Def draw_tree (x, y) :
# tree trunk (50 wide and tall 100)
Pygame. The draw. The rect (screen, (117, 90, 0), (x, y - 100, 50, 100))
# leaves are a circle
Pygame. The draw. Circle (screen, (27, 117, 0), (+ 25 x, y - 120), 50)


Def draw_house (x, y) :
# pink house
Pygame. The draw. The rect (screen, (255, 171, 244), (x, y - 180, 200, 180))
# brown feel
Pygame. The draw. The rect (screen, (89, 71, 0), (x + 80, y - 60, 40, 60))
# yellow knobs feel
Pygame. The draw. Circle (screen, (255, 204, 0), (x + 112, y - 30), 4)
# triangle roof
Pygame. The draw. Polygon (screen, (125, 125, 125), ((
X, y - 180), (x + 100, y - 250), (x + 200, y - 180)))
Draw_window (+ 20 x, y - 90)
Draw_window (x + 130, y - 90)
Draw_window (+ 20 x, y - 20)
Draw_window (x + 130, y - 20)


Def draw_window (x, y) :
# glass
Pygame. The draw. The rect (screen, random_color (), (x, y - 50, 50, 50))
Frame #
Pygame. The draw. The rect (screen, (0, 0, 0), (x, y - 50, 50, 50), 5)
Pygame. The draw. The rect (screen, (0, 0, 0), (5, 23, x + y - 50, 50))
Pygame. The draw. The rect (screen, (0, 0, 0), (x, y - 27, 50, 5))


Def draw_butterfly (x, y, size) :
Pygame. The draw. Polygon (screen, random_color (), [[x + 0, y + 0], [+ size * 10 x, y + 0], [x + size * 17, y + size * 10], [x + size * 17, y + size * 18], [x + size * 5, y + size * 18]])
Pygame. The draw. Polygon (screen, random_color (), [[x + size * 36, y + 0], [x + size * 26, y + 0], [x + size * 19, y + size * 10], [x + size * 19, y + size * 18], [x + size * 31, y + size * 18]])
Pygame. The draw. Polygon (screen, random_color (), [[x + 0, y + size * 40], [+ size * 10 x, y + size * 40], [x + size * 17, y + size * 30], [x + size * 17, y + size * 22], [x + size * 5, y + size * 22]])
Pygame. The draw. Polygon (screen, random_color (), [[x + size * 36, y + size * 40], [x + size * 26, y + size * 40], [x + size * 19, y + size * 30], [x + size * 19, y + size * 22], [x + size * 31, y + size * 22]])
Pygame. The draw. The ellipse (screen, (0, 0), [x + size * 13, y + size * 10, size * 10, size * 20])
Pygame. The draw. The line (screen, (0, 0), [x + size * 16, y + 0], [x + size * 18, y + size * 20], 2)
Pygame. The draw. The line (screen, (0, 0), [x + size * 20, y + 0], [x + size * 18, y + size * 20], 2)


# this function is able to draw clouds of company sizes
Def draw_cloud (x, y, size) :
# put int () around any multiplications by decimals to get rid of this warning:
# DeprecationWarning: integer argument expected, got float
Pygame. The draw. Circle (screen, (255, 255, 255), (x, y), int (size *. 5))
Pygame. The draw. Circle (screen, (255, 255, 255),
(int (x + size *. 5), y), int (size *. 6))
Pygame. The draw. Circle (screen, (255, 255, 255),
(x + size, int (y - size *. 1)), int (size *. 4))


# green ground
Pygame. The draw. The rect (screen, (0, 160, 3), (0, 400, 640, 80))
# light blue sky
Pygame. The draw. The rect (screen, (100, 200, 255), (0, 0, 640, 400))

Draw_tree (60, 400) # x and y locations are the bottom left of the tree trunk
Draw_tree (550, 400)
Draw_tree (450, 420)
Draw_tree (85, 450)

Draw_house (225, 400)

Draw_cloud (60, 120, 80)
Draw_cloud (200, 50, 40)
Draw_cloud (450, 100, 120)
Draw_cloud (300, 50, 70)

Draw_butterfly (50,50,1)
,80,2 draw_butterfly (150)
Draw_butterfly (430200, 3)

Pygame. Display. Flip ()

Running=True
While running:
For the event in pygame. Event. The get () :
If the event. The type==pygame. QUIT:
Running=False

Pygame. Quit ()
` ` `
Do translation requirements is 1. The cloud, x over the border to appear on the other side of the
2. Butterflies do Brownian motion (no more than the screen borders)

Foreign teachers gave a simple example to load the picture and then moving picture code
But you need to get behind the generation x, y and the breadth thereof into the

I for a long time did not find posts how to get a single graphics or a set of graphics (cloud) numerical
If you can want to consult the

Python is completely white, for the first time contact points to the foreign teachers miserably xi xi

CodePudding user response:

Foreign teachers to give examples of images of moving
 
# setup
The import pygame
The import math
The from scipy. Stats import norm
The import time

Pygame. The init ()
Screen=pygame. Display. Set_mode ([640, 480])
White=[255, 255, 255]


Def simple_movement (x, y, s_x, s_y) :
Return int (x + s_x), int (y + s_y)


Def sin_movement (x, y, s_x, s_y) :
Return int (x + s_x), int (y + math.h sin ((x + s_x)/screen. Get_width math.h () * 2 * PI * s_y) * my_R get_height ())


Def Brownian_movement (x, y, s, delta, dt) :
Return int (x + s * norm in RVS * * 2 * dt (delta), int (y + s * norm in RVS (delta * * 2 * dt))


# the load of the R image (must be saved in the same place as this file)
My_R=pygame. Image. The load (' R.j pg)

# set the variables to use in our program
X_Rh=0
Y_Rh=2 * my_R get_height ()
Speed_x_Rh=5
Speed_y_Rh=0

X_Rs=0
Y_Rs0=screen. Get_height () - 3 * my_R get_height ()
Speed_x_Rs=2.5
Speed_y_Rs=5

X_Rr=screen. Get_width ()/2
Y_Rr=screen. Get_height ()/2
Speed_Rr=50
The delta=0.25
Dt=0.1
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related