|
| 1 | +#!/bin/bash |
| 2 | +# Produces a bunch of `cmatrix` screenshots and screencasts. |
| 3 | +# This script requires X and the following: |
| 4 | +#apt-get install rxvt byzanz |
| 5 | + |
| 6 | +# NOTE We use rxvt, as we can get a screenshot without fuss (scrollbars, menu, ...), |
| 7 | +# it is fairly simple, |
| 8 | +# and it supports X fonts (unlike xterm and uxterm). |
| 9 | +TERM_EMULATOR_BASE="rxvt +sb" |
| 10 | + |
| 11 | +CAPTURES_DIR="data/img" |
| 12 | + |
| 13 | +# Function to take a single cmatrix screenshot (takes about 3.5s to execute) |
| 14 | +# or optionally, a screncast of choosable length. |
| 15 | +function captureCMatrix() |
| 16 | +{ |
| 17 | + CAPTURE_FILE="$1" |
| 18 | + CMATRIX_OPTIONS="$2" |
| 19 | + # If 0 (default if no 3rd param is given), |
| 20 | + # we make a screenshot instead of a screencast. |
| 21 | + SCREENCAST_DURATION="${3:-0}" |
| 22 | + |
| 23 | + if [ ${SCREENCAST_DURATION} -gt 0 ] |
| 24 | + then |
| 25 | + let KILL_DELAY="${SCREENCAST_DURATION} + 1" |
| 26 | + CAPTURE_FILE="${CAPTURE_FILE}.gif" |
| 27 | + else |
| 28 | + KILL_DELAY=3 |
| 29 | + CAPTURE_FILE="${CAPTURE_FILE}.png" |
| 30 | + fi |
| 31 | + WINDOW_TITLE="CMatrix capture ${CAPTURE_FILE}" |
| 32 | + |
| 33 | + # NOTE the "-PIPE" prevents output of the "Terminated: ..." message |
| 34 | + ( cmdpid=$BASHPID; ( sleep ${KILL_DELAY}; kill -PIPE $cmdpid ) & exec ${TERM_EMULATOR_BASE} -name "${WINDOW_TITLE}" -title "${WINDOW_TITLE}" -e bash -c " |
| 35 | + if [ ${SCREENCAST_DURATION} -gt 0 ] |
| 36 | + then |
| 37 | + # Take screencast (animated GIF) |
| 38 | +
|
| 39 | + # Get this windows X-window-info |
| 40 | + myXwininfo=\$(xwininfo -name \"${WINDOW_TITLE}\") |
| 41 | + # Extract location and size |
| 42 | + read X < <(awk -F: '/Absolute upper-left X/{print \$2}' <<< \"\$myXwininfo\") |
| 43 | + read Y < <(awk -F: '/Absolute upper-left Y/{print \$2}' <<< \"\$myXwininfo\") |
| 44 | + read W < <(awk -F: '/Width/{print \$2}' <<< \"\$myXwininfo\") |
| 45 | + read H < <(awk -F: '/Height/{print \$2}' <<< \"\$myXwininfo\") |
| 46 | + # Record a screencast as gif |
| 47 | + byzanz-record -c --delay=0 --duration=${SCREENCAST_DURATION} --x=\$X --y=\$Y --width=\$W --height=\$H "${CAPTURE_FILE}" & |
| 48 | + else |
| 49 | + # Take screen-shot (PNG image) |
| 50 | +
|
| 51 | + # Take screenshot in 2 seconds |
| 52 | + ( sleep 2 ; xwd -nobdrs -name \"${WINDOW_TITLE}\" -silent | xwdtopnm 2> /dev/null | pnmtopng 2> /dev/null > ${CAPTURE_FILE} ) & |
| 53 | + fi |
| 54 | +
|
| 55 | + # Run cmatrix until the process gets killed |
| 56 | + cmatrix ${CMATRIX_OPTIONS} |
| 57 | + " ) |
| 58 | +} |
| 59 | + |
| 60 | +CMD_CS="captureCMatrix" |
| 61 | +CAPTURE_FILE_BASE="${CAPTURES_DIR}/capture_" |
| 62 | +mkdir -p "${CAPTURES_DIR}" |
| 63 | + |
| 64 | +# Capture a screen session ("video"/animated GIF) |
| 65 | +${CMD_CS} "${CAPTURE_FILE_BASE}orig" "-xba" "5" |
| 66 | +${CMD_CS} "${CAPTURE_FILE_BASE}rainbow" "-xbar" "5" |
| 67 | + |
| 68 | +# From here on, we take several screenshots with different arguments. |
| 69 | +${CMD_CS} "${CAPTURE_FILE_BASE}default" "" |
| 70 | +${CMD_CS} "${CAPTURE_FILE_BASE}bold" "-b" |
| 71 | +${CMD_CS} "${CAPTURE_FILE_BASE}bold_font" "-bx" |
| 72 | +for color in green red blue white yellow cyan magenta black |
| 73 | +do |
| 74 | + ${CMD_CS} "${CAPTURE_FILE_BASE}bold_C_${color}" "-b -C ${color}" |
| 75 | +done |
| 76 | +${CMD_CS} "${CAPTURE_FILE_BASE}bold_rainbow" "-b -r" |
| 77 | + |
0 commit comments