timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Apr 24, 2020 1:18:26 GMT -5
There was a task to determine the color of the point. I solved it by saving the file with a dot and reading the contents of the file. Here is a test case
|
|
timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Apr 24, 2020 1:19:43 GMT -5
'nomainwin WindowWidth=1050 WindowHeight=560 global rr$,gg$,bb$'для возвращения значения цвета graphicbox #win.gbox, 0, 0, 512, 512 graphicbox #win.gbox2, 512, 0, 512, 512 open "Drawing" for window as #win print #win, "trapclose [quit]" print #win.gbox, "down" print #win.gbox, "size 2" print #win.gbox, "place 1 1" for i=0 to 254 for a=0 to 6.28318 step 0.005 x=255+i*cos(a) y=255+i*sin(a) s=254-i'127'255-i/2 d=127-ABS(i-127) r=s+d*cos(a) g=s+d*cos(a+3.141593*0.666666) b=s+d*cos(a+3.141593*1.333333) print #win.gbox, "color ";r;" ";g;" ";b print #win.gbox, "set ";x;" ";y next a next i
print #win.gbox, "flush"
print #win.gbox2, "down" print #win.gbox2, "size 5" for i1=1 to 511 step 4 for i2=1 to 511 step 4 call paint i2,i1 r=ASC(rr$) g=ASC(gg$) b=ASC(bb$) #win.gbox2, "color ";r;" ";g;" ";b #win.gbox2, "set ";i2;" ";i1 next i2 next i1
wait [quit] close #win end '- - - - - - - - - - - - - - - - sub paint x,y #win.gbox, "getbmp point ";x;" ";y;" 1 1"
bmpsave "point", "tempbmp.bmp" open "tempbmp.bmp" for binary as #PP seek #PP, lof(#PP)-4 bb$=input$(#PP,1) gg$=input$(#PP,1) rr$=input$(#PP,1) close #PP 'kill "tempbmp.bmp" end sub
|
|
|
Post by tsh73 on Apr 24, 2020 5:19:12 GMT -5
What you rediscovered is known hack But LB allows to call API finctions, and in this case, it will work MUCH faster
function getPixel(x,y) calldll #gdi32, "GetPixel", hDC as ulong, x as long, y as long, getPixel as long end function
|
|
|
Post by tenochtitlanuk on Apr 24, 2020 5:24:21 GMT -5
Getting colour details of a pixel this way ( first brought to the community by kcdan years ago) or the API method is the basis of many of my graphic examples on my LB website. www.diga.me.ukI look forward to seeing what you may do with this interesting graphic tool!
|
|
|
Post by tsh73 on Apr 24, 2020 5:47:51 GMT -5
Just put it in your program. On my box, copying part runs 4 to 5 times faster.
'nomainwin WindowWidth=1050 WindowHeight=560 global rr$,gg$,bb$'äëÿ âîçâðàùåíèÿ çíà÷åíèÿ öâåòà
graphicbox #win.gbox, 0, 0, 512, 512 graphicbox #win.gbox2, 512, 0, 512, 512 open "Drawing" for window as #win print #win, "trapclose [quit]"
pi = acs(-1) 'get the handle of the graphicbox and its associated DC global hDC,hWnd hWnd=hwnd(#win.gbox) calldll #user32, "GetDC", hWnd as ulong, hDC as ulong
print #win.gbox, "down" print #win.gbox, "size 2" print #win.gbox, "place 1 1" for i=1 to 254 for a=0 to 6.28318 step 1/i x=255+i*cos(a) y=255+i*sin(a) s=254-i'127'255-i/2 d=127-ABS(i-127) r=s+d*cos(a) g=s+d*cos(a+pi*2/3) b=s+d*cos(a+pi*4/3) print #win.gbox, "color ";r;" ";g;" ";b print #win.gbox, "set ";int(x);" ";int(y) next a next i
print #win.gbox, "flush"
t0=time$("ms") print #win.gbox2, "down" print #win.gbox2, "size 5" for i1=1 to 511 step 4 for i2=1 to 511 step 4 'call paint i2,i1 'r=ASC(rr$) 'g=ASC(gg$) 'b=ASC(bb$) colr = getPixel(i2,i1) r = colr and 255 g = int(colr/256) and 255 b = int(colr/256/256) #win.gbox2, "color ";r;" ";g;" ";b #win.gbox2, "set ";i2;" ";i1 next i2 next i1 t1=time$("ms") print "Time taken, ms :";t1-t0 '8 sec with API, 37 sec with file writing
wait [quit] close #win end '- - - - - - - - - - - - - - - - sub paint x,y #win.gbox, "getbmp point ";x;" ";y;" 1 1"
bmpsave "point", "tempbmp.bmp" open "tempbmp.bmp" for binary as #PP seek #PP, lof(#PP)-4 bb$=input$(#PP,1) gg$=input$(#PP,1) rr$=input$(#PP,1) close #PP 'kill "tempbmp.bmp" end sub
function getPixel(x,y) calldll #gdi32, "GetPixel", hDC as ulong, x as long, y as long, getPixel as long end function
|
|
timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Apr 24, 2020 8:14:15 GMT -5
Thank you very much, (but this is a departure from LB, you need to know what APIs are and how to apply them. The more APIs you use, the less LB remains.) But thanks anyway.
|
|
|
Post by tsh73 on Apr 24, 2020 12:38:11 GMT -5
The choice is always yours.
|
|