Author Topic: Paint Pixels 7 With JPG Saves And No Gaps In Drawing And Thicker Drawing!  (Read 860 times)

Online SierraKen

  • Forum Resident
  • Posts: 943
oldx and oldy are used with the draw and erase. lastx and lasty are used with everything else. I guess I could try using lastx and lasty on draw and erase instead, will try that.

Online SierraKen

  • Forum Resident
  • Posts: 943
OK I removed oldx and oldy and it seems to work fine with just lastx and lasty, thanks. But before I post the code again, I just need to figure out how to remove &HFFFFFFFF without getting a Syntax Error. I know I am a total newbie at SUBs. lol

Online bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
I don't know why, but without that HFFFFFF, it makes a Syntax Error.
When I do this:
Code: QB64: [Select]
  1. IF mouseLeftButton THEN paint3 mousex, mousey, clr~&  
  2.  

The above looks right and works in my copy with old PAINT3 restored to 3 arguments instead of 4.

Does the first line of PAINT3 sub look like this:
SUB paint3 (x0, y0, fill AS _UNSIGNED LONG) ' needs max, min functions
« Last Edit: June 27, 2020, 08:34:38 PM by bplus »

Online SierraKen

  • Forum Resident
  • Posts: 943
The SUB line had the clr~& also, so I just pasted yours in instead. But now Fill doesn't work at all. Here, let show you what I have. I do appreciate your help as always but if you are getting tired of this, just let me know and we can call it a day. Up to you.

Code: QB64: [Select]
  1.     IF fMode AND m = 6 THEN
  2.         _TITLE "Mode: (F)ill | (D)raw, (E)rase, 1 = New, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  3.         IF mouseLeftButton THEN paint3 mousex, mousey, clr~&
  4.         lastx = mousex
  5.         lasty = mousey
  6.         _PUTIMAGE , s&, picture&
  7.     END IF
  8.  


Code: QB64: [Select]
  1. SUB paint3 (x0, y0, fill AS _UNSIGNED LONG) ' needs max, min functions
  2.     DIM fillColor AS _UNSIGNED LONG, W, H, parentF, tick, ystart, ystop, xstart, xstop, x, y
  3.     fillColor = POINT(x0, y0)
  4.     W = _WIDTH - 1: H = _HEIGHT - 1
  5.     DIM temp(W, H)
  6.     temp(x0, y0) = 1: parentF = 1
  7.     PSET (x0, y0), clr~&
  8.     WHILE parentF = 1
  9.         parentF = 0: tick = tick + 1
  10.         ystart = max(y0 - tick, 0): ystop = min(y0 + tick, H)
  11.         y = ystart
  12.         WHILE y <= ystop
  13.             xstart = max(x0 - tick, 0): xstop = min(x0 + tick, W)
  14.             x = xstart
  15.             WHILE x <= xstop
  16.                 IF POINT(x, y) = fillColor AND temp(x, y) = 0 THEN
  17.                     IF temp(max(0, x - 1), y) THEN
  18.                         temp(x, y) = 1: parentF = 1: PSET (x, y), clr~&
  19.                     ELSEIF temp(min(x + 1, W), y) THEN
  20.                         temp(x, y) = 1: parentF = 1: PSET (x, y), clr~&
  21.                     ELSEIF temp(x, max(y - 1, 0)) THEN
  22.                         temp(x, y) = 1: parentF = 1: PSET (x, y), clr~&
  23.                     ELSEIF temp(x, min(y + 1, H)) THEN
  24.                         temp(x, y) = 1: parentF = 1: PSET (x, y), clr~&
  25.                     END IF
  26.                 END IF
  27.                 x = x + 1
  28.             WEND
  29.             y = y + 1
  30.         WEND
  31.     WEND
  32.  

Online bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
Here is the original PAINT3 before you changed variable names
Code: QB64: [Select]
  1. SUB paint3 (x0, y0, fill AS _UNSIGNED LONG) ' needs max, min functions
  2.     DIM fillColor AS _UNSIGNED LONG, W, H, parentF, tick, ystart, ystop, xstart, xstop, x, y
  3.     fillColor = POINT(x0, y0)
  4.     'PRINT fillColor
  5.     W = _WIDTH - 1: H = _HEIGHT - 1
  6.     DIM temp(W, H)
  7.     temp(x0, y0) = 1: parentF = 1
  8.     PSET (x0, y0), fill
  9.     WHILE parentF = 1
  10.         parentF = 0: tick = tick + 1
  11.         ystart = max(y0 - tick, 0): ystop = min(y0 + tick, H)
  12.         y = ystart
  13.         WHILE y <= ystop
  14.             xstart = max(x0 - tick, 0): xstop = min(x0 + tick, W)
  15.             x = xstart
  16.             WHILE x <= xstop
  17.                 IF POINT(x, y) = fillColor AND temp(x, y) = 0 THEN
  18.                     IF temp(max(0, x - 1), y) THEN
  19.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  20.                     ELSEIF temp(min(x + 1, W), y) THEN
  21.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  22.                     ELSEIF temp(x, max(y - 1, 0)) THEN
  23.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  24.                     ELSEIF temp(x, min(y + 1, H)) THEN
  25.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  26.                     END IF
  27.                 END IF
  28.                 x = x + 1
  29.             WEND
  30.             y = y + 1
  31.         WEND
  32.     WEND
  33.  

Keep it how it is and then the call to it
Code: QB64: [Select]
  1. IF mouseLeftButton THEN paint3 mousex, mousey, clr~&  

