Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hello :
- -verbose - # Make console output silent
- -local[] # Start a new empty environment
- # Create a 480x300 color background image.
- -input[background] 480,300,1,3,"
- y<0.75*h?
- (a = y/h/0.75; [32*a,96*a,165*a] ):
- (a = (y - 0.75*h)/0.25/h; [255*a,128*a,0] )" # Specify formula to create color gradient
- -text. "Try mouse buttons... Keys ESC or Q to quit",5,{h-18},13,1,255 # Add small notice at the bottom
- # Create text sprites (normal and mirrored versions).
- -input[text_color] 0 -text. " Hello\nWorld !",0,0,54,1,128,255,64,1 # RGBA text sprite
- -split. c,-3 -dilate. 5 -name. text_mask # Divide into two images : RGB (text_color) and dilated A (text_mask)
- --mirror. y -name. text_mask_shadow # Get mirrored version of the text mask for the shadow
- -input[text_color_shadow] 100%,100%,1,3 # RGB sprite for shadow sprite (with default color: black)
- # Initialize motion variables.
- x={(w#$background-w)/2} # Position 'x' is initially at the middle of the background
- y={(h#$background-h)/2} # Position 'y' is initially at the middle of the background
- vy=0 vx=0 # Define x and y velocities
- ax=0 ay=0 # Define x and y accelerations
- # Start animation loop.
- -do
- --image[background] [text_color],$x,$y,0,0,1,[text_mask] # Draw text in background and returns it as a new image
- y_shadow={1.5*h-$y-h#$text_color_shadow} # Compute the location for drawing the shadow
- -image. [text_color_shadow],$x,$y_shadow,0,0,0.3,[text_mask_shadow] # Draw shadow of the text sprite as well
- -window. -1,-1,0,"Hello World Demo" # Update window content with created frame
- -remove. # Remove the animation frame
- # Manage sprite motion and collisions.
- x+=$vx vx+=$ax # Compute new x-position and x-velocity
- y+=$vy vy+={0.5+$ay} # Compute new y-position and y-velocity (add 0.5 for the gravity!)
- -if {$x<=0" || "$x+w#$text_color>=w#$background} # Detect collision with left and right borders
- x={max(0,min($x,w#$background-w#$text_color))} # Constrain the x-coordinates to stay inside image
- vx={-$vx} # Revert the x-velocity
- -endif
- -if {$y+h#$text_color>0.75*h#$background} # Detect collision with the ground
- vy=-12 # Set new y-velocity (for bouncing)
- -endif
- ax*=0.5 ay*=0.5 # Decrease motion acceleration
- # Manage mouse events
- -if {{*,b}&1} # Left mouse button -> Set new random accelerations
- vx=0 vy=0
- ax={u(-5,5)} ay={u(-5,5)}
- -endif
- -if {{*,-b}&2} # Right mouse button -> Change sprite color
- -repeat {text_color,s}
- -shared[text_color] $> # Color is changed by random normalizations of all color channels independently
- -normalize. 0,{u(64,255)}
- -remove.
- -done
- -endif
- -wait[0] 20 # Wait a little bit to slow down animation (20ms)
- -while {!{*,ESC}" && "!{*,Q}" && "{*}} # Continue until keys 'ESC' or 'Q' have been pressed and window stays opened
- -remove # Remove all images used for the demo
- -endlocal # End local environment (is empty at this point)
- -verbose + # Go back to previous level of verbosity
- # End of the 'hello' command.
Advertisement
Add Comment
Please, Sign In to add comment