
-----------------------------------
Mr. T
Sun Oct 16, 2005 3:08 pm

Random Flashing
-----------------------------------
Can anyone figure out why the screen flashes blue in these 3 scenarios:
1) Create a vertical bar (right-click) and make sure all the balls are to the left of the bar
2) Create a vertical bar and make sure that balls are on both sides of the bar
3) Create a horizontal bar (left-click) and make sure that all the balls are below the bar


View.Set ("offscreenonly")
const RADIUS : int := 5
const NUM_BALLS : int := 3
var x, y, dx, dy, clr : array 1 .. NUM_BALLS of int
var box_x1, box_x2, box_y1, box_y2 : int := 0
var barX, barY, button, left, middle, right : int
var barCreator := true
var a, b : int := 0
var c1, c2 := false
var d1, d2 := false
var drawFill := true
var topCounterx, bottomCounterx,topCountery, bottomCountery := 0



for i : 1 .. NUM_BALLS
    x (i) := Rand.Int (RADIUS, maxx - RADIUS)
    y (i) := Rand.Int (RADIUS, maxy - RADIUS)
    dx (i) := Rand.Int (-5, 5)
    dy (i) := Rand.Int (-5, 5)
    clr (i) := Rand.Int (1, 15)
end for

loop
%Frame
Draw.Box (0,0,maxx,maxy,blue)

    %Outer Boundary Collision
    for i : 1 .. NUM_BALLS
        if x (i) + dx (i) < RADIUS or
                x (i) + dx (i) > maxx - RADIUS then
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < RADIUS or
                y (i) + dy (i) > maxy - RADIUS then
            dy (i) := -dy (i)
        end if

        %Incompleted Wall Collision
        if whatdotcolour (x (i), y (i)) = red or whatdotcolour (x (i), y (i)) = green then
            return
        end if

        %Completed Wall Collision
        if x (i) + dx (i) >= box_x1 and x (i) + dx (i) = box_y1 and y (i) + dy (i) = maxx then
            Draw.FillBox (box_x1 + a, box_y1, box_x2, box_y2, blue)
        else
            Draw.FillBox (box_x1 + a, box_y1, box_x2, box_y2, red)
        end if
    end if

    if d1 = true then
        if box_x1 - b = maxx and box_x1 - b  box_y2 then
                topCountery += 1
            elsif y (i) < box_y1 then
                bottomCountery += 1
            end if
        end for

        if topCountery >= 1 and bottomCountery >= 1 then
            drawFill := false
            else
            drawFill:=true
        end if

        if drawFill = true then
            for i : 1 .. NUM_BALLS
                if y (i) >= box_y1 then
                   Draw.Fill (box_x1,box_y1-1,blue, blue)
                elsif drawFill = true and y (i) = maxy then
            Draw.FillBox (box_x1, box_y1 + a, box_x2, box_y2, blue)
        else
            Draw.FillBox (box_x1, box_y1 + a, box_x2, box_y2, red)
        end if
    end if

    if d2 = true then
        if box_y1 - b = maxx and box_y1 - b  box_x2 then
                topCounterx += 1
            elsif x (i) < box_x1 then
                bottomCounterx += 1
            end if
        end for

        if topCounterx >= 1 and bottomCounterx >= 1 then
            drawFill := false
            else
            drawFill:=true
        end if

        if drawFill = true then
            for i : 1 .. NUM_BALLS
                if x (i) >= box_x1 then
                    Draw.Fill (box_x1-1,box_y1,blue, blue)
                elsif x (i) 