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

Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
I admit that color picker is confusing, the box at the bottom should Simply and Only show the current color selected.

I will fix up after getting this Tree Maker settled and the dog walked.

@SierraKen

I haven't checked yet but sounds like you have File Dialog working, I will assume you like very much ;-))
The BM file had a 2nd routine for file save AS, I hope that is what you found and didn't have to go through a bunch of extra work.

Offline SierraKen

  • Forum Resident
  • Posts: 943
Thanks B+. Nah I didn't change the BM file. I just added one line of code to automatically rename it to a jpg file if it wasn't already one.
I made many more small fixes since my last post, including thicker Ray lines. I'll wait until you are done with your color picker before I make a new zip file, but here's the code you can use. I'll add a picture of the thicker ray lines used with your fill-in code example in the attachments.


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

Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
@SierraKen

OK I left the colorDialog$ Function in the tester sub in case you want to play with settings yourself, otherwise just replace the function with this one. I don't think I messed with slider code.

I have made changes besides the giant color sample color box (not so pretty but not so confusing either):
1. Moved Color Dialogue to screen _middle
2. gave the test sample box a black background color, so the sample color is over black, keep that in mind when changing alpha = transparency
3. I defaulted alpha to full opaque 255, maybe some or mostly want solid color.

Color Dialog in tester:
Code: QB64: [Select]
  1. _TITLE "Color Dialog rev 2020-06-27" 'b+ 2020-06-27
  2. SCREEN _NEWIMAGE(400, 300, 32)
  3. _DELAY .25
  4.  
  5. WHILE _KEYDOWN(27) = 0
  6.     CLS
  7.     k~& = VAL(colorDialog$)
  8.     PRINT "Color is: "; k~&
  9.     LINE (20, 40)-(_WIDTH - 20, _HEIGHT - 20), k~&, BF
  10.     _DELAY 2
  11.  
  12. FUNCTION colorDialog$
  13.  
  14.     'first screen dimensions items to restore at exit
  15.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  16.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  17.  
  18.     DIM cd AS LONG
  19.     DIM makeConst$, k$
  20.     DIM f AS SINGLE
  21.  
  22.     'save old settings to restore at end ofsub
  23.     curRow = CSRLIN
  24.     curCol = POS(0)
  25.     autoDisplay = _AUTODISPLAY
  26.     sw = _WIDTH
  27.     sh = _HEIGHT
  28.     fg = _DEFAULTCOLOR
  29.     bg = _BACKGROUNDCOLOR
  30.     _KEYCLEAR
  31.     'screen snapshot
  32.     curScrn = _DEST
  33.     backScrn = _NEWIMAGE(sw, sh, 32)
  34.     _PUTIMAGE , curScrn, backScrn
  35.  
  36.     cd = _NEWIMAGE(800, 600, 32)
  37.     SCREEN cd
  38.     _DELAY .25
  39.     r = 128: g = 128: b = 128: a = 255
  40.     COLOR &HFFDDDDDD, &HFF000000
  41.     DO
  42.         CLS
  43.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  44.         COLOR &HFFDDDDDD, 0
  45.         slider 16, 10, r, "Red"
  46.         slider 16, 60, g, "Green"
  47.         slider 16, 110, b, "Blue"
  48.         slider 16, 160, a, "Alpha"
  49.         COLOR &HFFDDDDDD, &HFF000000
  50.         _PRINTSTRING (150, 230), "Current Color Setting is shown below (Alphas on Black Background)"
  51.         _PRINTSTRING (150, 260), "Press Enter or Spacebar, if you want to use the color: " + makeConst$
  52.         _PRINTSTRING (210, 280), "Press Escape or Q to not use any color, returns 0."
  53.         LINE (90, 300)-(710, 590), &HFF000000, BF
  54.         LINE (90, 300)-(710, 590), VAL(makeConst$), BF
  55.         WHILE _MOUSEINPUT: WEND
  56.         mb = _MOUSEBUTTON(1)
  57.         IF mb THEN 'clear it
  58.             mx = _MOUSEX: my = _MOUSEY
  59.             IF mx >= 16 AND mx <= 781 THEN
  60.                 IF my >= 10 AND my <= 50 THEN
  61.                     r = INT((mx - 16) / 3)
  62.                 ELSEIF my >= 60 AND my <= 100 THEN
  63.                     g = INT((mx - 16) / 3)
  64.                 ELSEIF my >= 110 AND my <= 150 THEN
  65.                     b = INT((mx - 16) / 3)
  66.                 ELSEIF my >= 160 AND my <= 200 THEN
  67.                     a = INT((mx - 16) / 3)
  68.                 END IF
  69.             END IF
  70.         END IF
  71.         k$ = INKEY$
  72.         IF LEN(k$) THEN
  73.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  74.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  75.         END IF
  76.         _DISPLAY
  77.         _LIMIT 60
  78.     LOOP
  79.  
  80.     'put things back
  81.     SCREEN curScrn
  82.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  83.     _PUTIMAGE , backScrn
  84.     _DISPLAY
  85.     COLOR fg, bg
  86.     _FREEIMAGE backScrn
  87.     _FREEIMAGE cd
  88.     IF autoDisplay THEN _AUTODISPLAY
  89.     'clear key presses
  90.     _KEYCLEAR
  91.     'clear mouse clicks
  92.     mb = _MOUSEBUTTON(1)
  93.     IF mb THEN 'clear it
  94.         WHILE mb 'OK!
  95.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  96.             _LIMIT 10
  97.         WEND
  98.     END IF
  99.     LOCATE curRow, curCol
  100.  
  101.  
  102. SUB slider (x, y, value, label$)
  103.     DIM c~&, s$
  104.     SELECT CASE label$
  105.         CASE "Red": c~& = &HFFFF0000
  106.         CASE "Green": c~& = &HFF008800
  107.         CASE "Blue": c~& = &HFF0000FF
  108.         CASE "Alpha": c~& = &H88FFFFFF
  109.     END SELECT
  110.     LINE (x, y)-STEP(765, 40), c~&, B
  111.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  112.     s2$ = STR$(value)
  113.     s3$ = LTRIM$(RTRIM$(s2$))
  114.     s$ = label$ + " = " + s3$
  115.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  116.  
  117.  

