Qbasicnews.com

Full Version: Drawing AI Challenge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Bump...
Sorry to be a party pooper, but none of these so far can be said to be AI.

I would say more of a random algorithm generated image.

(apart from maybe Z!re's original)
I'm working on creating something like painter.exe (based on your discription of it), but I cant seem to get it to run nearly as fast nor to create anyting nearly as interesting. What I have it doing is having a given number of groups (all things I say are a given number are defined by const in the code) each consisting of a given set of different colors creating a picture of a given size in a given screen (currently 13). What I have it do is generate a different random spot for each pixel, a random color within the range, and a random rate of change for the color. I have it set to execute a set of code over and over until the whole picture is made. All pixels try to move toward the center of their group (the average of all the x's and the average of all the y's of the pixels in that group). When they cannot go to the next pixel they want to, or if they are in the center of their group, they plot and 'die' otherwise, they move. When a pixel 'dies', a sub called RegenPxls gives them a new random coordanate and color that nothing occupies and plots it their. However, it takes an imensely long time to regernerate them even once. Here is my code:
Code:
DECLARE SUB PlotPxl (Pxl!)
DECLARE SUB RegenPxl ()
DECLARE FUNCTION Center! (Group!)
DECLARE SUB CreateGroups ()
OPTION BASE 1
'Declare constants for easy edit-ability.  The names are as follows:
'SNum        - SCREEN number
'SWidth      - SCREEN Width
'SHeight     - SCREEN Height
'SLColor     - The lower limit of the colors
'SUColor     - The upper limit of the colors
'Groups      - The number of ranges of pixels you want
'SBorder     - The width of the pixel border
'LPalette    - The lower limit of the palettes (set to 0 if not using palettes)
'UPalette    - The upper limit of the palettes (set to 0 if not using palettes)
'NotUsed     - The middle number of the group of colors not used
'CustGroups  - -1 only if you will define your own color groups
'SpaceGroups - The number of blank pixels between each group
'Pxls        - The number of pixels you want to have per group.
CONST SNum = 13
CONST SWidth = 320, SHeight = 200
CONST SLColor = 0, SUColor = 255
CONST Groups = 8
CONST SBorder = 10
CONST LPalette = 0, UPalette = 0
CONST NotUsed = 0
CONST CustGroups = -1, SpaceGroups = 0
CONST Pxls = 10
COMMON SHARED Picture()
COMMON SHARED ColorGroups()
CG = Groups
CS = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
DIM SHARED ColorGroups(CG, CS)
DIM SHARED PxlEngine(Pxls * Groups, 6)
SW = SWidth
SH = SHeight
DIM SHARED Picture(SW, SH)
SCREEN SNum
KEY 15, CHR$(0) + CHR$(49)
KEY 16, CHR$(0) + CHR$(1)
ON KEY(15) GOSUB beginner
ON KEY(16) GOSUB leaver
KEY(15) ON
KEY(16) ON
ERASE PxlEngine, Picture, ColorGroups
REDIM SHARED PxlEngine(Pxls * Groups, 6)
REDIM SHARED Picture(SW, SH)
REDIM SHARED ColorGroups(CG, CS)
IF CustGroups THEN
'================Edit this if you are making custom groups==============
        FOR y = 1 TO 8
                FOR x = 1 TO 32
                        READ colors
                        ColorGroups(y, x) = colors
                NEXT x
        NEXT y
        DATA 1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
        DATA 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
        DATA 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95
        DATA 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127
        DATA 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159
        DATA 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191
        DATA 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223
        DATA 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
'========================================================================
ELSE
        CALL CreateGroups
END IF
begin:
RESET
KEY(15) ON
KEY(16) ON
RANDOMIZE TIMER
ERASE PxlEngine, Picture
REDIM SHARED PxlEngine(Pxls * Groups, 6)
REDIM SHARED Picture(SW, SH)
FOR i = 1 TO Pxls * Groups
        DO
                works = -1
                PxlEngine(i, 1) = INT((SWidth - SBorder - SBorder + 1) * RND + SBorder)'x
                PxlEngine(i, 2) = INT((SHeight - SBorder - SBorder + 1) * RND + SBorder)'y
                FOR a = 1 TO i - 1
                        IF PxlEngine(a, 1) = PxlEngine(i, 1) AND PxlEngine(a, 2) = PxlEngine(i, 2) THEN
                                works = 0
                                EXIT FOR
                        END IF
                NEXT a
        LOOP UNTIL works
        PxlEngine(i, 3) = INT((i - 1) / Pxls + 1) 'group
        PxlEngine(i, 4) = INT(INT((SUColor - SLColor + 1) / Groups - SpaceGroups) * RND + 1) 'color
        PxlEngine(i, 5) = INT((3 - 1 + 1) * RND + 1) 'rate of change for color
        PxlEngine(i, 6) = -1 'alive (-1) or dead (0)
NEXT i
CLS
FOR i = 1 TO Pxls * Groups
        LINE (PxlEngine(i, 1), PxlEngine(i, 2))-(PxlEngine(i, 1), PxlEngine(i, 2)), ColorGroups(PxlEngine(i, 3), PxlEngine(i, 4))
        'Picture(PxlEngine(i, 1) + 1, PxlEngine(i, 2) + 1) = ColorGroups(PxlEngine(i, 3), PxlEngine(i, 4))
NEXT i
DO
        done = -1
        FOR x = SBorder TO SWidth - SBorder
                FOR y = SBorder TO SHeight - SBorder
                        IF Picture(x, y) = 0 THEN
                                done = 0
                                EXIT FOR
                        END IF
                NEXT y
                IF working = 0 THEN EXIT FOR
        NEXT x
        FOR i = 1 TO Pxls * Groups
                CALL PlotPxl(i)
        NEXT i
        CALL RegenPxl
LOOP UNTIL done
ik$ = ""
WHILE ik$ <> "n" AND ik$ <> CHR$(0) + CHR$(1)
        ik$ = LCASE$(INKEY$)
WEND
END
beginner: RETURN begin
leaver: END

FUNCTION Center (Group)
        total = 0
        SumX = 0
        SumY = 0
        FOR x = SBorder TO SWidth - SBorder
                FOR y = SBorder TO SHeight - SBorder
                        FOR c = 1 TO INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                                IF Picture(x, y) = ColorGroups(Group, c) THEN
                                        SumX = SumX + x
                                        SumY = SumY + y
                                        total = total + 1
                                END IF
                        NEXT c
                NEXT y
                IF working = 0 THEN EXIT FOR
        NEXT x
        IF total = 0 THEN
                FOR i = 1 TO Pxls * Groups
                        IF PxlEngine(i, 3) = Group THEN
                                SumX = SumX + PxlEngine(i, 1)
                                SumY = SumY + PxlEngine(i, 2)
                                total = total + 1
                        END IF
                NEXT i
        END IF
        Center = INT(SumX / (total - (total = 0))) + INT(SumY / (total - (total = 0))) / 1000
END FUNCTION

SUB CreateGroups
        FOR i = 1 TO Groups
                counter = 1
                FOR c = (i - 1) * INT((SUColor - SLColor + 1) / Groups) TO i * INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                        ColorGroups(i, counter) = c
                        counter = counter + 1
                NEXT c
        NEXT i
END SUB

SUB PlotPxl (Pxl)
        GCenter = Center(PxlEngine(Pxl, 3))
        GCenterX = INT(GCenter)
        GCenterY = 1000 * (GCenter - INT(GCenter))
        IF GCenterX = PxlEngine(Pxl, 1) AND GCenterY = PxlEngine(Pxl, 2) THEN
                Picture(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)) = ColorGroups(PxlEngine(Pxl, 3), PxlEngine(Pxl, 4))
                PxlEngine(Pxl, 6) = 0
                EXIT SUB
        END IF
        working = -1
        TryX = PxlEngine(Pxl, 1) - (PxlEngine(Pxl, 1) - GCenterX) / ABS(PxlEngine(Pxl, 1) - GCenterX - (PxlEngine(Pxl, 1) - GCenterX) = 0)
        TryY = PxlEngine(Pxl, 2) - (PxlEngine(Pxl, 2) - GCenterY) / ABS(PxlEngine(Pxl, 2) - GCenterY - (PxlEngine(Pxl, 2) - GCenterY) = 0)
        works = -1
        FOR i = 1 TO Pxls * Groups
                IF PxlEngine(i, 1) = TryX AND PxlEngine(i, 2) = TryY THEN
                        works = 0
                        EXIT FOR
                END IF
        NEXT i
        IF NOT works THEN
                Picture(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)) = ColorGroups(PxlEngine(Pxl, 3), PxlEngine(Pxl, 4))
                PxlEngine(Pxl, 6) = 0
                EXIT SUB
        END IF
        LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), 0
        PxlEngine(Pxl, 1) = TryX
        PxlEngine(Pxl, 2) = TryY
        PxlEngine(Pxl, 4) = PxlEngine(Pxl, 4) + PxlEngine(Pxl, 5)
        IF PxlEngine(Pxl, 4) < 1 THEN
                PxlEngine(Pxl, 4) = 1
                PxlEngine(Pxl, 5) = INT((3 - 1 + 1) * RND + 1)
        ELSEIF PxlEngine(Pxl, 4) > INT((SUColor - SLColor + 1) / Groups - SpaceGroups) THEN
                PxlEngine(Pxl, 4) = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                PxlEngine(Pxl, 5) = -INT((3 - 1 + 1) * RND + 1)
        END IF
        LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), ColorGroups(PxlEngine(Pxl, 3), PxlEngine(Pxl, 4))
