User Tools

Site Tools


user:escoute1:portfolio:hpc0project2

Project: Automated Drawing

A project for HPC0 by Eric Scouten

This project was begun on 2/4/2013 and is anticipated to take 4 days. Actually took a pretty long time, due to the nature of having to continually do trial and error with mouse movements.

Objectives

To create a shell-script program that automatically draws whatever it is programmed to.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • Basic understanding of shell script
  • Understanding of Linux
  • man xte
  • man xpaint
  • man xwit
  • man xwininfo

Background

Attempting to create a script that can draw a landscape or picture of some sort using xpaint and xte/xwit

xwit is an X window interface tool. By default when used with no arguments in an xterm it de-iconifies and raises the window. You can specify a different function to do, such as iconifying the window, and apply it to several windows whose name begins with one of the given strings, or a particular window id given, or the window id found in the environment variable WINDOWID (which is set by xterm for the program it runs).

xte is a program that generates fake input using the XTest extension, more reliable than xse.

xwininfo is a utility for displaying information about windows. Various information is displayed depending on which options are selected. If no options are chosen, -stats is assumed.

The user has the option of selecting the target window with the mouse (by clicking any mouse button in the desired window) or by specifying its window id on the command line with the -id option. Or instead of specifying the window by its id number, the -name option may be used to specify which window is desired by name. There is also a special -root option to quickly obtain information on the screen's root window.

Code

The First Version: The Square

#!/bin/bash
#
#
#
 
pkill -9 xpaint
xpaint -canvas -size 1024x768&
sleep 3s;
xte 'mousemove 800 1000'
sleep 1s;
xte 'mouseclick 1'
sleep 1s;
xte 'mousemove 25 150'
sleep 0.5s;
xte 'mouseclick 1'
sleep 0.5s;
xte 'mousemove 500 500'
sleep 0.5s;
xte 'mousedown 1'
sleep 0.25s;
xte 'mousemove 500 600'
sleep 0.25s;
xte 'mousemove 400 600'
sleep 0.25s;
xte 'mousemove 400 500'
sleep 0.25s;
xte 'mousemove 500 500'
xte 'mouseup 1'

Version 2: Consistency

#!/bin/bash
#
#
#
 
pkill -9 xpaint
xpaint -canvas -size 1024x768&
sleep 3s;
xwit -pop -id 0x3c0019a -resize 1280 937
sleep 1s;
xte 'mousemove 150 120'
sleep 0.5s;
xte 'mouseclick 1'
sleep 0.5s;
xwit -pop -id 0x3c00678
xte 'mousemove 500 500'
sleep 0.5s;
xte 'mousedown 1'
sleep 0.25s;
xte 'mousemove 500 600'
sleep 0.25s;
xte 'mousemove 400 600'
sleep 0.25s;
xte 'mousemove 400 500'
sleep 0.25s;
xte 'mousemove 500 500'
xte 'mouseup 1'

Version 3: The Circle

#!/bin/bash
#
#
#
r=400
pi=$(echo "scale=10; 4*a(1)" | bc -l)
 
 
pkill -9 xpaint
xpaint -canvas -size 1280x937&
sleep 3s;
xwit -pop -id 0x3c0019a -resize 1280 937
sleep 1s;
xte 'mousemove 150 120'
sleep 0.1s;
xte 'mouseclick 1'
sleep 0.1s;
xwit -pop -id 0x3c00678
xte 'mousemove 500 550'
sleep 0.1s;
xte 'mousemove 1040 512'
sleep 3s;
xte 'mousedown 1'
 
for ((n=0; n<360; n++));do
x=`echo "640 + (${r}*c(${n}*${pi}/180))" | bc -l`
y=`echo "512 + (${r}*s(${n}*${pi}/180))" | bc -l` 
 
xwit -root -warp $x $y
done
xte 'mouseup 1'

Poptart with a Bootiful Diamon Ring!

