#!/usr/dt/bin/dtksh # # xlinedemo - a demo of the X11 capabilities Desktop Korn Shell, dtksh. # Written on Solaris. # # 01-Apr-2004, ver 0.70 # # Written for a 24-bit colour display. On non-Solaris, check the path of your # dtksh (may not be "/usr/dt/bin/dtksh"). # # USAGE: xlinedemo # # See the code for customisation such as window size and colours. # # COPYRIGHT: Copyright (c) 2004 Brendan Gregg. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # (http://www.gnu.org/copyleft/gpl.html) # # 01-Apr-2004 Brendan Gregg Created this delay=20 # frame delay (ms) max_x=500 # window size x max_y=500 # window size y colour_fg=MidnightBlue # line colour colour_bg=SkyBlue # background colour # # --- Create X11 window --- # XtInitialize TOP linedemo Linedemo $0 XtCreateManagedWidget FORM form XmForm $TOP \ resizePolicy:RESIZE_NONE \ height:$max_y width:$max_x x:0 y:0 XtCreateManagedWidget DRAW draw XmDrawingArea $FORM \ height:$max_y width:$max_x x:0 y:0 \ background:$colour_bg foreground:$colour_bg XtDisplay DISPLAY $FORM XSync $DISPLAY true XtRealizeWidget $TOP XtWindow WINDOW $DRAW # # --- Initial line coordinates --- # old_x1=10 old_y1=10 old_x2=40 old_y2=10 x1=11 y1=11 x2=41 y2=11 xx1=1 xx2=2 yy1=3 yy2=4 # # --- Draw line function --- # function drawline { ### Calculate new line position (( x1 = x1 + xx1 )) (( x2 = x2 + xx2 )) (( y1 = y1 + yy1 )) (( y2 = y2 + yy2 )) if (( x1 < 0 || x1 > max_x )); then (( x1 = x1 - 2*xx1 )) if (( x1 < 10 )); then (( xx1 = $RANDOM % 6 + 1 )) else (( xx1 = - $RANDOM % 6 - 1 )) fi fi if (( x2 < 0 || x2 > max_x )); then (( x2 = x2 - 2*xx2 )) if (( x2 < 10 )); then (( xx2 = $RANDOM % 6 + 1 )) else (( xx2 = - $RANDOM % 6 - 1 )) fi fi if (( y1 < 0 || y1 > max_y )); then (( y1 = y1 - 2*yy1 )) if (( y1 < 10 )); then (( yy1 = $RANDOM % 6 + 1 )) else (( yy1 = - $RANDOM % 6 - 1 )) fi fi if (( y2 < 0 || y2 > max_y )); then (( y2 = y2 - 2*yy2 )) if (( y2 < 10 )); then (( yy2 = $RANDOM % 6 + 1 )) else (( yy2 = - $RANDOM % 6 - 1 )) fi fi ### White out old line # XDrawLine $DISPLAY $WINDOW \ # -foreground $colour_bg \ # -line_width 1 \ # -line_style LineSolid \ # $old_x1 $old_y1 $old_x2 $old_y2 ### Draw new line XDrawLine $DISPLAY $WINDOW \ -foreground $colour_fg \ -line_width 1 \ -line_style LineSolid \ $x1 $y1 $x2 $y2 ### Save old position old_x1=$x1 old_y1=$y1 old_x2=$x2 old_y2=$y2 XtAddTimeOut ID $delay drawline # pause, then draw next } # # --- Main --- # XtAddTimeOut ID $delay drawline # pause, then draw line XtMainLoop