Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Paint
#1
I've written a program which enables you to draw with one of 7 tools in all 16 colors. Right click to change your tool (displayed in the top right), left click on one of the colored boxes at the bottom to change your color, and hit "p" to print (will come out crappy unless you have a DOS enabled printer). The forum file hoster is giving me an error when I try to host it, so here's the code:
Code:
DECLARE SUB Interface (c%, tool$, tool%)
DECLARE SUB MouseDriver (AX%, bx%, x%, y%, lb%, rb%, EX%)
DECLARE SUB Printer ()

DIM SHARED mouse$
SCREEN 12
MouseDriver 1, bx%, x%, y%, lb%, rb%, 1

Box = 0
BoxX1 = 0
BoxX2 = 0
BoxY1 = 0
BoxY2 = 0
c% = 0
tool$ = "filled box"
tool% = 1
NumberOfTools = 8

Interface c%, tool$, tool%
'LINE (50, 50)-(639 - 51, 479 - 51), 15, BF

DO
  MouseDriver 3, bx%, x%, y%, lb%, rb%, 0


  COLOR 15
  'LOCATE 1, 1: PRINT lb%                'left button
  'LOCATE 2, 1: PRINT rb%                'right button
  'LOCATE 3, 1: PRINT x%                'x - coordinate
  'LOCATE 4, 1: PRINT y%                'y - coordinate
  'LOCATE 5, 1: PRINT box

  LOCATE 10, 10


  p$ = INKEY$
  IF p$ = "p" THEN Printer

  'if x and y coordinates are in a certain range
  'and lb = -1 then the button was clicked

  IF rb% = -1 THEN
    DO
     MouseDriver 3, bx%, x%, y%, lb%, rb%, 0
    LOOP UNTIL rb% = 0

    tool% = tool% + 1
    IF tool% > NumberOfTools THEN tool% = 1
    Interface c%, tool$, tool%
  END IF

  IF lb% = -1 AND y% >= 469 AND x% >= 50 AND x% <= (15 * 15 + 60) THEN
    IF x% <= 60 THEN oldc% = 0
    IF x% >= 65 AND x% <= 75 THEN oldc% = 1
    IF x% >= 80 AND x% <= 90 THEN oldc% = 2
    IF x% >= 95 AND x% <= 105 THEN oldc% = 3
    IF x% >= 110 AND x% <= 120 THEN oldc% = 4
    IF x% >= 125 AND x% <= 135 THEN oldc% = 5
    IF x% >= 140 AND x% <= 150 THEN oldc% = 6
    IF x% >= 155 AND x% <= 165 THEN oldc% = 7
    IF x% >= 170 AND x% <= 180 THEN oldc% = 8
    IF x% >= 185 AND x% <= 195 THEN oldc% = 9
    IF x% >= 200 AND x% <= 210 THEN oldc% = 10
    IF x% >= 215 AND x% <= 225 THEN oldc% = 11
    IF x% >= 230 AND x% <= 240 THEN oldc% = 12
    IF x% >= 245 AND x% <= 255 THEN oldc% = 13
    IF x% >= 260 AND x% <= 270 THEN oldc% = 14
    IF x% >= 275 AND x% <= 285 THEN oldc% = 15

    DO
     MouseDriver 3, bx%, x%, y%, lb%, rb%, 0
    LOOP UNTIL lb% = 0
  
    IF x% <= 60 THEN newc% = 0
    IF x% >= 65 AND x% <= 75 THEN newc% = 1
    IF x% >= 80 AND x% <= 90 THEN newc% = 2
    IF x% >= 95 AND x% <= 105 THEN newc% = 3
    IF x% >= 110 AND x% <= 120 THEN newc% = 4
    IF x% >= 125 AND x% <= 135 THEN newc% = 5
    IF x% >= 140 AND x% <= 150 THEN newc% = 6
    IF x% >= 155 AND x% <= 165 THEN newc% = 7
    IF x% >= 170 AND x% <= 180 THEN newc% = 8
    IF x% >= 185 AND x% <= 195 THEN newc% = 9
    IF x% >= 200 AND x% <= 210 THEN newc% = 10
    IF x% >= 215 AND x% <= 225 THEN newc% = 11
    IF x% >= 230 AND x% <= 240 THEN newc% = 12
    IF x% >= 245 AND x% <= 255 THEN newc% = 13
    IF x% >= 260 AND x% <= 270 THEN newc% = 14
    IF x% >= 275 AND x% <= 285 THEN newc% = 15

    IF oldc% = newc% THEN c% = newc%
    Interface c%, tool$, tool%
  END IF


  IF lb% = -1 AND (tool$ = "filled box" OR tool$ = "empty box" OR tool$ = "line") THEN
    BoxX1 = x%
    BoxY1 = y%
    PSET (BoxX1, BoxY1), c%
    DO
     MouseDriver 3, bx%, x%, y%, lb%, rb%, 0
    LOOP UNTIL lb% = 0
    BoxX2 = x%
    BoxY2 = y%
    IF tool$ = "filled box" THEN LINE (BoxX1, BoxY1)-(BoxX2, BoxY2), c%, BF
    IF tool$ = "empty box" THEN LINE (BoxX1, BoxY1)-(BoxX2, BoxY2), c%, B
    IF tool$ = "line" THEN LINE (BoxX1, BoxY1)-(BoxX2, BoxY2), c%
    Interface c%, tool$, tool%
  END IF

  IF lb% = -1 AND (tool$ = "circle" OR tool$ = "ellipse") THEN
    BoxX1 = x%
    BoxY1 = y%
    DO
     MouseDriver 3, bx%, x%, y%, lb%, rb%, 0
    LOOP UNTIL lb% = 0
    BoxX2 = x%
    BoxY2 = y%
    IF tool$ = "ellipse" THEN
      IF BoxX1 <> BoxX2 AND BoxY1 <> BoxY2 THEN
       CIRCLE (INT((BoxX1 + BoxX2) / 2), INT((BoxY1 + BoxY2) / 2)), INT(ABS(BoxX2 - BoxX1) / 2), c%, , , ABS(BoxY2 - BoxY1) / ABS(BoxX2 - BoxX1)
      END IF
    END IF
    IF tool$ = "circle" THEN CIRCLE (INT((BoxX1 + BoxX2) / 2), INT((BoxY1 + BoxY2) / 2)), INT(ABS(BoxX2 - BoxX1) / 2), c%
    Interface c%, tool$, tool%
  END IF

  IF lb% = -1 AND (tool$ = "pencil" OR tool$ = "paintbrush" OR tool$ = "big paintbrush") THEN
    MouseDriver 3, bx%, x%, y%, lb%, rb%, 0
    oldx% = x%
    oldy% = y%
    DO
     MouseDriver 3, bx%, x%, y%, lb%, rb%, 0
     IF tool$ = "pencil" THEN
       LINE (x%, y%)-(oldx%, oldy%), c%
       oldx% = x%
       oldy% = y%
     END IF

     IF tool$ = "paintbrush" THEN LINE (x% - 5, y% - 5)-(x% + 5, y% + 5), c%, BF
     IF tool$ = "big paintbrush" THEN LINE (x% - 10, y% - 10)-(x% + 10, y% + 10), c%, BF
    LOOP UNTIL lb% = 0
    Interface c%, tool$, tool%
  END IF


