Author |
Topic: RGB COLOR MIXER UTILITY (Custom spheres Enhanced) (Read 607 times) |
|
michael
Senior Member
member is offline


Posts: 335
|
 |
RGB COLOR MIXER UTILITY (Custom spheres Enhanced)
« Thread started on: Apr 12th, 2016, 3:53pm » |
|
Now you can modify a custom color for a 3D sphere easily using this utility.. HA HA!!!... windows doesn't have that!! Let me know if there is any problems with the function of this (ok.. maybe I will add size manipulation, because it functions on a preset size, which kinda makes the sphere over extend the visible draw if the RGB settings are wild.. ) I will work on that and repost over this program. Code:
INSTALL @lib$+"WINLIB5"
sspheresize%=200:rrr%=25:ggg%=25:bbb%=25
REM define 8 buttons names and locations and the PROCs that they link to
REM the button control is in the next 2 lines
button1% = FN_button("GREEN--", 20, 40, 80, 20, FN_setproc(PROCp1), 0)
button2% = FN_button("RED--", 20, 10, 80, 20, FN_setproc(PROCp2), 0)
button3% = FN_button("RED++", 120, 10, 80, 20, FN_setproc(PROCp3), 0)
button4% = FN_button("GREEN++", 120, 40, 80, 20, FN_setproc(PROCp4), 0)
button5% = FN_button("BLUE--", 20, 70, 80, 20, FN_setproc(PROCp5), 0)
button6% = FN_button("BLUE++", 120, 70, 80, 20, FN_setproc(PROCp6), 0)
button7% = FN_button("ALL--",20,100,80,20,FN_setproc(PROCp7), 0)
button8% = FN_button("ALL++",120,100,80,20,FN_setproc(PROCp8), 0)
button9% = FN_button("Size++",120,130,80,20,FN_setproc(PROCp9), 0)
button10% = FN_button("Size--",20,130,80,20,FN_setproc(PROCp10), 0)
REM set up a custom window
PROCscreen(1500,800,"RGB COLOR MIXER FOR SPHERES MADE FOR BBC BASIC :pixel thickness of 3",3)
REPEAT
WAIT 1
UNTIL FALSE
END
REM Now the complexity has been removed ******************************
DEF PROCscreen(winwidth,winheight,winname$,pixelthickness%)
winwidth=1000:winheight=800
VDU 23,22,winwidth;winheight;8,15,16,128
VDU 23,23,pixelthickness%|
VDU 5 : REM Treat text as graphics (transparent background)
SYS "SetWindowText", @hwnd%, winname$
PROC_color("b",0,0,0)
REM now clear the screen with the background color
CLG
ENDPROC
REM notice how many PROCs share the same ENDPROC? That is intresting.
DEF PROCp1 : f=0
DEF PROCp2 : f=1
DEF PROCp3 : f=2
DEF PROCp4 : f=3
DEF PROCp5 : f=4
DEF PROCp6 : f=5
DEF PROCp7 : f=6
DEF PROCp8 : f=7
DEF PROCp9 : f=8
DEF PROCp10 : f=9
CLG
IF f=0 THEN ggg%=ggg%-5
IF f=1 THEN rrr%=rrr%-5
IF f=2 THEN rrr%=rrr%+5
IF f=3 THEN ggg%=ggg%+5
IF f=4 THEN bbb%=bbb%-5
IF f=5 THEN bbb%=bbb%+5
IF f=6 THEN rrr%=rrr%-5:ggg%=ggg%-5:bbb%=bbb%-5
IF f=7 THEN rrr%=rrr%+5:ggg%=ggg%+5:bbb=bbb%+5
IF f=8 THEN sspheresize%=sspheresize%+1
IF f=9 THEN sspheresize%=sspheresize%-1
IF sspheresize%<1 THEN sspheresize%=1
IF sspheresize%>250 THEN sspheresize%=250
IF rrr%>255 THEN rrr%=255
IF rrr%<20 THEN rrr%=20
IF ggg%>255 THEN ggg%=255
IF ggg%<20 THEN ggg%=20
IF bbb%>255 THEN bbb%=255
IF bbb%<20 THEN bbb%=20
PROC_sphere(200,1000,255,0,0,0,0)
PROC_sphere(200,1000,sspheresize%,rrr%,ggg%,bbb%,1)
COLOUR 0,255,255,255 : GCOL 0
PROC_color("b",0,0,0)
MOVE 80,1250
PRINT "R ";rrr%;" G ";ggg%;" B ";bbb%;" SIZE ";sspheresize%
ENDPROC
REM this is the foreground and background tool. (funny how I keep putting this in programs)
DEF PROC_color(fb$,rrr%,ggg%,bbb%)
IF fb$="f" OR fb$="F" THEN COLOUR 0,rrr%,ggg%,bbb% : GCOL 0
IF fb$="b" OR fb$="B" THEN COLOUR 1,rrr%,ggg%,bbb% : GCOL 128+1
ENDPROC
DEF PROC_sphere(H,V,SIZE,R,G,B,DI)
r%=R
g%=G
b%=B
size%=SIZE
dimmer%=DI
*REFRESH OFF
FOR x%=0 TO size%
c%=50
r%=r%-dimmer%
g%=g%-dimmer%
b%=b%-dimmer%
IF r% <2 THEN r%=2
IF g% <2 THEN g%=2
IF b%<2 THEN b%=2
IF r%<50 AND g%<50 AND b%<50 THEN GOTO (jump)
COLOUR 0,r%,g%,b%
CIRCLE H,V,x%
(jump)
NEXT x%
*REFRESH
ENDPROC
|
« Last Edit: May 31st, 2016, 1:21pm by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
Zaphod
Guest
|
 |