END SUB

SUB RegenPxl
        FOR i = 1 TO Pxls * Groups
                IF NOT PxlEngine(i, 6) THEN
                        DO
                                works = -1
                                PxlEngine(i, 1) = INT((SWidth - SBorder - SBorder + 1) * RND + SBorder)
                                PxlEngine(i, 2) = INT((SHeight - SBorder - SBorder + 1) * RND + SBorder)
                                FOR a = 1 TO Pxls * Groups
                                        IF (PxlEngine(a, 1) = PxlEngine(i, 1) AND PxlEngine(a, 2) = PxlEngine(i, 2) AND a <> i) OR Picture(PxlEngine(i, 1), PxlEngine(i, 2)) <> 0 THEN
                                                works = 0
                                                EXIT FOR
                                        END IF
                                NEXT a
                        LOOP UNTIL works
                        PxlEngine(i, 4) = INT(INT((SUColor - SLColor + 1) / Groups - SpaceGroups) * RND + 1) 'color
                        PxlEngine(i, 5) = INT((3 - 1 + 1) * RND + 1) 'rate of change for color
                        PxlEngine(i, 6) = -1 'alive (-1) or dead (0)
                        LINE (PxlEngine(i, 1), PxlEngine(i, 2))-(PxlEngine(i, 1), PxlEngine(i, 2)), ColorGroups(PxlEngine(i, 3), PxlEngine(i, 4))
                END IF
        NEXT i
