|
Post by johnno56 on Jun 22, 2023 14:50:51 GMT -6
n00bAs discussed. This is a simple tool to convert a colour under a hovering mouse pointer to RGB and display the sample rgb() command. It is rough but it seems to work. J. colour_to_RGB.zip (90.41 KB) (colour grid and font included)
|
|
|
Post by n00b on Jun 23, 2023 16:17:50 GMT -6
johnno56 This is a nice demo. I made some modifications to it to get rid of the flicker it had when switching colors. Try this out: xmax = 444 ymax = 480 title$ = "Colour to RGB" center_x = windowpos_centered center_y = windowpos_centered WindowOpen(1,title$,center_x,center_y,xmax,ymax,WindowMode(1,0,0,0,0),1) SetWindowAutoClose(1, 0) CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0) ClearCanvas
grid = 1: loadImage(1,"assets/grid.png") fnt = 1: loadFont(1,"assets/Verdana.ttf",32)
'-------Generate Color Buffer from grid--------
' Note: GetPixel is an expensive operation so we generate a buffer of colors from the grid here so we don't have to use GetPixel each frame
cb_cols = 13 cb_rows = 9 Dim ColBuf[cb_cols, cb_rows] '9 rows high, 13 cols across
'Draw Grid to Canvas so we can get colors from it DrawImage(grid, 0, 0) Update() 'Since GetPixel returns the color from the window, we need to update the window first
'There is a 2 pixel spacing between the colors in grid.png so we need to add that spacing to our colors when reading x_spc = 2 y_spc = 2
For x = 0 to cb_cols-1 y_spc = 2 For y = 0 to cb_rows-1 ColBuf[x, y] = GetPixel(x*32+x_spc+16, y*32+y_spc+16) y_spc = y_spc + 2 Next x_spc = x_spc + 2 Next '--------------------------------------
font(fnt)
Red = 0 Green = 0 Blue = 0
'Set the Color the screen is cleared with on ClearCanvas() SetClearColor(RGB(240,240,240))
do ' "Read" the X and Y co-ordinates of the mouse pointer mx = mousex() my = mousey()
' Set the background to a very, very light grey ClearCanvas()
' Place the color grid on the canvas DrawImage(grid,0,0)
' Draw a box around the color "sample" SetColor(RGB(16,16,16)) Rect(255,320,180,100) ' Is the mouse within the grid of colors? if mx > 0 and mx < 444 and my > 0 and my < 308 then ' If the mouse is not touching dark grey ' or very light grey... then "see" the color. 'Convert mouseX and mouseY to the x,y positions in our color buffer '* Each color cell is 32x32 and there is a 2 pixel spacing between them so we account for it in cx and cy cx = Int(( mx - (Int(mx / 32)+1)*2 ) / 32) cy = Int(( my - (Int(my / 32)+1)*2 ) / 32) c = ColBuf[cx, cy] 'Read the color from the color buffer we created if c <> rgb(16, 16, 16) then if c <> rgb(240, 240, 240) then ' Test the color under the mouse pointer Color = c ' Extract the R, G and B values from the raw colour. ' You can shift the bits in the color to the right to extract each Color ' We use AndBit to get the last 8 bits in the number after we shift it Red = AndBit( (c shr 16), 255) Green = AndBit( (c shr 8), 255) Blue = AndBit( (c), 255) ' Fill the "sample" SetColor(RGB(Red, Green, Blue)) RectFill(255,320,180,100) SetColor(RGB(16,16,16)) Rect(255,320,180,100) ' Display the values of R, G and B DrawText(str(Red), 160, 310) DrawText(str(Green), 160, 350) DrawText(str(Blue), 160, 390) ' Display the current RGB command SetColor(RGB(0, 160, 0)) DrawText("rgb( " + str(Red) + ", " + str(Green) + ", " + str(Blue) + " )", 90, 430) end if end if end if ' Display the values of R, G and B SetColor(RGB(0,0,0)) DrawText("Red:", 0, 310) DrawText("Green:", 0, 350) DrawText("Blue:", 0, 390) if Not WindowExists(1) Or WindowEvent_Close(1) Then end end if update() loop until key(27) = 1
|
|
|
Post by johnno56 on Jun 23, 2023 23:02:22 GMT -6
Much improved. Thank you.
|
|
|
Post by n00b on Jun 24, 2023 11:01:21 GMT -6
I think your demo was still a really good basic example (pun was intended). It might be good to include both in the next release to demonstrate how to work around the limitations of GetPixel().
|
|
|
Post by johnno56 on Jun 24, 2023 12:53:55 GMT -6
GetPixel() has limitations? I thought its sole purpose was to determine the colour of a pixel. Apart from using it as an inefficient form of collision detection, I cannot think of any limitations... unless you count that it does not convert the raw colour to RGB....
|
|
|
Post by n00b on Jun 24, 2023 14:52:28 GMT -6
I meant on performance. It's really slow.
|
|
|
Post by johnno56 on Jun 24, 2023 21:19:12 GMT -6
Agreed...
|
|
|
Post by johnno56 on Jun 25, 2023 5:45:31 GMT -6
Here is the 'primitives' file... As I mentioned before, the format, is almost identical to the manual. Some parts of the manual gave better descriptions than the ones I came up with, so I 'borrowed' those descriptions. I tried to elaborate a little for each description/example. Feel free to make any changes that need to be made. If there are too many, let me know, and I will try again. I had a crazy idea (ok. you can stop chuckling...) about attempting to make a menu driven program to demonstrate each command. Not sure exactly how but could be fun to try... do not hold your breath waiting for this one... lol J primitives.zip (2.22 KB) (Pure text. No fonts or colours etc)
|
|
|
Post by n00b on Jun 25, 2023 9:38:58 GMT -6
Thanks. I will do some formatting on this today and add it to the manual. I think your idea about a menu driven program to switch between the examples would be a great idea. I used a python library called Kivy a while back that did this with its examples. Here is a mockup I did of what I am thinking about:
|
|
|
Post by johnno56 on Jun 25, 2023 13:49:55 GMT -6
Well... What can I say? Your example is WAY better than my idea... lol (I even like the colours...)
|
|
|
Post by johnno56 on Jun 26, 2023 2:35:23 GMT -6
I am attempting to re-create the 'mock up' but having a less than successful time in selecting a nice font. Do you have any idea as to which font was used in your mockup? It looks a little 'times roman-ish' (which I have tried), but reducing the font size to the size in your mockup, causes the font to start to "break down"... There are a squillion fonts to choose from... I will keep looking...
|
|
|
Post by n00b on Jun 26, 2023 8:26:54 GMT -6
I am attempting to re-create the 'mock up' but having a less than successful time in selecting a nice font. Do you have any idea as to which font was used in your mockup? It looks a little 'times roman-ish' (which I have tried), but reducing the font size to the size in your mockup, causes the font to start to "break down"... There are a squillion fonts to choose from... I will keep looking... I just used the default font of kolour paint (it's in your software center) You might want to play around with a few fonts to find one that scales well. It doesn't need to match my mockup exactly.
|
|
|
Post by johnno56 on Jun 26, 2023 13:03:06 GMT -6
Yeah. Scaling seems to be the issue. I have had to increase the size of the mockup a little and it looks a bit better.
I have my grandson visiting until the end of the week (school holidays), as a result, early morning, between 0430 and 0700, may be my only window of opportunity to work on the demo... lol
|
|
|
Post by johnno56 on Jun 28, 2023 14:09:49 GMT -6
Long story short... As you know, my grandson visited a couple of days ago... The following day his sisters and older brother visited. Michael, the oldest, wanted to show me his version of 5 Nights at Freddy's that he has been working on for the better part of three years (using Scratch). By this time the game had ballooned out to more than 400mb and it took some time to load... Too long actually... My machine did a Walt Disney (froze) and refused to reboot time after time... It was a good thing that I had a spare HDD. Michael thought it was his fault... It was a combination of a Google Chrome bug and a HDD issue... I now have a bare-bones system up and running... Phew!! I really should get into the habit of imaging the HDD... *sigh*
|
|
|
Post by tbird on Jun 29, 2023 7:29:03 GMT -6
johnno56, you must be getting quite efficient at OS installs, I don't know of anyone that does fresh OS's as often as you. 😁 Joking aside glad your "up and running"
|
|