Re: RGB COLOR MIXER UTILITY (remade for BBC Basic)
« Reply #1 on: Apr 12th, 2016, 5:48pm » |
|
Windows has a built in dialog for that.
Code:
DIM CustCol{(15)col%}
DIM Cc{lStructSize%, hwndOwner%, hInstance%, rgbResult%, lpCustColors%, Flags%, lCustData%, lpfnHook%, lpTemplateName%}
Cc.lStructSize%=DIM(Cc{})
Cc.lpCustColors%=CustCol{(0)}
SYS"ChooseColor", Cc{}
PRINT "&"; ~Cc.rgbResult%
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646912%28v=vs.85%29.aspx
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: RGB COLOR MIXER UTILITY (remade for BBC Basic)
« Reply #2 on: Apr 12th, 2016, 5:55pm » |
|
I replaced the post with a more useful version..
|
« Last Edit: Apr 12th, 2016, 6:55pm by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
Zaphod
Guest
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #3 on: Apr 13th, 2016, 12:44am » |
|
Please forgive me, but I don't understand what it would be useful for, so have difficulty with why the update is more useful. Could you explain its application or is it just for amusement, not that there is anything wrong with that.
In terms of programming you might consider just using one button procedure and passing the button number as a parameter. Then using a CASE statement using the button number it could be considerably simplified.
Having several Procedures with the same body is a useful feature. Normally you would put: DEF PROCp1 :LOCAL f: f=0 DEF PROCp2 :LOCAL f: f=1
But you don't need the multiple DEFs if you had
DEF PROCp(f)
f, being a parameter will be local automatically.
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #4 on: Apr 13th, 2016, 01:20am » |
|
I Guess its a stairway to somewhere. A custom made sphere could be put in a game.. Or it could be put into a scene for decoration.. But perhaps I am not being creative enough.. I need to spice things up with a game..
Back in 1990 I made a stop animation text based game in Turbo Pascal 6.0.. (RIP) All the images were made with just code.. (believe it) That's perhaps why I have an obsession with using code for everything... Lets see what I can do.. This example was a lot to do with using the windows based controls to make things happen.. So.. I am one step closer to a game. So its not so much to do with the spheres..
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #5 on: Apr 13th, 2016, 08:33am » |
|
Hi Michael,
I've never been a huge fan of your "dimmer" approach, since you tend to cut the outer parts off your spheres,so you don't end up with a predictable size.
How about this approach, which uses Zaphod's (well, Windows'!) colour picker to get the colour, and then uses the resulting number in a sphere plotter a bit like yours, but which always gives a sphere of the specifiied size, and a smooth transition to a white highlight. I've provided two versions: the first takes separate R,G, and B values, while the other takes the combined colour number provided by the picker (or the user!). Code:
DIM CustCol{(15)col%}
DIM Cc{lStructSize%, hwndOwner%, hInstance%, rgb%, lpCustColors%, Flags%, lCustData%, lpfnHook%, lpTemplateName%}
Cc.lStructSize%=DIM(Cc{})
Cc.lpCustColors%=CustCol{(0)}
SYS"ChooseColor", Cc{}
PROCSphere(300,500,200,Cc.rgb% AND 255,(Cc.rgb%>>8) AND 255,(Cc.rgb%>>16) AND 255)
PROCSphereCN(600,500,100,Cc.rgb%)
END
:
DEFPROCSphere(px%,py%,rd%,r%,g%,b%)
DEFPROCSphereCN(px%,py%,rd%,rgb%):LOCAL r%,g%,b%:r%=rgb% AND 255:g%=(rgb%>>8) AND 255:b%=(rgb%>>16) AND 255
LOCAL x%,progress%,dr,dg,db
VDU 23,23,3| :REM Line thickness 3: to be good I should have tested and stored the current value, to be restored later
dr=(255-r%)/rd%
dg=(255-g%)/rd%
db=(255-b%)/rd%
GCOL 0
FOR x%=rd% TO 1 STEP -2
progress%=rd%-x%
COLOUR 0,r%+progress%*dr,g%+progress%*dg,b%+progress%*db
CIRCLE px%,py%,x%
NEXT x%
COLOUR 0,0,0,0 :REM Reset colour 0 to black - assumes that's what it was before!
ENDPROC
Best wishes,
D
|
|
Logged
|
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #6 on: Apr 13th, 2016, 1:16pm » |
|
Hi Michael,
I know how keen you are on "roll-your-own" solutions, rather than using the Windows functions, so how about this: Code:
MODE 8
c%=FNGetColour
PRINT c%
COLOUR 0,c% AND 255,(c%>>8)AND 255,(c%>>16) AND 255
GCOL 0
CIRCLE FILL 200,500,150
END
:
DEFFNGetColour
LOCAL x%,y%,z%,r%,g%,b%,done%
done%=FALSE
*REFRESH OFF
REPEAT
GCOL 0
RECTANGLE FILL0,0,400,100
GCOL 15
VDU 5
MOVE 0,30
PRINT"B"
RECTANGLE 20,10,255,20
MOVE 0,60
PRINT"G"
RECTANGLE 20,40,255,20
MOVE 0,90
PRINT"R"
RECTANGLE 20,70,255,20
LINE 20+r%,70,20+r%,90
LINE 20+g%,40,20+g%,60
LINE 20+b%,10,20+b%,30
COLOUR 7,r%,g%,b%
GCOL 7
RECTANGLE FILL 300,10,80,80
GCOL 15
RECTANGLE 390,10,80,80
MOVE 410,65
PRINT "OK"
VDU 4
MOUSE x%,y%,z%
IF z%>0 THEN
CASE TRUE OF
WHEN y%>9 AND y%<31 AND x%>19 AND x%<276:b%=x%-20
WHEN y%>39 AND y%<61 AND x%>19 AND x%<276:g%=x%-20
WHEN y%>69 AND y%<91 AND x%>19 AND x%<276:r%=x%-20
WHEN y%>10 AND y%<90 AND x%>390 AND x%<470:done%=TRUE
ENDCASE
ENDIF
*REFRESH
UNTIL done%
COLOUR 7,200,200,200
*REFRESH ON
=(r%+(g%<<8)+(b%<<16))
Of course that splats a bit of the output window (though I guess you could save it to a spare bitmap if you used some SYS commands!). I'm sure you could modify it to be able to place the picker somewhere else on the screen (ideally using x,y parameters in the call).
Best wishes,
D
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #7 on: Apr 13th, 2016, 3:55pm » |
|
You should show Richard that.. Its a nice working display. A little border work and make it a pop up from a Menu and you have one of the utilities Richard needs.
You know, I have been reinventing things as my hobby..
Actually Richard is now working on new methods for the x86 platforms that don't have windows.
So he told me that the ideas I am pursuing could have a use in that project..(when they are up to standards I guess)
I will have to work hard.
So .. I do have one project that needs doing since the SYS commands will be unavailable and windows essentially will need to be reinvented to an extent. Dialogs, menus, and on and on..
The RGB COLOR MIXER program he mentions would be an asset for the new systems.. ( I would need to make it professional looking and reinvent buttons like I was doing before)
But then we are talking and I am hoping I may eventually get something made that will meet the standards for the new BBC Basic x86 platform.
|
« Last Edit: Apr 13th, 2016, 4:04pm by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #8 on: Apr 15th, 2016, 08:04am » |
|
Here's another boring colour picker,: click somewhere to call it up: you can choose a colour, and then a circle of that colour will be plotted at the same place. It (the picker) WON'T kill what was underneath!
but...
This one has some features that might be useful to people in other contexts, too. BB4W, by default, has an output bitmap much bigger than the output window: 1920 x 1440 pixels, or 3840 x 2880 graphics units. That means that there is some spare "real estate" that we can use if we have a smaller window.
To do that, we need to extend the graphics viewport with VDU 24. Having done that, we can copy/move stuff off our main window for temporary storage, and then copy it back: in this routine I "save" the material behind where my colour picker "window" is going to be, and then when I've finished, I bring it back: the two RECTANGLE FILL... TO... commands move the blocks into, and back from, storage.
Potentially, this space has other uses: you could have "alternative" screens already made up in this space, and then use RECTANGLE...TO to copy them to the main window area - a form of bank switching: that might sometimes have advantages over using *REFRESH OFF and *REFRESH - for example if you want to have 2 different views available at different times.
There are a couple of slight "catches" that caught me... well explained on the wiki (thanks, Richard...): http://bb4w.wikispaces.com/Drawing+outside+the+window
1) The main window area is in the TOP LEFT of the larger bitmap - so you can expand it to the right or down, but not up (or left). 2) The addresses start from 0, and ALL 4 points you send to VDU 24 must lie WITHIN the bitmap - so, for example Code:
VDU 24,0;0;width%-1;height%-1;
Note also the semicolons, including the one at the end. Using commas or missing out the last one is likely to lead to disaster...
Here's the colour picker in a short demo program to show its use. Click somewhere with the mouse and then choose a colour. Repeat until bored... Code:
MODE 8
GCOL 1
RECTANGLE FILL 50,50,200,200
GCOL 3
RECTANGLE FILL 200,0,600,500
REPEAT
WAIT 1
MOUSE x%,y%,z%
IF z%>0 THEN
c%=FNGetColour(x%,y%)
PRINT c%
COLOUR 7,c% AND 255,(c%>>8)AND 255,(c%>>16) AND 255
GCOL 7
CIRCLE FILL x%,y%,200
REPEAT MOUSE x%,Y%,z% UNTIL z%=0
ENDIF
UNTIL FALSE
END
:
DEFFNGetColour(px%,py%)
LOCAL x%,y%,z%,r%,g%,b%,done%
LOCAL w%,h%
done%=FALSE
*REFRESH OFF
w%=@vdu%!208*2 :REM The width of the current window in BB4W graphics units
h%=@vdu%!212*2 :REM The height of the current window in BB4W graphics units
IF w%>3839-500 THEN
SYS "MessageBox",@hwnd%,"Output window is too large: can't back up hidden section, which will be lost!"
ELSE
VDU 24,0;0;w%+500;h%-2;
RECTANGLE FILL px%,py%,500,100 TO w%,py%
ENDIF
GCOL 15
RECTANGLE px%,py%,500,100
RECTANGLE px%+4, py%+4,492,92
REPEAT
GCOL 0
RECTANGLE FILL px%+6,py%+6,488,88
GCOL 15
VDU 5
MOVE px%+8,py%+30
PRINT"B"
RECTANGLE px%+30,py%+10,255,20
MOVE px%+8,py%+60
PRINT"G"
RECTANGLE px%+30,py%+40,255,20
MOVE px%+8,py%+90
PRINT"R"
RECTANGLE px%+30,py%+70,255,20
LINE px%+30+r%,py%+70,px%+30+r%,py%+90
LINE px%+30+g%,py%+40,px%+30+g%,py%+60
LINE px%+30+b%,py%+10,px%+30+b%,py%+30
COLOUR 7,r%,g%,b%
GCOL 7
RECTANGLE FILL px%+300,py%+10,90,80
GCOL 15
RECTANGLE px%+410,py%+10,80,80
MOVE px%+430,py%+65
PRINT "OK"
VDU 4
MOUSE x%,y%,z%
IF z%>0 THEN
CASE TRUE OF
WHEN y%>py%+9 AND y%<py%+31 AND x%>px%+29 AND x%<px%+286:b%=x%-30 -px%
WHEN y%>py%+39 AND y%<py%+61 AND x%>px%+29 AND x%<px%+286:g%=x%-30-px%
WHEN y%>py%+69 AND y%<py%+91 AND x%>px%+29 AND x%<px%+286:r%=x%-30-px%
WHEN y%>py%+10 AND y%<py%+90 AND x%>px%+390 AND x%<px%+470:done%=TRUE
ENDCASE
ENDIF
*REFRESH
UNTIL done%
COLOUR 7,200,200,200
RECTANGLE FILL w%,py%,500,100 TO px%,py%
VDU 24,0;0;w%;h%-2;
*REFRESH ON
=(r%+(g%<<8)+(b%<<16))
Best wishes,
D
|
|
Logged
|
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: RGB COLOR MIXER UTILITY (Custom spheres Enhanc
« Reply #9 on: Apr 16th, 2016, 4:22pm » |
|
At the risk of boring the pants off you, here is yet another version, partly to make Richard happy.
Rather than saving the bit of window we are going to overwrite in the offscreen bit of the bitmap, this version writes it to a temporary file, restores it from there, and then deletes the file. This has some advantages: you don't need to worry about the size of the output bitmap, or the size of the screen mode. It may also work better for Richard's SDL version, where the bitmap is 1920 x 1920, but may all get used unexpectedly if the user rotates their phone!
Michael, if you are planning to write "windows" routines for Richard's SDL version, this may the way to go - though Richard tells me he is now looking at making the bitmap there bigger...
I've also corrected a couple of bugs in the previous version: it now checks that it isn't going to overrun the window (making the OK button inaccessible), and the area of the OK button checked for clicks has been corrected.
It is left as an exercise for the reader to convert it to a procedure that also takes a colour number and sets it directly... one extra parameter and one extra line of code at the end....
Best wishes,
D
Code:
MODE 8
GCOL 1
RECTANGLE FILL 50,50,200,200
GCOL 3
RECTANGLE FILL 200,0,600,500
REPEAT
WAIT 1
MOUSE x%,y%,z%
IF z%>0 THEN
c%=FNGetColour(x%,y%)
COLOUR 7,c% AND 255,(c%>>8)AND 255,(c%>>16) AND 255
GCOL 7
CIRCLE FILL x%,y%,200
REPEAT MOUSE x%,Y%,z% UNTIL z%=0
ENDIF
UNTIL FALSE
END
:
DEFFNGetColour(px%,py%)
LOCAL x%,y%,z%,r%,g%,b%,done%
LOCAL w%,h%
done%=FALSE
*REFRESH OFF
w%=@vdu%!208*2 :REM The width of the current window in BB4W graphics units
h%=@vdu%!212*2 :REM The height of the current window in BB4W graphics units
REM Make sure the picker doesn't fall off the edge of the screen, making the OK button impossible to click!
IF px%>w%-502 THEN px%=w%-502
IF py%>h%-102 THEN py%=h%-102
REM Now we'll save the area that will have the colour picker in to a temporary file
OSCLI "SCREENSAVE """+@tmp$+"tempscreenbit.bmp"+""" "+STR$(px%)+","+STR$(py%)+",502,102"
REM Clear the space to black
GCOL 0
RECTANGLE FILL px%,py%,500,100
GCOL 15
RECTANGLE px%,py%,500,100
RECTANGLE px%+4, py%+4,492,92
REPEAT
GCOL 0
RECTANGLE FILL px%+6,py%+6,488,88
GCOL 15
VDU 5
MOVE px%+8,py%+30
PRINT"B"
RECTANGLE px%+30,py%+10,255,20
MOVE px%+8,py%+60
PRINT"G"
RECTANGLE px%+30,py%+40,255,20
MOVE px%+8,py%+90
PRINT"R"
RECTANGLE px%+30,py%+70,255,20
LINE px%+30+r%,py%+70,px%+30+r%,py%+90
LINE px%+30+g%,py%+40,px%+30+g%,py%+60
LINE px%+30+b%,py%+10,px%+30+b%,py%+30
COLOUR 7,r%,g%,b%
GCOL 7
RECTANGLE FILL px%+300,py%+10,90,80
GCOL 15
RECTANGLE px%+410,py%+10,80,80
MOVE px%+430,py%+65
PRINT "OK"
VDU 4
MOUSE x%,y%,z%
IF z%>0 THEN
CASE TRUE OF
WHEN y%>py%+9 AND y%<py%+31 AND x%>px%+29 AND x%<px%+286:b%=x%-30 -px%
WHEN y%>py%+39 AND y%<py%+61 AND x%>px%+29 AND x%<px%+286:g%=x%-30-px%
WHEN y%>py%+69 AND y%<py%+91 AND x%>px%+29 AND x%<px%+286:r%=x%-30-px%
WHEN y%>py%+10 AND y%<py%+90 AND x%>px%+410 AND x%<px%+490:done%=TRUE
ENDCASE
ENDIF
*REFRESH
UNTIL done%
COLOUR 7,200,200,200
REM OK, Restore the original picture, and delete our temporary file.
OSCLI "DISPLAY """+@tmp$+"tempscreenbit.bmp"+""" "+STR$(px%)+","+STR$(py%)+",502,102"
OSCLI "DEL """+@tmp$+"tempscreenbit.bmp"+""""
*REFRESH ON
=(r%+(g%<<8)+(b%<<16))
|
|
Logged
|
|
|
|
|