Guest User

Hello World in G'MIC

a guest
Jun 2nd, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.51 KB | None | 0 0
  1.  
  2. hello :
  3.   -verbose -  # Make console output silent
  4.   -local[]    # Start a new empty environment
  5.  
  6.   # Create a 480x300 color background image.
  7.   -input[background] 480,300,1,3,"
  8.    y<0.75*h?
  9.      (a = y/h/0.75; [32*a,96*a,165*a] ):
  10.      (a = (y - 0.75*h)/0.25/h; [255*a,128*a,0] )"                       # Specify formula to create color gradient
  11.   -text. "Try mouse buttons... Keys ESC or Q to quit",5,{h-18},13,1,255  # Add small notice at the bottom
  12.  
  13.   # Create text sprites (normal and mirrored versions).
  14.   -input[text_color] 0 -text. " Hello\nWorld !",0,0,54,1,128,255,64,1 # RGBA text sprite
  15.   -split. c,-3 -dilate. 5 -name. text_mask  # Divide into two images : RGB (text_color) and dilated A (text_mask)
  16.   --mirror. y -name. text_mask_shadow       # Get mirrored version of the text mask for the shadow
  17.   -input[text_color_shadow] 100%,100%,1,3   # RGB sprite for shadow sprite (with default color: black)
  18.  
  19.   # Initialize motion variables.
  20.   x={(w#$background-w)/2}  # Position 'x' is initially at the middle of the background
  21.   y={(h#$background-h)/2}  # Position 'y' is initially at the middle of the background
  22.   vy=0 vx=0                # Define x and y velocities
  23.   ax=0 ay=0                # Define x and y accelerations
  24.  
  25.   # Start animation loop.
  26.   -do
  27.     --image[background] [text_color],$x,$y,0,0,1,[text_mask]             # Draw text in background and returns it as a new image
  28.     y_shadow={1.5*h-$y-h#$text_color_shadow}                             # Compute the location for drawing the shadow
  29.     -image. [text_color_shadow],$x,$y_shadow,0,0,0.3,[text_mask_shadow]  # Draw shadow of the text sprite as well
  30.     -window. -1,-1,0,"Hello World Demo"                                  # Update window content with created frame
  31.     -remove.                                                             # Remove the animation frame
  32.  
  33.     # Manage sprite motion and collisions.
  34.     x+=$vx vx+=$ax           # Compute new x-position and x-velocity
  35.     y+=$vy vy+={0.5+$ay}     # Compute new y-position and y-velocity (add 0.5 for the gravity!)
  36.  
  37.     -if {$x<=0" || "$x+w#$text_color>=w#$background} # Detect collision with left and right borders
  38.       x={max(0,min($x,w#$background-w#$text_color))} # Constrain the x-coordinates to stay inside image
  39.       vx={-$vx}                                      # Revert the x-velocity
  40.     -endif
  41.     -if {$y+h#$text_color>0.75*h#$background}        # Detect collision with the ground
  42.       vy=-12                                         # Set new y-velocity (for bouncing)
  43.     -endif
  44.  
  45.     ax*=0.5 ay*=0.5                                  # Decrease motion acceleration
  46.  
  47.     # Manage mouse events
  48.     -if {{*,b}&1}                       # Left mouse button -> Set new random accelerations
  49.       vx=0 vy=0
  50.       ax={u(-5,5)} ay={u(-5,5)}
  51.     -endif
  52.     -if {{*,-b}&2}                      # Right mouse button -> Change sprite color
  53.       -repeat {text_color,s}
  54.         -shared[text_color] $>          # Color is changed by random normalizations of all color channels independently
  55.         -normalize. 0,{u(64,255)}
  56.         -remove.
  57.       -done
  58.     -endif
  59.  
  60.     -wait[0] 20                            # Wait a little bit to slow down animation (20ms)
  61.   -while {!{*,ESC}" && "!{*,Q}" && "{*}}   # Continue until keys 'ESC' or 'Q' have been pressed and window stays opened
  62.  
  63.   -remove    # Remove all images used for the demo
  64.   -endlocal  # End local environment (is empty at this point)
  65.   -verbose + # Go back to previous level of verbosity
  66.  
  67. # End of the 'hello' command.
Advertisement
Add Comment
Please, Sign In to add comment