#!/bin/bash
#
#
#
pi=$(echo "scale=10; 4*a(1)" | bc -l)
 
 
pkill -9 xpaint
sleep 2s;
xpaint -canvas -size 1280x937&
sleep 3s;
xwit -pop -id 0x3a0019a -resize 1280 937
sleep 1s;
xte 'mousemove 150 120'
sleep 0.1s;
xte 'mouseclick 1'
sleep 0.1s;
xwit -pop -id 0x3a00678
xte 'mousemove 570 120'
xte 'mouseclick 1'
sleep 1s;
xte 'mousemove 60 120'
xte 'mouseclick 1'
sleep 1s;
xwit -pop -id 0x3a00678
xte 'mousemove 60 110'
xte 'mouseclick 1'
sleep 1s;
xte 'mousemove 300 220'
xte 'mousedown 1'
sleep 0.5s;
xte 'mousemove 200 690'
sleep 0.5s;
xte 'mousemove 960 690'
sleep 0.5s;
xte 'mousemove 1060 220'
sleep 0.5s;
xte 'mousemove 300 220'
xte 'mouseup 1'
sleep 0.5s;
xwit -pop -id 0x3a0019a
xte 'mousemove 1050 120'
xte 'mouseclick 1'
sleep 0.5s;
xwit -pop -id 0x3a00678
sleep 0.5s;
xte 'mousemove 640 400'
xte 'mouseclick 1'
sleep 0.5s;
xwit -pop -id 0x3a0019a
sleep 0.5s;
xte 'mousemove 25 120'
xte 'mouseclick 1'
sleep 1s;
xwit -pop -id 0x3a00678
sleep 1s;
xte 'mousemove 275 100'
xte 'mouseclick 1'
xte 'mousemove 350 255'
xte 'mousedown 1'
sleep 0.5s;
xte 'mousemove 1000 255'
xte 'mousemove 915 640'
xte 'mousemove 265 640'
xte 'mousemove 350 255'
xte 'mouseup 1'
sleep 0.5s;
xwit -pop -id 0x3a0019a
xte 'mousemove 1050 120'
xte 'mouseclick 1'
sleep 0.5s;
xwit -pop -id 0x3a00678
xte 'mousemove 640 400'
xte 'mouseclick 1'
sleep 0.5s;
xte 'mousemove 295 110'
xte 'mouseclick 1'
xte 'mousemove 500 75'
xte 'mouseclick 1'
sleep 1s;
xte 'key BackSpace'
sleep 1s;
xte 'key 5'
sleep 1s;
xte 'mousemove 45 255'
sleep 2s;
xte 'mouseclick 1'
xwit -pop -id 0x3a0019a
sleep 1s;
xte 'mousemove 725 110'
xte 'mouseclick 1'
sleep 0.5s;
xwit -pop -id 0x3a00678
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "365 + ($n / 4) + $(( r %= 20 ))" | bc -l`
y=`echo "580 - ($n - 0.5) - $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
 
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "420 + ($n / 2) + $(( r %= 20 ))" | bc -l`
y=`echo "340 + $n + 2 + $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "520 + ($n / 4) + $(( r %= 20 ))" | bc -l`
y=`echo "580 - ($n - 0.5) - $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "550 + ($n / 2) + $(( r %= 20 ))" | bc -l`
y=`echo "340 + $n + 2 + $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "675 + ($n / 4) + $(( r %= 20 ))" | bc -l`
y=`echo "580 - ($n - 0.5) - $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "740 + ($n / 2) + $(( r %= 20 ))" | bc -l`
y=`echo "340 + $n + 2 + $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
for ((n=0; n<240; n++));do
r=$RANDOM
x=`echo "850 + ($n / 6) + $(( r %= 20 ))" | bc -l`
y=`echo "580 - ($n - 0.5) - $(( r %= 20 ))" | bc -l`
 
xwit -root -warp $x $y
xte 'mouseclick 1'
done
xte 'mouseclick 2'
xte 'mousemove 220 110'
xte 'mouseclick 1'
xwit -pop -id 0x3a0019a
xte 'mousemove 20 120'
sleep 0.5s
xte 'mouseclick 1'
sleep 2s;
xwit -pop -id 0x3a00678
xte 'mousemove 640 240'
xte 'mousedown 1'
sleep 1s;
for ((n=90; n<360; n++));do
r=25
x=`echo "640 + (${r}*c(${n}*${pi}/180))" | bc -l`
y=`echo "215 + (${r}*s(${n}*${pi}/180))" | bc -l` 
 
xwit -root -warp $x $y
done
xte 'mouseup 1'
xte 'mousemove 295 110'
xte 'mouseclick 1'
xwit -pop -id 0x3a0019a
sleep 1s;
xte 'mousemove 725 110'
xte 'mouseclick 1'
sleep 0.5s;
xwit -pop -id 0x3a00678
xte 'mousemove 640 190'
sleep 1s;
xte 'mouseclick 1'
xte 'mousemove 620 170'
xte 'mouseclick 1'
xte 'mousemove 635 160'
xte 'mouseclick 1'
xte 'mousemove 656 180'
xte 'mouseclick 1'
xte 'mousemove 640 190'
xte 'mouseclick 1'
xte 'mouseclick 2'
sleep 1s;
xwit -pop -id 0x3a0019a
xte 'mousemove 1050 120'
sleep 0.5s;
xte 'mouseclick 1'
sleep 1s;
xwit -pop -id 0x3a00678
xte 'mousemove 640 180'
sleep 0.5s;
xte 'mouseclick 1'
xwit -pop -id 0x3a0019a
xte 'mousemove 20 120'
sleep 0.5s
xte 'mouseclick 1'
sleep 2s;
xwit -pop -id 0x3a00678
xte 'mousemove 285 110'
xte 'mouseclick 1'
sleep 1s;
xte 'mousemove 640 180'
sleep 1s;
xte 'mousedown 1'
xte 'mousemove 620 170'
xte 'mousemove 653 178'
xte 'mouseup 1'

Execution

Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:

pod01:~/mystuff$ ./autodrawtest

Reflection

I learned that making an automated drawing, of anything, is very time consuming but yet very rewarding! I'll probably remember this for a long time.

user/escoute1/portfolio/hpc0project2.txt · Last modified: 2013/03/06 13:37 by escoute1