END SUB

Sorry for the (almost) complete lack of comments (a bad habbit of mine). Any advice/suggestions on my code, in addition to any additonal discription of the source code of painer.exe would be greatly appreciated.

Edit: I fixed a few errors in my code, so now it finishes in a resonable amount of time, but it still is nothing like painer.exe. I am not sure how to make it less like random movement and more like an AI (I'm thinking maybe get rid of the part of code where the pixels 'die' or something like that, or make where they are regenerated less random).
I dont have time to look at your source, sorry..


Painter use a pack algorithm, where each dot tries to go for one of it's own approximate kind, their kind/groups are based on their colour.

If a dot is trapped on all sides it jumps out to the border of the picture, where it goes around until it finds a gap.

If a dot is blocked in it's path, either by another dot, or by the drawing itself, it leaves behind a single pixel of it's own color there, then tries to find an alternative route.


It all sound far more advanced than it really was.. Only about 150 lines of code or so.. too bad I lost it, would've been fun to mess with..
Code:
Screen 12,8,2,0
Size=20 'Size of the "flames"
S=1
ScreenSet S,1-S
For X=0 to 639
Pset (X,479),Int(Rnd*200)+1
Next
    Do
ScreenSet S,1-S
For Y=479 to 0 step -1
    For X=1 to 638
    If Int(Rnd*Size)+1<>1 Then Pset(X,Y-1),Point(X+Int(Rnd*3)-1,Y)
    Next
Next
ScreenCopy S,1-S
S=1-S
    Loop while inkey$=""
Sleep

Slow but... interesting.
@JasonSG: I couldnt run your code, it fails on this line:
DIM SHARED Picture(SW, SH)
With a subscript out of range..
What are you using to run it?


@Pyrodap, nice, but doesent follow the rules:
* Upload the entry to FileAnchor in a zip or rar archive, containing compiled exe and source.
* Drawing must stop by itself, and will only be judged then.

Still cool though =)
I'm using QB 7.1 PDS with the /Ah command line option.

Anonymous

