Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

So use Python to achieve good-looking water wave effects.

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "so using Python to achieve good-looking water wave special effects". In daily operation, I believe that many people have doubts about using Python to achieve good-looking water wave special effects. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "so using Python to achieve good-looking water wave special effects". Next, please follow the editor to study!

I. operating environment

1) Environmental installation

Python3, Pycharm, Pygame module part of the built-in module is not displayed. (if you need to install packages, activation codes, etc., directly

I can install questions and answers by private message.

Installation of third-party libraries:

Pip install pygame or pip install-I https://pypi.douban.com/simple/ + module name with mirror source

Second, effect display

The screenshot doesn't seem to show the fluctuating effect of the water. Hey, I can't be a little lazy, so I didn't shoot the video, so we'll just watch the horn.

The real video effect is good! It ripples with the water.

1) the first group of random landscape maps

2) the second group of random figures

3) the third group of real-life pictures

3. The code shows "import pygame, osfrom pygame.locals import * from math import sin # the toolbox for importing sine function import timemain_dir = os.path.split (os.path.abspath (_ _ file__)) [0] # gets the path of the current file def main (): pygame.init () # initialization screen = pygame.display.set_mode ((640,480)) HWSURFACE | DOUBLEBUF) # generate a window imagename = os.path.join (main_dir, 'data') 'liquid.bmp') # stitching image path bitmap = pygame.image.load (imagename) # load picture bitmap = pygame.transform.scale2x (bitmap) # magnify the image twice bitmap = pygame.transform.scale2x (bitmap) # magnify the image twice if screen.get_bitsize () = = 8: # get the image and screen screen.set_palette in the same format (bitmap .get _ palette () else: bitmap = bitmap.convert () anim = 0.0 while 1: for e in pygame.event.get (): # handle event if e.type in [QUIT KEYDOWN, MOUSEBUTTONDOWN]: return anim = anim + 0.02 for x in range: # simulating the fluctuation effect of water xpos = (x + (sin (anim + x * .01) * 15)) + 20 for y in range (0480) 20): ypos = (y + (sin (anim + y * .01) * 15)) + 20 screen.blit (bitmap, (x, y), (xpos, ypos, 20,20) pygame.display.flip () # Update time.sleep (0.01) # wait for 0.01sif _ _ name__ = ='_ main__': main () to come here The study on "so using Python to achieve good-looking water wave effects" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report