We could go back to that pretty color box, the user clicks a point and that becomes the color picked.

That is like killing 3 sliders with one click! ;-))

(That is maybe what TempodiBasic thought was supposed to happen.)
« Last Edit: June 27, 2020, 04:27:13 PM by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 943
The new color picker works GREAT! Thanks! One thing though I should mention is that for some reason the Fill-in Sub sometimes doesn't gets used when it needs it. I tested that by putting a PRINT "test" in the Sub and sometimes it just won't do anything. I thought maybe it has to wait until the other one is finished but I don't think that's the case because I wait a bit longer and sometimes it still doesn't work. When I added the different colors to the Sub I might have messed it up, I don't know. Can you check it for me? Here is the code. Oh by the way, I think the 3 Sliders is an awesome thing because it helps the user get in control of exactly what color they want, instead of just guessing on a click.

The first section:
Code: QB64: [Select]
  1.     'Here is Fill-In
  2.     IF a$ = "f" OR a$ = "F" THEN
  3.         fMode = 1 - fMode
  4.         m = 6
  5.         IF fMode THEN lastx = mousex: lastY = mousey
  6.     END IF
  7.     IF fMode AND m = 6 THEN
  8.         _TITLE "Mode: (F)ill | (D)raw, (E)rase, 1 = New, (C)olors, (R)ays, (O)rbits, (B)oxes, (S)ave, (L)oad, (P)rint"
  9.         IF mouseLeftButton THEN paint3 lastx, lastY, clr~&, &HFFFFFFFF
  10.         lastx = mousex
  11.         lastY = mousey
  12.         _PUTIMAGE , s&, picture&
  13.     END IF
  14.  