will work, clr~& will get passed through and be used where ever fill is in the SUB just like mousex will replace all x0, and mousey will replace all y0. That's how sub arguments work.

That's the beauty of SUBs all the x,y's inside a SUB have their own meanings only inside the SUB and have no relation to x, y's outside the SUB. You don't have to worry about changing x, y in the main code because you are using them in the SUB, that is the real advantage of SUBs. 
« Last Edit: June 27, 2020, 09:08:23 PM by bplus »

Online SierraKen

  • Forum Resident
  • Posts: 943
Thanks again. I just replaced mine with all of yours completely with your new code. And the colors work pretty good. Still has a bit of a problem of sometimes not working but let's leave it at that. It might even have something to do with the Mouse left button detection. But we can leave it as it is and since it works around 80% of the time or so, people can just click a few more times in the same area to make it work. I'm off for the night myself. If you want to work on it more, go right ahead. Here is the entire program besides the 4 needed library files, which can be found on an earlier post.
Thanks for your time and effort B+, it's still a GREAT program and soon I might add more to it sometime.


Update: Huge memory issue found, please delete this version if you have it. Code has been removed.
« Last Edit: July 04, 2020, 05:21:59 PM by SierraKen »

Online SierraKen

  • Forum Resident
  • Posts: 943
Just a quick note, I just found out that when it doesn't work, it's because the whole program freezes up for a few seconds. So, there's either a loop that won't end somewhere or a memory glitch. I have a pretty good computer though, Windows 10 Quadcore with 16 GB RAM.

Online SierraKen

  • Forum Resident
  • Posts: 943
Whew... I just figured something really important out. The mouse detection is 2 times per click sometimes. So it was doing 2 entire processes at once sometimes. I know this from what I did earlier today with using the PRINT command, it made 2 words every time the Fill click happened. So, I just put in a quick IF  mouseLeftButton then mouseLeftButton = 0 right after the paint3 call on the next line. And now it works around 100% of the time!!! It also works faster. Here is the updated and fixed code. B+ please check it out because you spent tons of time on this. Attached is the new zip file with all the files and also attached is a picture of a scribble I made with 50 1-click fill-ins that were perfect every time. Thanks again B+ for the help and keeping me going at this.




Online bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
Good! and the old color picker was prettier anyway :-))

Glad we got PAINT3 working, it is nice variation to other PAINT options but you might want a paint fill to a border color for filling in on an image in the future.


Online SierraKen

  • Forum Resident
  • Posts: 943
LOL Woops! I forgot to put the new color picker on it again. I think I will because I like how it's very easy to tell what the new color is from the big color box you made. I'll post the new zip in a few minutes. Thanks for telling me! My memory (in my noggin) is very bad sometimes.

Online bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
I think one can get a little batty trying to chase down two mice! Tom and Jerry and Jerry's twin brother Gary. ;)
« Last Edit: June 27, 2020, 10:21:06 PM by bplus »

Online SierraKen

  • Forum Resident
  • Posts: 943
LOL and the Gremlins strike again! I replaced your older color dialog Function with your newer one again and now the Fill is doing that same problem. So I'm going to stop while I'm ahead and just keep the old color picker. :)) I have absolutely no idea what happened but I'm going to back away... LOL

Online SierraKen

  • Forum Resident
  • Posts: 943
I once heard, a long time ago, that color can "bleed" through to another screen somehow? LOL here I go again, trying to hunt down the mice. LOL

Online bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
Here is the one with new simpler Color Dialog, since my name is on this too I can help ;)

Update: OK download seems to be working correctly.

You know this fill reminds me of Dav's Game of filling colors until the whole screen is one color.

« Last Edit: June 27, 2020, 10:44:04 PM by bplus »

Online SierraKen

  • Forum Resident
  • Posts: 943
Bplus, by now you probably hate me LOL but I just found something I totally forgot today. To add what the Cancel button does on the Open and Save dialogues. It's not hard to fix though. I just added IF NM$ = "" THEN GOTO.....
Just copy/paste this into your Save Section and Open Section.

Code: QB64: [Select]
  1. 'Saving Section
  2. saving:
  3. nm$ = GetSaveFileName("Save Image" + CHR$(0), ".\", "JPG Image (.JPG)|*.JPG" + CHR$(0), 1, OFN_OVERWRITEPROMPT + OFN_NOCHANGEDIR, _WINDOWHANDLE)
  4. IF nm$ = "" THEN GOTO skipsave:
  5. IF RIGHT$(nm$, 4) <> ".jpg" THEN nm$ = nm$ + ".jpg"
  6. _DELAY .25
  7. Result = SaveImage(nm$, 0, 0, 0, _WIDTH(img), _HEIGHT(img)) 'first zero is your screen, second zero is X start, 3th zero is y start
  8. _DELAY .25
  9. nm$ = ""
  10. skipsave:
  11. dMode = 1
  12. m = 1
  13.  
  14. 'Loading Section
  15. loading:
  16. nm$ = GetOpenFileName("Open Image" + CHR$(0), ".\", "JPG Image (.JPG)|*.JPG" + CHR$(0), 1, OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_READONLY, _WINDOWHANDLE)
  17. l = 0
  18. IF nm$ = "" THEN GOTO skipopen:
  19. i& = _LOADIMAGE(nm$, 32)
  20. s& = i&
  21. i& = 0
  22. screenx = _WIDTH
  23. screeny = _HEIGHT
  24. picture& = _NEWIMAGE(screenx, screeny, 32)
  25. skipopen:
  26. dMode = 1
  27. m = 1
  28.