color mix question

I am trying to write a fairly simple program that will present a square and a line on the screen, but the color of the square and line will randomly change between presentations (between three different variations of gray). I know enough about TB to get myself in trouble, but not to fix this program. If anyone can help me, I would appreciate it greatly!!!

Right now, I have the color changing, but there are times that the square does not appear with the line or they are two different colors. I need the square that is associated with each case to be the color I have designated for the research that I am doing (I would also like the line to be the same color as the square for each case).

Thanks in advance!

Below is the program that is sort of working. :) (I hope this is okay)

DIM URN(72),NRAND(72)

REM ILM 79 prac trials

SET WINDOW 0,1024,0,748

set COLOR mix(0) 0,0,0
SET BACKGROUND color 0
rem background color is black

SET COLOR MIX(1) 1,1,1
SET COLOR 1

PRINT " "
PRINT "Please wait for a few moments..."

REM RANDOM NUMBER GENERATOR
RANDOMIZE
LET NURN=72
FOR I=1 TO 72
LET URN(I)=I
NEXT I

FOR J=1 TO 72
DO
LET IRAND=INT(RND*NURN+1)
IF IRAND<=NURN THEN EXIT DO
LOOP
LET K=0
LET NRAND(J)=URN(IRAND)
LET NURN=NURN-1
FOR I2=1 TO NURN
IF I2=IRAND THEN LET K=1
LET URN(I2)=URN(I2+K)
NEXT I2
NEXT J
REM END RANDOM NUMBER GENERATOR

CLEAR
REM MAIN EXPERIMENT BEGINS
FOR TRIAL=1 TO 10
plot lines: 502,254;522,254
plot lines: 512,244;512,264

LET Q=NRAND(TRIAL)
LET COND=MOD(Q,18)
IF COND=0 THEN LET COND=18
IF MOD(TRIAL,2)=1 THEN
PRINT "Please press the h-key for trial ";trial
DO
GET KEY PRESS
IF PRESS=ORD("h") THEN EXIT DO
LOOP
ELSE
PRINT "Please press the k-key for trial ";trial
DO
GET KEY PRESS
IF PRESS=ORD("k") THEN EXIT DO
LOOP
END IF
CLEAR

PAUSE .25

SELECT CASE COND
CASE 1,7,13
set color mix(.85).85,.85,.85
SET COLOR .85
LET X=200
LET Y=200
BOX AREA X,X+20,Y,Y+20
BOX KEEP X,X+20,Y,Y+20 IN CUE1$
CLEAR
BOX SHOW CUE1$ AT 374,398
CASE 2,8,14
set color mix(.85).85,.85,.85
SET COLOR .85
LET X=200
LET Y=200
BOX AREA X,X+20,Y,Y+20
BOX KEEP X,X+20,Y,Y+20 IN CUE1$
CLEAR

BOX SHOW CUE1$ AT 630,398
CASE 3,9,15
set color mix(.5).5,.5,.5
SET COLOR .5
LET X=200
LET Y=200
BOX AREA X,X+20,Y,Y+20
BOX KEEP X,X+20,Y,Y+20 IN CUE1$
CLEAR

BOX SHOW CUE1$ AT 374,398
CASE 4,10,16
set color mix(.5).5,.5,.5
SET COLOR .5
LET X=200
LET Y=200
BOX AREA X,X+20,Y,Y+20
BOX KEEP X,X+20,Y,Y+20 IN CUE1$
CLEAR

BOX SHOW CUE1$ AT 630,398
CASE 5,11,17
set color mix(.15).15,.15,.15
SET COLOR .15
LET X=200
LET Y=200
BOX AREA X,X+20,Y,Y+20
BOX KEEP X,X+20,Y,Y+20 IN CUE1$
CLEAR

BOX SHOW CUE1$ AT 374,398
CASE 6,12,18
set color mix(.15).15,.15,.15
SET COLOR .15
LET X=200
LET Y=200
BOX AREA X,X+20,Y,Y+20
BOX KEEP X,X+20,Y,Y+20 IN CUE1$
CLEAR

BOX SHOW CUE1$ AT 630,398
END SELECT
SET COLOR 1

SELECT CASE COND
CASE 1,2,3,4,5,6
PAUSE .05
CASE 7,8,9,10,11,12
PAUSE .25
CASE 13,14,15,16,17,18
PAUSE .45
END SELECT