aff z!re, post souce b4 u demand it from others =(
I modifyied my program to make it more like painter. I still have a few problems. The main ones are that not all the pixels move around the outside to try to find an alternate route correctly; occassionaly getting "stuck", and that there are almost always black spots that leave me with unfinished paintings. I also found two minor ones: if you press and hold down the "n" key, it gives me an out of stack space error (in z!ire's painer, it dosen't) (possibly caused by the way I am trapping the keys - ON KEY(n) GOSUB), the fact that sometimes, it runs very slowly (this is fixed by restarting qbasic). Here is my updated code:
Code:
DECLARE FUNCTION Math.Rand! (lowerbound!, upperbound!)
DECLARE FUNCTION RAND! ()
DECLARE FUNCTION MIN! (num1!, num2!)
DECLARE SUB PlotPxl (Pxl!)
DECLARE SUB RegenPxl ()
DECLARE FUNCTION Center! (Group!)
DECLARE SUB CreateGroups ()
OPTION BASE 1
'Declare constants for easy edit-ability.  The names are as follows:
'SNum        - SCREEN number
'SWidth      - SCREEN Width
'SHeight     - SCREEN Height
'SLColor     - The lower limit of the colors
'SUColor     - The upper limit of the colors
'Groups      - The number of ranges of pixels you want
'SBorder     - The width of the pixel border
'LPalette    - The lower limit of the palettes (set to 0 if not using palettes)
'UPalette    - The upper limit of the palettes (set to 0 if not using palettes)
'NotUsed     - The middle number of the group of colors not used
'CustGroups  - -1 only if you will define your own color groups
'SpaceGroups - The number of blank pixels between each group
'Pxls        - The number of pixels you want to have per group.
CONST SNum = 13
CONST SWidth = 320, SHeight = 200
CONST SLColor = 0, SUColor = 55
CONST Groups = 7
CONST SBorder = 10
CONST LPalette = 0, UPalette = 0
CONST NotUsed = 0
CONST CustGroups = -1, SpaceGroups = 0
CONST Pxls = 10
COMMON SHARED ColorGroups()
CG = Groups
CS = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
DIM SHARED ColorGroups(CG, CS)
DIM SHARED PxlEngine(Pxls * Groups, 6)
SW = SWidth
SH = SHeight
SCREEN SNum
KEY 15, CHR$(0) + CHR$(49)
KEY 16, CHR$(0) + CHR$(1)
ON KEY(15) GOSUB beginner
ON KEY(16) GOSUB leaver
KEY(15) ON
KEY(16) ON
ERASE PxlEngine, ColorGroups
REDIM SHARED PxlEngine(Pxls * Groups, 6)
REDIM SHARED ColorGroups(CG, CS)
IF CustGroups THEN
'================Edit this if you are making custom groups==============
        FOR y = 1 TO Groups
                FOR x = 1 TO (1 + SUColor - SLColor) / Groups
                        READ colors
                        ColorGroups(y, x) = colors
                NEXT x
        NEXT y
        'DATA 4,128,6,7,8,100,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,162,161,160,64,97,65,99
        'DATA 96,98,129,130,131,132,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
        'DATA 192,2,193,194,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95
        'DATA 104,1,32,33,9,3,124,125,126,127,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,101,102,103
        'DATA 5,34,35,36,37,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159
        'DATA 31,30,29,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191
        'DATA 66,66,67,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223
        'DATA 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255

        'DATA 1,181,205,106,130,31,55,9
        'DATA 2,182,206,107,131,32,56,10
        'DATA 3,183,207,108,132,33,57,11
        'DATA 4,184,208,109,133,34,58,12
        'DATA 5,185,209,110,134,35,59,13
        'DATA 6,186,210,111,135,36,60,14
        'DATA 7,187,211,112,136,37,61,15
        'DATA 8,188,212,113,137,38,62,16

        DATA 1,1,1,1,1,1,1,1
        DATA 2,2,2,2,2,2,2,2
        DATA 3,3,3,3,3,3,3,3
        DATA 4,4,4,4,4,4,4,4
        DATA 5,5,5,5,5,5,5,5
        DATA 6,6,6,6,6,6,6,6
        DATA 7,7,7,7,7,7,7,7
        DATA 8,8,8,8,8,8,8,8


'========================================================================
ELSE
        CALL CreateGroups
END IF
RESET
ERASE PxlEngine
REDIM SHARED PxlEngine(Pxls * Groups, 6)
Quad(1) = INT((SWidth - 2 * SBorder) / INT(SQR(Groups) + .5) + .5)
Quad(2) = INT((SHeight - 2 * SBorder) / INT(Groups / INT(SQR(Groups) + .5) + .5) + .5)
DIM GQuad(Groups, 2)
FOR i = 1 TO Groups
        DO
                working = -1
                GQuad(i, 1) = Math.Rand(1, INT(SQR(Groups) + .5))
                GQuad(i, 2) = Math.Rand(1, INT(Groups / INT(SQR(Groups) + .5) + .9))
                FOR N = 1 TO i - 1
                        IF GQuad(N, 1) = GQuad(i, 1) AND GQuad(i, 2) = GQuad(N, 2) THEN
                                working = 0
                                EXIT FOR
                        END IF
                NEXT N
        LOOP UNTIL working
NEXT i
FOR i = 1 TO Pxls * Groups
        PxlEngine(i, 3) = INT((i - 1) / Pxls + 1) 'group
        PxlEngine(i, 4) = Math.Rand(SLColor + 1, INT(SUColor / Groups)) 'color
        PxlEngine(i, 5) = Math.Rand(1, 3)'rate of change for color
        PxlEngine(i, 6) = -1 'alive (-1) or dead (0)
        DO
                works = -1
                PxlEngine(i, 1) = Math.Rand(GQuad(PxlEngine(i, 3), 1) * Quad(1) - Quad(1) + SBorder, GQuad(PxlEngine(i, 3), 1) * Quad(1) + SBorder)'x
                PxlEngine(i, 2) = Math.Rand(GQuad(PxlEngine(i, 3), 2) * Quad(2) - Quad(2) + SBorder, GQuad(PxlEngine(i, 3), 2) * Quad(2) + SBorder)'y
                'IF -INT(RAND + .5) THEN
                        'coord = INT((SWidth - SBorder - SBorder + 1) * RAND + SBorder)
                        'PxlEngine(i, 1) = coord
                        'PxlEngine(i, 2) = SBorder + INT(RAND + .5) * (SHeight - 2 * SBorder + 1)
                'ELSE
                        'coord = INT((SHeight - SBorder - SBorder + 1) * RAND + SBorder)
                        'PxlEngine(i, 2) = coord
                        'PxlEngine(i, 1) = SBorder + INT(RAND + .5) * (SWidth - 2 * SBorder + 1)
                'END IF
                FOR a = 1 TO i - 1
                        IF PxlEngine(a, 1) = PxlEngine(i, 1) AND PxlEngine(a, 2) = PxlEngine(i, 2) THEN
                                works = 0
                                EXIT FOR
                        END IF
                NEXT a
        LOOP UNTIL works
NEXT i
begin:
KEY(15) ON
KEY(16) ON
CLS
FOR i = 1 TO Pxls * Groups
        LINE (PxlEngine(i, 1), PxlEngine(i, 2))-(PxlEngine(i, 1), PxlEngine(i, 2)), ColorGroups(PxlEngine(i, 3), PxlEngine(i, 4))
NEXT i
DO
        RANDOMIZE TIMER * RAND
        done = -1
        FOR x = SBorder TO SWidth - SBorder
                FOR y = SBorder TO SHeight - SBorder
                        IF POINT(x, y) = 0 THEN
                                done = 0
                                EXIT FOR
                        END IF
                NEXT y
                IF done = 0 THEN EXIT FOR
        NEXT x
        FOR i = 1 TO Pxls * Groups
                CALL PlotPxl(i)
                'PxlEngine(i, 1) = PxlEngine(i - 1, 1) AND PxlEngine(i, 2) = PxlEngine(i - 1, 2)
        NEXT i
        CALL RegenPxl
        'PLAY "L64 N0"
LOOP UNTIL done
ik$ = ""
WHILE ik$ <> "n" AND ik$ <> CHR$(0) + CHR$(1)
        ik$ = LCASE$(INKEY$)
WEND
END
beginner: RETURN begin
leaver: END

FUNCTION Center (Group)
        total = 0
        SumX = 0
        SumY = 0
        FOR i = 1 TO Pxls * Groups
                IF PxlEngine(i, 3) = Group THEN
                        SumX = SumX + PxlEngine(i, 1)
                        SumY = SumY + PxlEngine(i, 2)
                        total = total + 1
                ELSEIF total <> 0 THEN
                        EXIT FOR
                END IF
        NEXT i
        Center = INT(SumX / (total - (total = 0))) + INT(SumY / (total - (total = 0))) / 1000
END FUNCTION

SUB CreateGroups
        FOR i = 1 TO Groups
                counter = 1
                FOR c = (i - 1) * INT((SUColor - SLColor + 1) / Groups) TO i * INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                        ColorGroups(i, counter) = c
                        counter = counter + 1
                NEXT c
        NEXT i
END SUB

FUNCTION Math.Rand (lowerbound, upperbound)
        'RANDOMIZE TIMER
        Math.Rand = INT((upperbound - lowerbound + 1) * RND + lowerbound)
END FUNCTION

FUNCTION MIN (num1, num2)
        IF num1 < num2 THEN MIN = num1 ELSE MIN = num2
END FUNCTION

SUB PlotPxl (Pxl)
        GCenter = Center(PxlEngine(Pxl, 3))
        GCenterX = INT(GCenter)
        GCenterY = INT(1000 * (GCenter - INT(GCenter)))
        IF GCenterX = PxlEngine(Pxl, 1) AND GCenterY = PxlEngine(Pxl, 2) AND PxlEngine(Pxl, 1) > SBorder AND PxlEngine(Pxl, 1) < SWidth - SBorder AND PxlEngine(Pxl, 2) > SBorder AND PxlEngine(Pxl, 2) < SHeight - SBorder THEN
                s = INT(RAND + .5) * 2 - 1
                e = -s
                st = (e - s) / ABS(e - s)
                FOR x = s TO e STEP st
                        s2 = INT(RAND + .5) * 2 - 1
                        e2 = -s2
                        st2 = (e2 - s2) / ABS(e2 - s2)
                        FOR y = s2 TO e2 STEP st2
                                IF POINT(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)) = 0 THEN
                                        PxlEngine(Pxl, 1) = PxlEngine(Pxl, 1) + x
                                        PxlEngine(Pxl, 2) = PxlEngine(Pxl, 2) + y
                                        PxlEngine(Pxl, 4) = PxlEngine(Pxl, 4) + PxlEngine(Pxl, 5)
                                        IF PxlEngine(Pxl, 4) < 1 THEN
                                                PxlEngine(Pxl, 4) = 1
                                                PxlEngine(Pxl, 5) = INT((3 - 1 + 1) * RAND + 1)
                                        ELSEIF PxlEngine(Pxl, 4) > INT((SUColor - SLColor + 1) / Groups - SpaceGroups) THEN
                                                PxlEngine(Pxl, 4) = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                                                PxlEngine(Pxl, 5) = -INT((3 - 1 + 1) * RAND + 1)
                                        END IF
                                        LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), ColorGroups(PxlEngine(Pxl, 3), PxlEngine(Pxl, 4))
                                        EXIT SUB
                                END IF
                        NEXT y
                NEXT x
                PxlEngine(Pxl, 6) = 0
                EXIT SUB
        END IF
        works = -1
        TryX = PxlEngine(Pxl, 1) - (PxlEngine(Pxl, 1) - GCenterX) / ABS(PxlEngine(Pxl, 1) - GCenterX - ((PxlEngine(Pxl, 1) - GCenterX) = 0))
        TryY = PxlEngine(Pxl, 2) - (PxlEngine(Pxl, 2) - GCenterY) / ABS(PxlEngine(Pxl, 2) - GCenterY - ((PxlEngine(Pxl, 2) - GCenterY) = 0))
        IF POINT(TryX, TryY) <> 0 THEN
                TryX = PxlEngine(Pxl, 1)
                TryY = PxlEngine(Pxl, 2)
                IF TryX = SWidth - SBorder OR TryX = SBorder OR TryY = SBorder OR TryY = SHeight - SBorder THEN
                        FOR TX = -1 TO 1
                                IF TX = 0 THEN TX = 1
                                FOR TY = -1 TO 1
                                        IF TY = 0 THEN TY = 1
                                        works = -1
                                                IF TryX + TX < SWidth - SBorder AND TryX + TX > SBorder AND TryY + TY > SBorder AND TryY + TY < SHeight - SBorder THEN
                                                IF POINT(TryX + TX, TryY + TY) <> 0 THEN
                                                        works = 0
                                                END IF
                                                IF works THEN
                                                        TryX = TryX + TX
                                                        TryY = TryY + TY
                                                        EXIT FOR
                                                END IF
                                        ELSE
                                                works = 0
                                        END IF
                                NEXT TY
                                IF works THEN EXIT FOR
                        NEXT TX
                        IF NOT works THEN
                                IF TryX < SWidth / 2 THEN TrY = 1 ELSE TrY = -1
                                IF TryY < SHeight / 2 THEN TrX = -1 ELSE TrX = 1
                                FOR TX = 0 TO TrX STEP TrX
                                        FOR TY = 0 TO TrY STEP TrY
                                                IF ABS(TX) <> ABS(TY) THEN
                                                        IF (POINT(TryX + TX, TryY + TY) = 0 OR POINT(TryX + TX, TryY + TY) = -1) AND TryX + TX < SWidth - SBorder + 1 AND TryX + TX > SBorder - 1 AND TryY + TY > SBorder - 1 AND TryY + TY < SHeight -  _
