coda
Junior Member
Posts: 65
|
Post by coda on Apr 5, 2022 3:15:04 GMT -5
I'm sorry for asking so many questions lately. I feel like a nuisance. :/ I know very well how to use variables with graphics commands to set certain parameters such as the following: #handle, "color ";Mycolour$(1)
#handle, "backcolour ";Mycolour$(2)
#handle, "place X Y"
But... is there a way to query these currently set values and STORE them in variables? For example can I retrieve the current foreground and background colours and store them in either Mycolour$(c) or MyRed, MyGreen, MyBlue somehow, instead of the other way around. Likewise, can I retrieve the current pen position and STORE it in X and Y? I know it may not be immediately obvious why I want to do that as I, as the programmer, am the one who set them in the first place and therefore should KNOW what they are but I have some large complicated loops in which the current positions and colours are continually updated and which are dependent on various user settings. In these loops, it would, at certain points, simplify programming greatly if instead of trying to keep track of all the possibilities by hand at any point in the loop, I could simply query and retrieve the current color, backcolor and pen position. Any help greatly appreciated.
|
|
|
Post by Rod on Apr 5, 2022 4:48:48 GMT -5
You can get the current pen xy with this command
print #handle, "posxy xVar yVar" This command assigns the pen's current position to xVar & yVar. The background and foreground colors can be saved and filled simply by using them as ordinary variables.
c$=systemvariable$ (background color/foreground color) systemvariable$=c$
But this is probably not necessary as the color will always be whatever you set last. Perhaps you wanted to know the color of the pixel you are on?
|
|
|
Post by tsh73 on Apr 5, 2022 6:15:00 GMT -5
There is a trick for getting angle. It looks I never needed it though.
' reading Turtle turn angle ' demo by tsh73, Sept 2010 ' Idea was suggested by uncleBen
nomainwin
WindowWidth = 552 WindowHeight = 430
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "push me", [button1Click], UL, 406, 16, 122, 25 open "determining drawing turtle angle - demo" for graphics_nsb_nf as #main print #main, "down; fill white; flush" print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" #main.button1, "!setfocus"
'now, print some description here print #main, "place 20, 20" print #main, "\As you know, you can read up your turtle position" print #main, "\with POSXY command." print #main, "\However, there are no command to read turtle ANGLE." print #main, "\BUT." print #main, "\It could be computed." print #main, "\" print #main, "\This demo draws 5 randomly rotated segments" print #main, "\(four blue, last one made green)" print #main, "\then computes angle which turtle ended with" print #main, "\then draws red line from center point, with same angle." print #main, "\" print #main, "\We need function ATAN2() (or the like) for it."
wait
[quit.main] Close #main END
[button1Click] #main, "cls; home" #main, "size 2; color blue" 'five segments by length 50 length = 50 pi = acs(-1) deg2rad = pi/180 rad2deg = 1/deg2rad
for i = 1 to 5 'random angle, +/-180 degrees angle = int(rnd(1)*360)-180 #main, "turn ";angle if i = 5 then #main, "color green" #main, "go ";length timer 100, [another] wait [another] timer 0 next
'>>>>>>>> now, determine turtle angle #main, "posxy x0 y0" #main, "up" #main, "go 1000" 'probably well offscreen, doesn't matter #main, "posxy x1 y1" 'now, at least we should put pen down 'but we also could restore previous point ' #main, "go -1000" 'is the easiest way #main, "down" angle = arctan2(0-(y1-y0),x1-x0) *rad2deg '>>>>>>> here we got our angle. You sure can compress it in less lines #main, "home; north" #main, "turn ";angle #main, "color red" #main, "go ";150 #main "flush" #main.button1, "try again" wait
'by nukesrus21, returns -Pi..Pi as C standard library version (though in C it's atan2(y,x) - note argument order) Function arctan2(x, y) On Error GoTo [Error] 'For the first 0, 0 to prevent divide by zero error arctan2 = (2 * (atn((sqr((x * x) + (y * y)) - x)/ y))) [Error] End Function
|
|
|
Post by tsh73 on Apr 5, 2022 6:17:07 GMT -5
drawing a pixel in obscure point(corner pixel?) then reading color might go for getting colors.
|
|
coda
Junior Member
Posts: 65
|
Post by coda on Apr 5, 2022 9:01:51 GMT -5
Yes, you are right. That is documented in the manual. I just didn't remember it or see it for some reason. Sorry. So, do the System Variables BackgroundColor$ and ForegroundColor$ hold values set by the following commands too, do they? #handle, "color ";Mycolour$(1) #handle, "backcolour ";Mycolour$(2) I thought these were different variables specific to the GUI. No, I know how to get the colour of a pixel. I was just wondering if there was either a system variable for graphicbox/window fore/background colour or else a command to query them in LB. The problem with knowing what the current foreground/background colour is, is that I, as the programmer, cannot know what colour was last set, if the setting of that colour is dependent on several prior and disconnected actions taken by the user at run time and the interaction of those actions with the result of several calculations which are unknowable before the program is run. Programming becomes very abstract at times but I don't have to tell you guys that. Because I don't know, therefore, my loop doesn't know this info when it is invoked. The only 2 ways around this would be 1. Set a variable of my own every time the background or foreground colour was potentially set by the program (which I didn't do because I didn't know I couldn't poll LB for the answer)... lol or 2. Poll LB for the answer which it looks like I can't do... which is why I'm asking. I am hoping not to have to go back and use method 1. I shall file this away for future reference tsh73. Thankyou.
|
|
|
Post by Walt Decker on Apr 5, 2022 9:27:58 GMT -5
There are several ways to do it. Without much thought three spring to mind:
1. When the user performs an action that will change the graphic write the new foreground color(text color/line color) and fill color(background) to a file,
2. Set control properties using User32.dll function SetPropA(), and retrieve the colors with GetPropA()
3. Set the colors in a 2 dimensional array and retrieve them from the array.
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Apr 5, 2022 9:28:40 GMT -5
I would set up Globals SaveForeColor$, SaveBackColor$ then funnel all color changes through 2 subs:
Sub ChangeFore color$ SaveForeColor$ = color$ #win "Color ";color$ end sub
Sub ChangeBack color$ SaveBackColor$ = color$ #win "BackColor ";color$ end sub
Now if you need the current color just ask SaveForeColor$ or SaveBackColor$.
|
|
|
Post by Rod on Apr 5, 2022 9:29:09 GMT -5
I think it is as simple as using a single variable to set the color. That variable will always contain the current pen color.
|
|
coda
Junior Member
Posts: 65
|
Post by coda on Apr 5, 2022 11:41:23 GMT -5
You are quite right, Rod. Unfortunately, because I wasn't aware that I couldn't just poll LB for the answer when I started writing the program many moons ago (or that I would even need to), values are set in some places by variables but in many places by literals which can overwrite the last set value being remembered by the variable, often hundreds of times in nested loops without knowing beforehand which will be triggered at each each point in the loop, the literals or one of the the variables. So, I have two choices: 1. Reprogram... a lot 2. Find out if I can obtain the value from LB (hence my question)... Good idea. If only I had known I would need to do that when I started writing...lol
|
|
|
Post by Rod on Apr 5, 2022 12:12:35 GMT -5
Well reprogramming is inevitable. So reprogram to use specific variable each time or reprogram to find the color. In any event you will find the search and replace function in the IDE invaluable. Used correctly you can transform code in the blink of an eye if you choose the correct search fragment and the correct replace fragment.
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Apr 5, 2022 12:45:58 GMT -5
Well reprogramming is inevitable. So reprogram to use specific variable each time or reprogram to find the color. In any event you will find the search and replace function in the IDE invaluable. Used correctly you can transform code in the blink of an eye if you choose the correct search fragment and the correct replace fragment. There's a veteran talking! +1 Thank goodness for search and change!
|
|