LET X=200
LET Y=200
BOX AREA X,X+196,Y,Y+20
BOX KEEP X,X+196,Y,Y+20 IN LINE1$
CLEAR

BOX SHOW LINE1$ AT 414,398
PAUSE .25
CLEAR
Pause .25

PRINT "Please rate the velocity at which the line expanded on a 1-7 scale"
PRINT "[where 1 is 'very slow' and 7 is 'very fast']"

SELECT CASE COND
CASE 1
INPUT change1
CASE 2
INPUT change2
CASE 3
INPUT change3
CASE 4
INPUT change4
CASE 5
INPUT change5
CASE 6
INPUT change6
CASE 7
INPUT change7
CASE 8
INPUT change8
CASE 9
INPUT change9
CASE 10
INPUT change10
CASE 11
INPUT change11
CASE 12
INPUT change12
CASE 13
INPUT change13
CASE 14
INPUT change14
CASE 15
INPUT change15
CASE 16
INPUT change16
CASE 17
INPUT change17
CASE 18
INPUT change18
END SELECT

CLEAR
NEXT TRIAL

PRINT "That's all of the practice trials. Please summon the experimenter."

PRINT "Press 't' to exit program"
DO
GET KEY PRESS
IF PRESS=ORD("t") then exit do
LOOP

end

Comments

Color Program

Hi,

Mike is absolutely correct about defining all the colors you intend to use at the start. Rik is also correct about color reference numbers being integers.

I am sure we can all help you develop a program that runs properly, but we need to understand exactly what you want the program to do. For example, you mention that you want to display a square with a line across it. Is the line north-south or east-west, or is it diagonal? How big do you want the squares and how wide is the line? From your code, I see no indication what sort of units you are using - are they pixels or user units, i.e. 0 to 1?

Personally I prefer to use pixels units, but others may prefer user units. Setting x=200 and y=200 suggests you are using pixel units, in which case you need a statement such as:
ASK PIXELS xpix,ypix
SET WINDOW 0,xpix-1,ypix-1,0

The above definition will mean the origin is top left so the x-axis runs from left to right, and the y-axis runs from top to bottom. If you do not specify pixel units in this way, then TrueBASIC will default to user units, in which case many of your plots are off screen!

Do you require only one square on the screen at any one time?

Regards
Big John

Color Mix question

Here's what I usually do:
Define all the colors [i.e., SET COLOR MIX (integer xxx) r,g,b] at the beginning of the program .

If you want, you may name them with descriptive names, or just use some unique integer as a color number.

They may be made PUBLIC so they can be accessed elsewhere by "DECLARE PUBLIC" statements. You do not have to keep SETting COLOR MIX (xxx) each time you want to use that color. Just use the SET COLOR command.

! Colors: [here all colors to be used are defined] ---------
option nolet ! or else use LET
PUBLIC Gcolor, Lcolor, DkGrn, Orange, LtGray
SET COLOR MIX (22) 1,1,1 ! white
SET COLOR MIX (33) 0,0,0 ! black
SET COLOR MIX (100) 230/255,125/255,0/255 ! Orange
SET COLOR MIX (101) 230/255,230/255,230/255 ! light gray
SET COLOR MIX (99) 130/255,120/255,106/255 ! dark green
LtGray=(101) ! optional color names. You can use SET COLOR (101) or SET COLOR LtGray
Orange=(100)
DkGrn= (99)
Lcolor=6 ! a standard color number
Gcolor=4 ! " (red)
! ---------
... then later in the code when you want the color, use:
SET COLOR (100)
...
SET COLOR Orange
... etc.

Or if in an external SUB, use:
DECLARE PUBLIC Gcolor, LtGray, ... as needed
...
SET COLOR Gcolor
...
SET COLOR LtGray
etc.

Hope this helps.
Mike C.

Mike, Thank you so much for

Mike,

Thank you so much for responding to my question. I apologize for the tardiness of my response, but work was really crazy for a while and I just recently had a chance to try and implement your suggestions.

I still could not get my program to work with your changes. At most, the color of the instructions changed from trial to trial, but the square and the block line remained stubbornly white...and these are the two stimuli that have to change color. Also, I tried to use the DECLARE PUBLIC statement, but it kept telling me I had an undefined public variable...when I went to define it, it told me that I could not redefine the variable. I am so confused.