SBorder + 1 THEN
                                                                'IF TryX + TX > 9 AND TryY + TY > 9 AND POINT(TryX + TX, TryY + TY) = 0 AND (TX <> 0 OR TY <> 0) THEN
                                                                LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), 0
                                                                PxlEngine(Pxl, 1) = PxlEngine(Pxl, 1) + TX
                                                                PxlEngine(Pxl, 2) = PxlEngine(Pxl, 2) + TY
                                                                PxlEngine(Pxl, 4) = PxlEngine(Pxl, 4) + PxlEngine(Pxl, 5)
                                                                IF PxlEngine(Pxl, 4) < 1 THEN
                                                                        PxlEngine(Pxl, 4) = 1
                                                                        PxlEngine(Pxl, 5) = INT((3 - 1 + 1) * RAND + 1)
                                                                ELSEIF PxlEngine(Pxl, 4) > INT((SUColor - SLColor + 1) / Groups - SpaceGroups) THEN
                                                                        PxlEngine(Pxl, 4) = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                                                                        PxlEngine(Pxl, 5) = -INT((3 - 1 + 1) * RAND + 1)
                                                                END IF
                                                                LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), ColorGroups(PxlEngine(Pxl, 3), PxlEngine(Pxl, 4))
                                                                EXIT SUB
                                                        END IF
                                                END IF
                                        NEXT TY
                                NEXT TX
                                PxlEngine(Pxl, 4) = PxlEngine(Pxl, 4) + PxlEngine(Pxl, 5)
                                IF PxlEngine(Pxl, 4) < 1 THEN
                                        PxlEngine(Pxl, 4) = 1
                                        PxlEngine(Pxl, 5) = INT((3 - 1 + 1) * RAND + 1)
                                ELSEIF PxlEngine(Pxl, 4) > INT((SUColor - SLColor + 1) / Groups - SpaceGroups) THEN
                                        PxlEngine(Pxl, 4) = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                                        PxlEngine(Pxl, 5) = -INT((3 - 1 + 1) * RAND + 1)
                                END IF



                                LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), 0
                                PxlEngine(Pxl, 6) = 0



                                EXIT SUB
                        END IF
                ELSE
                        s = INT(RAND + .5) * 2 - 1
                        e = -s
                        st = (e - s) / ABS(e - s)
                        FOR TX = s TO e STEP st
                                s2 = INT(RAND + .5) * 2 - 1
                                e2 = -s2
                                st2 = (e2 - s2) / ABS(e2 - s2)
                                FOR TY = s2 TO e2 STEP st2
                                        works = -1
                                        IF TryX + TX < SWidth - SBorder AND TryX + TX > SBorder AND TryY + TY > SBorder AND TryY + TY < SHeight - SBorder THEN
                                                IF POINT(TryX + TX, TryY + TY) <> 0 THEN
                                                        works = 0
                                                END IF
                                                IF works THEN
                                                        TryX = TryX + TX
                                                        TryY = TryY + TY
                                                        EXIT FOR
                                                END IF
                                        ELSE
                                                works = 0
                                        END IF
                                NEXT TY
                                IF works THEN EXIT FOR
                        NEXT TX
                END IF
        ELSE
                LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), 0
        END IF
        IF NOT works AND PxlEngine(Pxl, 1) > SBorder AND PxlEngine(Pxl, 1) < SWidth - SBorder AND PxlEngine(Pxl, 2) > SBorder AND PxlEngine(Pxl, 2) < SHeight - SBorder THEN
                make = -1
        ELSE
                make = 0
        END IF
        IF make THEN
                PxlEngine(Pxl, 6) = 0
                EXIT SUB
        ELSEIF NOT works THEN
                LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), 0
                PxlEngine(Pxl, 6) = 0
                EXIT SUB
        END IF
        PxlEngine(Pxl, 1) = TryX
        PxlEngine(Pxl, 2) = TryY
        PxlEngine(Pxl, 4) = PxlEngine(Pxl, 4) + PxlEngine(Pxl, 5)
        IF PxlEngine(Pxl, 4) < 1 THEN
                PxlEngine(Pxl, 4) = 1
                PxlEngine(Pxl, 5) = INT((3 - 1 + 1) * RAND + 1)
        ELSEIF PxlEngine(Pxl, 4) > INT((SUColor - SLColor + 1) / Groups - SpaceGroups) THEN
                PxlEngine(Pxl, 4) = INT((SUColor - SLColor + 1) / Groups - SpaceGroups)
                PxlEngine(Pxl, 5) = -INT((3 - 1 + 1) * RAND + 1)
        END IF
        LINE (PxlEngine(Pxl, 1), PxlEngine(Pxl, 2))-(PxlEngine(Pxl, 1), PxlEngine(Pxl, 2)), ColorGroups(PxlEngine(Pxl, 3), PxlEngine(Pxl, 4))