Here is the Sub itself:
Code: QB64: [Select]
  1. SUB paint3 (x0, y0, clr~&, 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.  

Oh, and here are the 2 tiny Functions.
Code: QB64: [Select]
  1. FUNCTION min (n1, n2)
  2.     IF n1 > n2 THEN min = n2 ELSE min = n1
  3.  
  4. FUNCTION max (n1, n2)
  5.     IF n1 < n2 THEN max = n2 ELSE max = n1
  6.  
« Last Edit: June 27, 2020, 06:03:24 PM by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 943
I just changed one line from lastx, lasty to mousex, mousey. But it still does the same thing sometimes.

Code: QB64: [Select]
  1. IF mouseLeftButton THEN paint3 mousex, mousey, clr~&, &HFFFFFFFF
  2.  

Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
I checked fill from code in reply #16
 

Looks OK

Remember fill only fills all color around it that is exactly the same as point you click.

If you try fill over photo where nearly every color is different you will want to fill to a border color, draw the border and then use PAINT (x, y), fillColor, toBorderColor

Wait....


Why are there 4 parameters in PAINT3? It should look like this:
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

When you call it inside your program
PAINT3 mousex, mousey, colorToFillInWith '< the color selected off picker 

No 4th argument!
« Last Edit: June 27, 2020, 07:23:27 PM by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 943
The more you use it on one image, the lesser it works on my end. The first few times it works fine. But if you use it like over 5 times, every other time it doesn't work, and sometimes it only works every few times. So please try it again. Make a big scribble and try it about 10 times. If it works perfectly on your end, then something is off. By the way, my QB64 version is 1.3 still. I think it's time to get 1.4.

Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
No I see you mucked up PAINT3, only 3 arguments in the call.

It's a wonder it works at all?

OK new Color Picker and PAINT3 returned to 3 arguments and yes, I see what you mean. After awhile the clicks don't work or only rarely.

EDIT: Sorry wrong copy posted, seems I lost track of proper mod.
« Last Edit: June 27, 2020, 08:36:26 PM by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 943
Bplus, yours doesn't work with a white background. And yours only produces a white fill-in. So I had to add the current color variable to it. Maybe I did mess it up, but that's why I'm asking you.

Offline SierraKen

  • Forum Resident
  • Posts: 943
Here it is with your SUB... try it out..


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

Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
Yeah I plugged in the old PAINT3 and new Color Picker and see what you mean about clicks not working after awhile.

I updated here: https://www.qb64.org/forum/index.php?topic=2751.msg119938#msg119938

BTW your orbits and boxes work funny too?

But I do like the thicker lines, that's new right?
« Last Edit: June 27, 2020, 07:41:10 PM by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 943
Thanks for adding the color. Well, I never changed your orbits and boxes. But they work good for me. This isn't a professional app :).
But yeah, the Fill-In still has the same problem of not working sometimes. I don't know if there's a fix for this or not. I wonder if it's trying to squeeze in between points and filling up other stuff, because I did notice that one shade of an already-existing fill-in changed color a tiny bit when I used the fill-in on a different place. If you think I should just remove the fill-in that's OK with me. I'm just having fun with this. Oh and yeah I made the lines thicker earlier today. I like them too. :) Those and the open and save windows dialog totally made my weekend.

Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
Dang it I posted wrong code here:
https://www.qb64.org/forum/index.php?topic=2751.msg119938#msg119938

It has your paint3, I am getting confused... I know PAINT3 works if you don't mess with parameters and it's innards.

You could check if you have a shared variable that PAINT3 might be changing or be change by but I doubt you share variables that much.

What is difference between your oldx, oldy and lastx, lasty?


Offline bplus

  • Forum Resident
  • Posts: 4564
  • B+ nots
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, &HFFFFFFFF '<<<<<<<<<<<<<< no use the users Clr~& pick
  4.         lastx = mousex
  5.         lastY = mousey
  6.         _PUTIMAGE , s&, picture&
  7.     END IF

Offline SierraKen

  • Forum Resident
  • Posts: 943
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.