ThorPy

A GUI library for pygame

Examples - Shadows

Full code

The code below shows how to check if the user can generate shadows and how to generate them. We also give a few parameters for the shadow at the end of the code. Note that this code is suitable for generating shadows of objects that are supposed to stand "vertically" on the ground. If not, you can either manually parametrize the shadow by setting its vertical attribute to False or use thorpy.makeup.set_button_shadow.

If you want to use the same awesome character image as the one in the example below, you can find it here.


0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import pygame, thorpy ap = thorpy.Application((500,400), "Shadows example") e_img = thorpy.Draggable(finish=False) image_path = "../documentation/examples/character.png" painter = thorpy.painters.imageframe.ImageFrame(image_path, colorkey=(255,255,255)) e_img.set_painter(painter) e_img.finish() #don't forget to finish if thorpy.constants.CAN_SHADOWS: thorpy.makeup.add_static_shadow(e_img, {"target_altitude":0, "shadow_radius":3}) e_text = thorpy.make_text("Drag the image", 20, (255,0,0)) e_text.stick_to("screen", "top", "top") e_background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG, elements=[e_img, e_text]) menu = thorpy.Menu(e_background) menu.play() ap.quit() ##examples of shadow arguments: ###thorpy.makeup.add_static_shadow(e_img, ### {"target_altitude":10, # altitude (in pixels) of the target ### "shadow_radius":3, # the smaller, the sharper is the shadow ### "sun_angle":60, # angle in degrees of the sun ### "shadow_color":(255,200,0), # color of the shadow ### "alpha_factor":0.5, # alpha factor ### "decay_mode":"linear"}) # linear or exponential