% paint.jam
% last changed by Bill Paxton, March 12, 1982 8:31 am

(paint) 256 .dict .def

paint .begin

(x) 0 .def
(y) 0 .def
(RHWidth) 0 .def
(RHHeight) 0 .def

(RedDown) { (Track) (TrackRed) .load .def Track } .cvx .def
(TrackRed) {	% paint rectangular box
	.translate RHWidth .neg RHHeight .neg RHWidth RHHeight .drawbox } .cvx .def
(RedUp) { (Track) TwoPop Track } .cvx .def

(CtrlRedDown) { (CtrlTrack) (CtrlTrackRed) .load .def CtrlTrack } .cvx .def
(CtrlTrackRed) {	% erase rectangular box
	.pushdc .true .setopaque 0 .setcolor TrackRed .popdc } .cvx .def
(CtrlRedUp) { (CtrlTrack) TwoPop CtrlTrack } .cvx .def

(ShiftRedDown) { (ShiftTrack) TwoPop % discard intermediate positions
	(y) .exch .def (x) .exch .def % save start position
	} .cvx .def
(ShiftRedUp) {
	(:y) .exch .lv (:x) .exch .lv % save end position
	(RHWidth) :x x .sub .abs 2 .div .def	% half width of rectangle
	(RHHeight) :y y .sub .abs 2 .div .def	% half height of rectangle
	} .cvx .def

(CtrlShiftRedDown) { (CtrlShiftTrack) (CtrlShiftTrackRed) .load .def CtrlShiftTrack } .cvx .def
(CtrlShiftTrackRed) {	% invert rectangular box
	.pushdc .setinvert TrackRed .popdc } .cvx .def
(CtrlShiftRedUp) { (CtrlShiftTrack) TwoPop Track } .cvx .def

(.abs) { .dup 0 .lt { .neg } .cvx .if } .cvx .def

(YHWidth) 0 .def
(YHHeight) 0 .def

(YellowDown) { (Track) (TrackYellow) .load .def Track } .cvx .def
(TrackYellow) {	% paint oval
	.translate
	YHWidth .neg 0 .knot
	0 YHHeight .neg .knot
	YHWidth 0 .knot
	0 YHHeight .knot
	.cspline .drawarea } .cvx .def
(YellowUp) { (Track) TwoPop Track } .cvx .def

(CtrlYellowDown) { (CtrlTrack) (CtrlTrackYellow) .load .def CtrlTrack } .cvx .def
(CtrlTrackYellow) {	% erase oval
	.pushdc .true .setopaque 0 .setcolor TrackYellow .popdc } .cvx .def
(CtrlYellowUp) { (CtrlTrack) TwoPop CtrlTrack } .cvx .def

(ShiftYellowDown) { (ShiftTrack) TwoPop % discard intermediate positions
	(y) .exch .def (x) .exch .def % save start position
	} .cvx .def
(ShiftYellowUp) {
	(:y) .exch .lv (:x) .exch .lv % save end position
	(YHWidth) :x x .sub .abs 2 .div .def	% half width 
	(YHHeight) :y y .sub .abs 2 .div .def	% half height
	} .cvx .def

(CtrlShiftYellowDown) { (CtrlShiftTrack) (CtrlShiftTrackYellow) .load .def CtrlShiftTrack } .cvx .def
(CtrlShiftTrackYellow) {	% erase oval
	.pushdc .setinvert TrackYellow .popdc } .cvx .def
(CtrlShiftYellowUp) { (CtrlShiftTrack) TwoPop CtrlTrack } .cvx .def

(BMx1) 0 .def
(BMx2) 0 .def
(BMy1) 0 .def
(BMy2) 0 .def
(BHWidth) 0 .def
(BHHeight) 0 .def

(BlueDown) { 
	(Track) (TrackBlue) .load .def Track } .cvx .def
(TrackBlue) {	% copy bitmap
	.translate 0 0 .moveto
	BMx1 BMy1 BMx2 BMy2 .copyscreen } .cvx .def
(BlueUp) { (Track) TwoPop Track } .cvx .def

(CtrlBlueDown) {
	(CtrlTrack) (CtrlTrackBlue) .load .def CtrlTrack } .cvx .def
(CtrlTrackBlue) {	% erase bimap sized rectangle
	.pushdc .true .setopaque 0 .setcolor TrackBlue .popdc } .cvx .def
(CtrlBlueUp) { (CtrlTrack) TwoPop CtrlTrack } .cvx .def

(ShiftBlueDown) { (ShiftTrack) TwoPop % discard intermediate positions
	.screencoords (BMy1) .exch .neg 808 .add .def (BMx1) .exch .def % save first corner of bitmap
	} .cvx .def
(ShiftBlueUp) {
	.screencoords (BMy2) .exch .neg 808 .add .def (BMx2) .exch .def % save second corner of bitmap
	(BHWidth) BMx1 BMx2 .sub .abs 2 .div .def	% half width 
	(BHHeight) BMy1 BMy2 .sub .abs 2 .div .def	% half height
	} .cvx .def

(CtrlShiftBlueDown) {
	(CtrlShiftTrack) (CtrlShiftTrackBlue) .load .def CtrlShiftTrack } .cvx .def
(CtrlShiftTrackBlue) {	% invert
	.pushdc .setinvert TrackBlue .popdc } .cvx .def
(CtrlShiftBlueUp) { (CtrlShiftTrack) TwoPop CtrlTrack } .cvx .def