Any clarification you can give me to get this program to do what I need it to do would be greatly appreciated!!!

Thanks! Susan

color mix problem, et. al.

Susan, I have now fixed all of the problems, and have some notes and hints about what went wrong. Too much to post here so email me and I will send the file and notes.

Your Random Number Generator had me stumped until I realized that it is a shuffler or scrambler and not actually a RNG. The numbers in the NRAND() are just serial numbers rearranged in random order.

Presumably you wanted to record the subject's speed perception responses, but there was nothing in your code to do that. So I added a SUB to record them. You can modify it to deal with the recorded data to suit your needs.

Regards, Mike C.

color mix problem, et. al.

Susan,
(1) The Random Number Generator is grossly un-random. Just after the line: "End of RANDOM NUMBER GENERATOR", Add the lines:

MAT PRINT URN ! this will list the numbers in urn().
STOP

Run the program over and over and you will see that these are NOT very random numbers. Are these sequences what you wanted?

If you really wanted "pseudo-random" numbers (which is the ONLY thing computers can produce), then that's what the RND function itself does. However even those are not very "random" either, and better algorithms exist which give much better "uniform random" results.

For instance, the built-in RND function is NOT very good for Monte Carlo simulations and absolutely UNFIT for serious encryption work.
If you want a better algorithm I can email you one.

(2) The last SELECT CASE COND has 18 cases and 18 variables change1, change2,... are input. But then
there is never any use made of these 18 variables. What are those for?
Rather than clutter up the TB Forum perhaps we can discuss the whole thing in more detail better by email.

(3) I haven't tackled the color problem yet, but it doesn't look to be much of a problem to fix.
Regards, Mike C.

Deleted: this was a duplicate post. sorry 'bout that

deleted

color mix problem, et al...

Susan, I will look at your code to see if I can tell what's wrong, but first have to figure out what is supposed to be happening.

In the meantime, you might check on the following:

(1) "Undefined Public variable" means: Down in some SUB you have "DECLAREd PUBLIC" some variable which had not been made "PUBLIC" at the outset:
!-----------------
!...(up at beginning of main program)
PUBLIC x1,x2,x3$ ! say these are your variables;
! the PUBLIC statement just announces that "everybody" gets
! to know and use these variables. Now you must give them
! some initial value: (or they will be=0 or "" by default)
LET x1=43.9
LET x2=0
LET x3$="xxx" ! etc
!...
CALL FirstSub
! upon return here, x1,x2,x3$ have been used/acted upon by FirstSub.
!...
END ! of this little demo program: EXTERNAL SUBS follow:

SUB FirstSub
DECLARE PUBLIC x1,x2,x3$ ! now the SUB is aware of these
!...do whatever the sub does to/with these variables...
END SUB
!-----------------

(2) Similarly with the SET COLOR stuff. Also note that once the color is SET, it stays set until another SET COLOR statement is encountered. What I do if a SUB is going to change a color, but the color needs to be reset to what it was before, is to do this:

SUB blah(u,v)
DECLARE PUBLIC DarkGreen ! Previously defined color (see my other post.)
ASK COLOR wascolor ! this finds out what the color was upon entering the sub.
SET COLOR DarkGreen ! color we want for the moment.
!...do whatever the sub calls for...
SET COLOR wascolor ! now the color is restored to whatever it was before the call to this sub.
END SUB

I hope this helps; meanwhile will look at your code.
Regards, Mike

re: color mix

I haven't run this but I'm immediately drawn to your later color mix statements. I've never encournter a color designation that wasn't an integer. That is, if you are using a pallette of 256 colors, they will be numbered 0-255. So I'm not sure what SET COLOR MIX (.15) .15,.15,.15 would actually do. It might assign a color designation to '.15' or may reset color 0. Don't have the time or will to experiment, but you might try using integer designations for your colors.

I have a 256 color pallette (actually a couple of these) that I always load at the start of my programs. The stored values of rr,gg,bb are between 0-1, but as you can see, the actual color numbers run 1 to 255.

SET MODE "color256"
OPEN #1:name "new256.pal",ACCESS INPUT
MAT READ #1:rr
MAT READ #1:gg
MAT READ #1:bb
CLOSE #1
FOR n = 1 to 255
SET COLOR MIX(n) rr(n),gg(n),bb(n)
NEXT n

So again, without looking at your program in detail, I'd start by using integer color numbers.