get at point color

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

get at point color

Post by mestnyi »

can you confirm that this is a bug in windows?

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example DPI", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(0, 200, 200, 24, $FFFFFF) And StartDrawing(ImageOutput(0))
        
      ; Draw the same figure at different locations by moving the drawing origin
      For x = 0 To 120 Step 40
        For y = 0 To 120 Step 60
          
          SetOrigin(x, y)
          
          color = Point(x, y) 
          
          Debug color
          
          Box(0, 0, 30, 30, $FF0000)
          Circle(15, 15, 10, $00FF00)
          
          
          Circle(15, 15, 5, color)
          
        Next y
      Next x   
         
      StopDrawing() 
      ImageGadget(0, 0, 0, 200, 200, ImageID(0))      
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: get at point color

Post by infratec »

If you use SetOrigin() you move the offset.
If you use the original x y, you get out of the image.

Use

Code: Select all

Debug Str(x) + "/" + Str(y)
to see the cordinates.
If you get 120 for y you are at 240 in reality, which is out of the image.
User avatar
Bisonte
Addict
Addict
Posts: 1320
Joined: Tue Oct 09, 2007 2:15 am

Re: get at point color

Post by Bisonte »

the help says for POINT() :
For performance reasons there are no bounds checks performed on these coordinates, the specified coordinates must be inside the current drawing area. OutputWidth() and OutputHeight() can be used to verify that. This command is also not affected by calls to ClipOutput().
So there is no check if the coordinates are exist... and if not... error. I said no bug, because the help also said : This command is also not affected by calls to ClipOutput() so I think all is ok.
It makes no sense in your example to write Point(x, y) more 0, 0 or another fixed point, because you are already use a SetOrigin and there you not need the whole Output...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: get at point color

Post by mestnyi »

in this example I expected the inner circle to be colored blue, what do you think?

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example DPI", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, 200, 200, 24, $FFFFFF) And StartDrawing(ImageOutput(0))
    x = 50
    y = 50
    size = 30
    
    Box(x, y, size, size, $FF0000)
    Circle(x+15, y+15, 10, $00FF00)
                
    color = Point(x+size, y+size) 
    
    Debug color
    
    Circle(x+15, y+15, 5, color)
    
    
    StopDrawing() 
    ImageGadget(0, 0, 0, 200, 200, ImageID(0))      
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
User avatar
jacdelad
Addict
Addict
Posts: 2031
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: get at point color

Post by jacdelad »

Point gets a pixel outside your rectangle, because the box ends at X+size-1 (the first of your 30 pixels is on X, then 29 remaining). A box with width 1 draws a single pixel at x,y. Width 2 draws 2 pixel next to each other (x and X+1). The last pixel is always X+width-1. And of course same with y.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
mestnyi
Addict
Addict
Posts: 1102
Joined: Mon Nov 25, 2013 6:41 am

Re: get at point color

Post by mestnyi »

jacdelad wrote: Sat Oct 26, 2024 6:20 pm Point gets a pixel outside your rectangle, because the box ends at X+size-1 (the first of your 30 pixels is on X, then 29 remaining). A box with width 1 draws a single pixel at x,y. Width 2 draws 2 pixel next to each other (x and X+1). The last pixel is always X+width-1. And of course same with y.
why box draw X+size-1?
User avatar
jacdelad
Addict
Addict
Posts: 2031
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: get at point color

Post by jacdelad »

I said the box ends at X+size-1. The last pixel is there. You get the colour of X+size...but never drew there.

As an example:

Code: Select all

Box(0,0,1,1)
draws a box containing just a single pixel at 0,0. You try to get the pixel at 1,1, aka X+size.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: get at point color

Post by Mijikai »

A Macro to help debug color:

Code: Select all

Macro DebugColorTriplet(_v_)
  Debug RSet(Hex(_v_,#PB_Long),6,"0")
EndMacro

DebugColorTriplet(65280)
Post Reply