Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The simplest paint routine.
#4
Is it fair to post something you wrote previously?

This one doesn't work like QB's (which stops only at the border color you give it) - it's more like the flood fill tool an image editor might have, which stops at any other color besides the one it's filling over.

Code:
DECLARE SUB fill (x1%, y1%, fc%)
DEFINT A-Z

TYPE p2d
  x AS INTEGER
  y AS INTEGER
END TYPE

RANDOMIZE TIMER
SCREEN 13

' Draw some random stuff:
FOR a = 1 TO 13
  x1 = INT(RND * 320): y1 = INT(RND * 200)
  x2 = INT(RND * 320): y2 = INT(RND * 200)
  COLOR INT(RND * 7) + 9
  SELECT CASE INT(RND * 4)
    CASE 1: CIRCLE (x1, y1), INT(RND * 200) + 1
    CASE 2: LINE (x1, y1)-(x2, y2)
    CASE 3: LINE (x1, y1)-(x2, y2), , B
  END SELECT
NEXT a

' Paint from a random point:
fill INT(RND * 320), INT(RND * 200), 1

END

SUB fill (x1, y1, fc)
IF x1 < 0 OR x1 > 319 OR y1 < 0 OR y1 > 199 THEN EXIT SUB
c = POINT(x1, y1)
IF c = fc THEN EXIT SUB
h = 0
PSET (x1, y1), fc
DIM max AS LONG
max = FRE(-1) \ 4
IF max > 16384 THEN max = 16384
DIM q(1 TO max) AS p2d
s = 1: sm1 = 0: e = 1: q(e).x = x1: q(e).y = y1
DO WHILE e >= s
  x = q(s).x: y = q(s).y: sm1 = s: s = s + 1
  xm1 = x - 1: ym1 = y - 1: xp1 = x + 1: yp1 = y + 1
  IF x > 0 THEN
    IF POINT(xm1, y) = c THEN
      PSET (xm1, y), fc
      e = e + 1
      IF e > max THEN
        FOR a = s TO max: q(a - sm1) = q(a): NEXT a
        e = e - sm1: s = 1: sm1 = 0
      END IF
      q(e).x = xm1: q(e).y = y
    END IF
  END IF
  IF x < 319 THEN
    IF POINT(xp1, y) = c THEN
      PSET (xp1, y), fc
      e = e + 1
      IF e > max THEN
        FOR a = s TO max: q(a - sm1) = q(a): NEXT a
        e = e - sm1: s = 1: sm1 = 0
      END IF
      q(e).x = xp1: q(e).y = y
    END IF
  END IF
  IF y > 0 THEN
    IF POINT(x, ym1) = c THEN
      PSET (x, ym1), fc
      e = e + 1
      IF e > max THEN
        FOR a = s TO max: q(a - sm1) = q(a): NEXT a
        e = e - sm1: s = 1: sm1 = 0 ': o = o + 1
      END IF
      q(e).x = x: q(e).y = ym1
      'nh = e - sm1: IF nh > h THEN h = nh
    END IF
  END IF
  IF y < 199 THEN
    IF POINT(x, yp1) = c THEN
      PSET (x, yp1), fc
      e = e + 1
      IF e > max THEN
        FOR a = s TO max: q(a - sm1) = q(a): NEXT a
        e = e - sm1: s = 1: sm1 = 0 ': o = o + 1
      END IF
      q(e).x = x: q(e).y = yp1
      'nh = e - sm1: IF nh > h THEN h = nh
    END IF
  END IF
LOOP
END SUB
Reply


Messages In This Thread
The simplest paint routine. - by Rokkuman - 07-12-2003, 03:56 AM
The simplest paint routine. - by whitetiger0990 - 07-12-2003, 04:08 AM
The simplest paint routine. - by toonski84 - 07-12-2003, 04:31 AM
The simplest paint routine. - by Agamemnus - 07-12-2003, 07:10 AM
The simplest paint routine. - by Plasma - 07-12-2003, 07:53 AM
The simplest paint routine. - by Antoni Gual - 07-12-2003, 02:25 PM
The simplest paint routine. - by Plasma - 07-12-2003, 08:04 PM
The simplest paint routine. - by Agamemnus - 07-12-2003, 08:14 PM
The simplest paint routine. - by Antoni Gual - 07-14-2003, 01:32 PM
The simplest paint routine. - by Antoni Gual - 07-14-2003, 02:17 PM
The simplest paint routine. - by Plasma - 07-15-2003, 03:04 AM
The simplest paint routine. - by Antoni Gual - 07-15-2003, 06:13 PM
The simplest paint routine. - by Plasma - 07-15-2003, 07:11 PM
The simplest paint routine. - by Agamemnus - 07-15-2003, 09:39 PM
The simplest paint routine. - by Nexinarus - 07-16-2003, 05:00 AM
My code - by Meg - 07-16-2003, 07:22 AM
. - by Meg - 07-18-2003, 08:13 AM
Re: My code - by Mango - 07-18-2003, 08:47 AM
oops - by Meg - 07-18-2003, 10:01 AM
The simplest paint routine. - by Sterling Christensen - 07-12-2003, 06:54 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)