LOOP UNTIL p$ = CHR$(27)


DATA 55,89,E5,8B,5E,0C,8B,07,50,8B,5E,0A,8B,07,50,8B
DATA 5E,08,8B,0F,8B,5E,06,8B,17,5B,58,1E,07,CD,33,53
DATA 8B,5E,0C,89,07,58,8B,5E,0A,89,07,8B,5E,08,89,0F
DATA 8B,5E,06,89,17,5D,CA,08,00

DATA 205, 5, 203  : ' int 5  retf  'Machine-language code
                                       'for printing screen.

END

SUB Interface (c%, tool$, tool%)
  LINE (49, 49)-(639 - 50, 479 - 50), 15, B

  LINE (0, 0)-(48, 639), 0, BF
  LINE (639 - 48, 0)-(639, 479), 0, BF
  LINE (0, 0)-(639, 48), 0, BF
  LINE (0, 479 - 49)-(639, 479), 0, BF


  LOCATE 1, 1
  COLOR 15
  IF tool% = 1 THEN tool$ = "filled box"
  IF tool% = 2 THEN tool$ = "empty box"
  IF tool% = 3 THEN tool$ = "line"
  IF tool% = 4 THEN tool$ = "circle"
  IF tool% = 5 THEN tool$ = "ellipse"
  IF tool% = 6 THEN tool$ = "pencil"
  IF tool% = 7 THEN tool$ = "paintbrush"
  IF tool% = 8 THEN tool$ = "big paintbrush"
  PRINT tool$
  LOCATE 2, 1
  COLOR c%
  PRINT c%

  

  FOR BoxX = 0 TO 15
    LINE (BoxX * 15 + 50, 468)-(BoxX * 15 + 50 + 10, 478), BoxX, BF
    IF c% = BoxX THEN
      LINE (BoxX * 15 + 50 - 1, 467)-(BoxX * 15 + 50 + 10 + 1, 479), 15, B
    END IF
  NEXT BoxX

END SUB

SUB MouseDriver (AX%, bx%, x%, y%, lb%, rb%, EX%)
IF EX% = 1 THEN
  mouse$ = SPACE$(57)
  FOR i% = 1 TO 57
    READ a$
    h$ = CHR$(VAL("&H" + a$))
    MID$(mouse$, i%, 1) = h$
  NEXT i%
  CLS
END IF

DEF SEG = VARSEG(mouse$)
CALL ABSOLUTE(AX%, bx%, x%, y%, SADD(mouse$))
lb% = ((bx% AND 1) <> 0)
rb% = ((bx% AND 2) <> 0)

LOCATE 3, 1
PRINT "x:";
PRINT USING "###"; x%
LOCATE 4, 1
PRINT "y:";
PRINT USING "###"; y%


END SUB

SUB Printer
DIM a%(2)
DEF SEG = VARSEG(a%(0))
d% = 205
POKE VARPTR(a%(0)) + 0, d%
d% = 5
POKE VARPTR(a%(0)) + 1, d%
d% = 203
POKE VARPTR(a%(0)) + 2, d%
CALL ABSOLUTE(VARPTR(a%(0)))
DEF SEG

printing$ = "Printing, this may take a minute"
LOCATE 3, 1
PRINT printing$
SLEEP 2
LOCATE 3, 1
PRINT SPACE$(LEN(printing$))

END SUB
'm boycotting signatures.
Reply
#2
dark ninja:
I copied your program to my QuickBASIC 4.5, running under Windows XP Home Edition. When I tried to run it, it gave me an error message, "Subprogram not defined", at line 13:
CALL ABSOLUTE(AX%, bx%, x%, y%, SADD(mouse$))

Anything I can do to fix this?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#3
Load QB with the /L parameter
Reply
#4
Quote:Load QB with the /L parameter
Yep, that did it! Thanks a lot.

Does the /L parameter or switch mean "load a Library"?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#5
Yup, and by default it loads QB.QLB, wich holds the ABSOLUTE function
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)