pygame scale

Solutions on MaxInterview for pygame scale by the best coders in the world

showing results for - "pygame scale"
Nicole
29 Aug 2019
1import pygame
2picture = pygame.image.load(filename)
3picture = pygame.transform.scale(picture, (1280, 720))
4
Kenza
22 May 2017
1"""Load image"""
2# I'm loading an image, but that does not matter.
3surface = pygame.image.load("path/to/file.png").convert()
4# Documentation for Surface.convert() and Surface.convert_alpha():
5# https://www.pygame.org/docs/ref/surface.html#pygame.Surface.convert
6
7"""Scale / resize surface"""
8surface = pygame.transform.scale(surface=surface, size=(50, 50))
9# In depth documentation:
10# https://www.pygame.org/docs/ref/transform.html#pygame.transform.rotate
María Paula
22 Sep 2020
1pygame.transform.scale(Surface, (width, height), DestSurface = None)
Emil
04 Mar 2019
1import pygame
2import pygame.font
3
4pygame.init()
5size = (400,400)
6screen = pygame.display.set_mode(size)
7clock = pygame.time.Clock()
8
9def blitRotate(surf, image, pos, originPos, angle):
10
11    # calcaulate the axis aligned bounding box of the rotated image
12    w, h       = image.get_size()
13    box        = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]]
14    box_rotate = [p.rotate(angle) for p in box]
15    min_box    = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1])
16    max_box    = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1])
17
18    # calculate the translation of the pivot 
19    pivot        = pygame.math.Vector2(originPos[0], -originPos[1])
20    pivot_rotate = pivot.rotate(angle)
21    pivot_move   = pivot_rotate - pivot
22
23    # calculate the upper left origin of the rotated image
24    origin = (pos[0] - originPos[0] + min_box[0] - pivot_move[0], pos[1] - originPos[1] - max_box[1] + pivot_move[1])
25
26    # get a rotated image
27    rotated_image = pygame.transform.rotate(image, angle)
28
29    # rotate and blit the image
30    surf.blit(rotated_image, origin)
31
32    # draw rectangle around the image
33    pygame.draw.rect (surf, (255, 0, 0), (*origin, *rotated_image.get_size()),2)
34
35font = pygame.font.SysFont('Times New Roman', 50)
36text = font.render('image', False, (255, 255, 0))
37image = pygame.Surface((text.get_width()+1, text.get_height()+1))
38pygame.draw.rect(image, (0, 0, 255), (1, 1, *text.get_size()))
39image.blit(text, (1, 1))
40w, h = image.get_size()
41
42angle = 0
43done = False
44while not done:
45    clock.tick(60)
46    for event in pygame.event.get():
47        if event.type == pygame.QUIT:
48            done = True
49        elif event.type == pygame.KEYDOWN:
50            if event.key==pygame.K_ESCAPE:
51                done = True
52
53    pos = (screen.get_width()//2, screen.get_height()//2)
54    pos = (200, 200)
55
56    screen.fill(0)
57    blitRotate(screen, image, pos, (w//2, h//2), angle)
58    angle += 1
59
60    pygame.draw.line(screen, (0, 255, 0), (pos[0]-20, pos[1]), (pos[0]+20, pos[1]), 3)
61    pygame.draw.line(screen, (0, 255, 0), (pos[0], pos[1]-20), (pos[0], pos[1]+20), 3)
62    pygame.draw.circle(screen, (0, 255, 0), pos, 7, 0)
63
64    pygame.display.flip()
65
66pygame.quit()
67
Leon
29 Oct 2020
1#Start Libraries
2import pygame, sys
3from pygame.locals import *
4#End Libraries
5
6pygame.init() #We're initializing the script
7
8pygame.display.set_caption('Platform') #This is the name of the window
9window_size = (600,400) #The size of the window
10screen = pygame.display.set_mode(window_size) #Initializing the screen
11
12image_not_scaled = pygame.image.load('file_path.png').convert() #Importing the image
13image = pygame.transform.scale(image_not_scaled, (32, 32)) #You can insert whatever you want for example (64, 64)
14														   #It MUST be a tuple
15
16#Now we'll create the while loop
17run = True #With this we can control the script (stop it)
18while run: #For NOW itz a simple while true
19    screen.fill((255, 255, 255)) #Filling the screen with white
20    screen.blit(image, (0, 0)) #Blitting the image on the screen
21
22    for event in pygame.event.get(): #Checking the events
23        if event.type == QUIT: #Checking if the event is QUIT
24            pygame.quit() #In that case we'll exit from pygame
25            sys.exit() #In that case we'll exit from the script
26    
27    pygame.display.update() #Updating the screen
28
queries leading to this page
how to scale and transform image pygamephoto size in pygame 5d 5cpython pygame how to change the size of an imageresize pygame imagehow to scale down pygame imagepygame get size of scaled imagepygame load image sizechange the resolution of a picture in pygamepygame upscale imagereduce the image size in pygamerotating image pygamepygame size imagescale an image pygamepygame rect rotatepygame scale percentagepytgame transform rotate 28 29pygame image rotatepygame transform flip vs rotatepygame change imagehow do i shrink a image in pygame in pythonpygame rotate surfacehow to rotate a image in pygamehow to scale images in pygamepython pygame display image biggerhow to rotate from centre of image pygamehow can i render jpeg images in pygamehow to downscale an image pygamehow to rotate image through mouse in pygamehow to resize images in pygamechange size image pygamesetting the size of an image in pygamepygame scale imgpygame load images and scale itrisizable image in pygamepygame transform laplacian 28 29how to rotate an image around it center in pygamepygame scale up imagepygame transform scale 28 29how to shrink a picture pygamescale image in pygamehow to resize pygame imagecustomize the width of an image pygamepygame make window scaleablehow to scale images pygamepygame rotate objecthow to resize image in pygamehow to shrink image size pygameresize surface pygamepygame how to increase image sizehow to scale in pygamepygame rotate image around pointhow to rotate a image to mouse in pygamepygame rotate memorypygame how to upscale imgaepygame load and scalepygame set image sizepygame how to change scalepygame image width how to change a picture position in pygamehow to change size of image in pygamehow to alter image size pygame blithow to rotate img in pygame horizontalypygame rotate matrixpygame image resolutionpygame rotate transformpygame rescale imagehow to resize and display an image in pygamehow to set image size in pygamehow to rotate an image using rect and vector in pygamehow to make an image rotate in pygamehow to rotate a sprite pygamepygame transform rotatescale down image pygamepygame set rotation of imagepygame trasnform scalepygame size of imagepygame resize picturepygame rotate image resize img pygamerotate image python pygamepygame rotate image around centerpygame image stretchblit rotate pygamepygame scale an image downpygame scalepgygame resize imagehow to stretch a image in pygamehow to get an image size in pygamepygame shrink imageshrink image pygamescale transformation image in pygamehow to resize an image in pygameimage size pygamehow to increase the size of the image in pygamepygame resize iamgeresize images in pygamehow to make a cimage grow then shrink in pygamepygame alter image sizepygame flip imageresize a picture pygamehow to change a images size in pygamehow to downscale an image in pygamehow to upscale image pygamescaling a pygame imagepygame how to resize a pic to screen sizehow to modify screen size to picture pygamehow to rotate an image with pygamehow to make pygame tranform scale betterresize an image in pygameset rotation of image pygamehow to change the size of an image in pygameresize pygame load imagerotater img pygamehow to resize in pygameupscale images pygamepygame scale down imagerescalse image pygametransform size of picture pygamepygame image scalingpygame set image rotationtransform image on load pygamepygame rotationhow to resize imgs in pygametransform rotate pygamepygame transform scale 2xpygame transform rotatepygame image render sizepygame change width of imageresize and imagepygamehow to change size of image pygamehow to change size of a picture pygamepygame surface get rotationpygame rotate image around pivotpygame how to resize an impygame resize imagherotate an image pygamesmooth transformation pygameimage size adjust on pygamepython pygame how to scale an objectrotate image pygaempygame rotate image 5chow to make an image bigger in pygameresize an image pygameresize image in pygamerezise object pygamehow to rotate picture in pygamepython pygame rotate functioncan you change the size of an image in pygamescaling image in pygamescaling images in pgamepygame transform image sizeztransform image pygamepygame zoomhow to changet the size of picture in pygame 5chow can we rotate a image about a point in pygamehow to change scale of an image in pygameresizing images in pygamepygame blit rotationhow to rotate image in pygamehow to scale image pygamepygame image sizeblit an image pygame at double sizepygame rotate a drawn recthow to shrink image pygamerotate image in pygamehow to change the size of a image python pygamehow to load images with pygame with scalehow to scalle up an image i npygamepygame draw blit image smallertranformation image in pygamepygame image resizehow to rotate img in pygamepygame transform fliphow to define size of image in pygamechange size of image in pygamehow to rotate images in pygamepygame sizehow to change the size of picture in pygame 5cauto scale to display size pygamecan you downsize a photo in pygamepygame scale image to halfmake picture bigger pygamepygame scale image 2xhow to size an image pygamepygame image transformpython pygame how to add a scalepygame rotate spritepython pygame resize imagepygame scale rectpygame transform rotozoompygame make smallerrotate image pygamepygame scale imagepygame make an image rotate around a pointpygame stretch imagepygame get image scalerotate recntanlge image pygamehow to rotate a image in pygamewpygame rotatehow to shrink a image in pygamepygame transform scale 28pygame image loadpygame image wont scalehow to increase the size of an image in pygamehow to change the size of images pygamepygame crop imagehow to change the size od an image in pygame pythonrotate image from center pygamehow to rotate a picture in pygamehow to scale image in pygamepygame get image sizepygame transform scalepygame transform scalepygame transform scale 28pygame image load 28 29 29can we change the resolution of an image in pygame 3fpygame make an image rotate over a pointhow to rotate an image pygamepygame how to change a pictures sizepygame rotate image centerpygame image rotatepygame scale all imagespygame image transform scalescaling images pygamemake image smaller pygamepygame transformpygame scale imageshow to resize an image in pygame without losing qualitypygame display and scale image on screenpygame change surface sizetransform pygamehow to rotate an image in pygamepygame image resizepygame image rotationset size of pygame imgpygame load image at scalehow to change capacity of image in pygamepygame background image full screenscale image to be smaller in pygamehow to scale a image in pygametransform an image on a surfacep 5bygame resize imagehow to rotate a image about a point in pygamehow to scale screen size to image in pygamepygame resize an imagehow make an image smaller in pygamehow to reduce the dimensions of an image in pygameset rotation of image in pygamerotation image pygamepygame transform scale 28 29pygame blit scaleresize loaded image pygamechange image size pygamepygame transform scale examplechange image sixe pygamehow to scale and rotate image in pygamepygame change angle of imagehow to change a size of an image in pygameenlarge a texture pygamepygame resize pnghow ro resize an imag3e in pygamescale image to window pygamehow to rotate image to a angle in pygameptgame rotate imagepygame draw image with set sizehow to change the scale of a picture in pygameresizing image pygamechange the size of an image pygamehow to resize an image in python using pygamescale pygame imagechange the image size in pygamehow to rotate images in pygame on an axisscale surface pygameset scale pygamepygame scale surfacepygame rotate image to mousepygame changing size of imagepygame scaling not working on full imagepygame rotate imagespygame scale an imagepygame how to change image sizescale img pygamerotate image around center pygamepygame scale image to fit rectanglepygame convert size of imagepygame increase image sizepygame how to change picture 27s sizerotate a surface pygmaepygame transform rotate objectrotate img pygamescale an image up pygamepygame change resolution of imagerotate rect pygamerotate in pygamepygame how to resize an imagehow do i shrink a image in pygamepygame how do i scale an image by 1 5how to rotate image pygamehow to resize image pygamepygasme scalepygame how to scale imagehow to change the size of image in pygamepygame scale image sizeshould resized images be converted pygamepygame image scaleset dimensions of image pygamehow to change image size in pygamepygame change the size of imagepygame change image based on pixel sizepygame make an image rotate around a point outside the imagepygame make image biggerresizing images pygamepygame transform rotatehow to change the dimesions of an image pygamerotate image crashing pygamepygame image dimensionshow to change the size of imges in pygamehow to transform scale in pygamerescale image pygameresize image pygamehow to rotate an image in pygame around a pointpygame blit image smallerhow to reduce the scale of an image python pygametransform scale in pygamehow to resize an image to smaller in pygamescale images to window size pygamescaling pygame imageimage pygame transform positionpygame image shrink to sizempygame scale imagepygame transform scaletransform scale documentation pygamedraw image bigger pygamehow to scale an image pygamescale image pygamepygame changingsize of imagepygame image set sizerotate photo in pygamehow to shrink an image in pygamehow to change the scale in pygame of an imgagechange size of image pygamehow to resize image with pygamepygame rotating imagescale tranformation image in pygamehow to shrink an image pygamebetter pygame transform scalescreen blit sizemake image bigger pygamepygame resize imagepygame load image resizetransform image scale pygamechange image size in pygamepygame scaling imagescale pygamewhy isn pygame transform scale workingscale an image down pygamehow to make image smaller pygamepygame transform scale 28pygame image load pygame latest versionpygame image rotate centerpygame transform recalepygame rotatinghow to scale an image in pygamerotate images in pygamerotate pygamescale pygame surfacepygame image transform rotate 28 29how to decrease size of an image in pygamepygame transform rotate 28 29pygame resize image resolutionpygame how to resize imagepygame change size of imagehow to resize imag ein pygamepygame transform fliphow to resize a image pygamehow to size up images in pygameset image size pygameimage scale pygamehow to resize an image pygamepygame display and scale imagehiw ti resize image in pytgamehow to upscale an image pygamepygame resizepygame how to scalehow to set the scale of an image in pygamepygame function that rotate an imagechange size image python pygametransform scale pygamepygame transformpygame change image sizehow to scale an image by 2 in pygamepygame size of a scaled imagehow to decrease the image size in pygamepygame scale image downpygame resize imapygame change angle imagespygame how to scale an imagehow to make an image smaller in pygamepygame scale