END SUB

FUNCTION RAND
        'RANDOMIZE TIMER
        RAND = RND
END FUNCTION

SUB RegenPxl
        FOR i = 1 TO Pxls * Groups
                IF NOT PxlEngine(i, 6) THEN
                        TY = SHeight - SBorder - PxlEngine(i, 2)
                        RX = SWidth - SBorder - PxlEngine(i, 1)
                        LX = PxlEngine(i, 1) - SBorder
                        BY = PxlEngine(i, 2) - SBorder
                        MX = MIN(RX, LX)
                        MY = MIN(TY, BY)
                        IF MX < MY OR -INT(RAND + RAND / 2) THEN
                        'IF -INT(RAND + .5) THEN
                                PxlEngine(i, 1) = SWidth - SBorder
                                IF MX = LX OR -INT(RAND + RAND / 2) THEN PxlEngine(i, 1) = SBorder
                                'IF -INT(RAND + .5) THEN PxlEngine(i, 1) = SBorder
                        ELSE
                                PxlEngine(i, 2) = SHeight - SBorder
                                IF MY = BY OR -INT(RAND + RAND / 2) THEN PxlEngine(i, 2) = SBorder
                                'IF -INT(RAND + .5) THEN PxlEngine(i, 2) = SBorder
                        END IF
                        IF POINT(PxlEngine(i, 1), PxlEngine(i, 2)) <> 0 THEN
                                DO
                                        works = -1
                                        IF -INT(RAND + .5) THEN
                                                coord = INT((SWidth - SBorder - SBorder + 1) * RAND + SBorder)
                                                PxlEngine(i, 1) = coord
                                                PxlEngine(i, 2) = SBorder + INT(RAND + .5) * (SHeight - 2 * SBorder + 1)
                                        ELSE
                                                coord = INT((SHeight - SBorder - SBorder + 1) * RAND + SBorder)
                                                PxlEngine(i, 2) = coord
                                                PxlEngine(i, 1) = SBorder + INT(RAND + .5) * (SWidth - 2 * SBorder + 1)
                                        END IF
                                        IF POINT(PxlEngine(i, 1), PxlEngine(i, 2)) <> 0 THEN works = 0
                                LOOP UNTIL works
                        END IF
                        PxlEngine(i, 4) = INT(INT((SUColor - SLColor + 1) / Groups - SpaceGroups) * RAND + 1) 'color
                        PxlEngine(i, 5) = INT((3 - 1 + 1) * RAND + 1) 'rate of change for color
                        PxlEngine(i, 6) = -1 'alive (-1) or dead (0)
                        LINE (PxlEngine(i, 1), PxlEngine(i, 2))-(PxlEngine(i, 1), PxlEngine(i, 2)), ColorGroups(PxlEngine(i, 3), PxlEngine(i, 4))
                END IF
        NEXT i
        'PxlEngine(i, 1) = PxlEngine(i - 1, 1) AND PxlEngine(i, 2) = PxlEngine(i - 1, 2)
END SUB

If you want more random pictures, make Pxls be random and regenerated each time you hit "n".
holy crap! this whole time i didn't know that with z!re's program if you press 'n' you get a new drawing. :-?
Pages: 1 2 3 4