
-----------------------------------
Jekate
Wed Oct 26, 2005 7:58 pm

RGB Colours.
-----------------------------------
I know there are already threads on RGB colours but there is something that is really bugging me. I've looked over this many times and so have my friends but we can't figure it out. Here is the code : 



var col1 : real
var colchange : int

col1 := 0

loop
    if col1 = 1 then
        colchange := 1
    elsif col1 = 0 then
        colchange := 0
    end if
    if colchange = 1 then
        col1 := col1 - 0.01
    elsif colchange = 0 then
        col1 := col1 + 0.01
    end if
    RGB.SetColor (1, col1, 0, 0)
    drawfillbox (0, 0, 100, 100, 1)
    delay (10)
end loop




The program is suppose to draw the box so it turns from black to red slowly. It does that properly but then it is suppose to do the same back to black.

It is probably some stupid mistake. Thnx.

-----------------------------------
beard0
Wed Oct 26, 2005 8:25 pm


-----------------------------------
I have not fixed your code, but simply added two lines that will show you what your problem is so that you can fix your code yourself.  The technique I have used here is a very useful one that you should start using yourself to debug your programs.

var col1 : real
var colchange : int

col1 := 0

loop
    if col1 = 1 then
        colchange := 1
    elsif col1 = 0 then
        colchange := 0
    end if
    if colchange = 1 then
        col1 := col1 - 0.01
    elsif colchange = 0 then
        col1 := col1 + 0.01
    end if
    RGB.SetColor (1, col1, 0, 0)
    drawfillbox (0, 0, 100, 100, 1)
    delay (10)
    locate (1, 1)                    %My debugger
    put "col1: ", col1               %   lines
end loop

-----------------------------------
Jekate
Wed Oct 26, 2005 8:33 pm


-----------------------------------
I get what your showing but the program still isn't working as it should. I have:


if col1 = 1 then
colchange := 1
end if


and then


if colchange = 1 then
col := col - 0.01
end if


This should make col1 decrease once it reaches 1 but it is not for some reason. I think that it is skipping 1 for unknown causes. I fixed the program though by adding >= and = 1 then
        colchange := 1
    elsif col1 