rect border bug?

not sure if it’s a bug or I’m doing something wrong, but the following doesn’t draw the right side of the border

function draw()
    background(0, 0, 0)
    noSmooth()
    fill(255,255,255,255)
    stroke(0,0,255,255)
    strokeWidth(1)
    rect(300,300,200,200)
end

If you make fill() and background() both the same color you can see it.

I think the white is just too bright to see the border

Maybe it has to do with the whitest white having a bit of blue in it

http://www.mrsstewart.com/pages/purpose.htm

note a green line is visible

Seems to be drawing for me. It’s just hard to see on the black background. If you take a screenshot and zoom in, it’s there.

you’re right it’s there if I zoom in

I think I found something or I’m not understanding the math.

It may be an issue only with rect() or sprite() w/image used at scale()

Sorry for the long example, sort of in the middle of something

The sprite seems a bit to thin on the right as compared to the border.


--living images
function setup()
    it = {} -- image table
    ni = 10 -- number images/knights who say ni
    scl = 10
    for i = 1, ni do
        local x = (math.random(WIDTH - (WIDTH/10)) + WIDTH/20) / scl
        local y = (math.random(HEIGHT - (HEIGHT/10)) + HEIGHT/20) / scl
        local h = 2
        local w = 2
        it[i] = Lim(x,y,w,h)
        it[i]:rand()  
    end
end

function draw()
    background(0, 0, 0)
    scale(scl)
    noSmooth()
    for i = 1, ni do
        it[i]:draw()
    end
end

Lim = class()

function Lim:init(x,y,w,h)
    self.x = x
    self.y = y
    self.w = w
    self.h = h
    self.im = image(w,h)
end

function Lim:rand()
    local i
    local j
    for i = 1, self.w do
        for j = 1, self.h do
            local r = math.random(256)-1
            local g = math.random(256)-1
            local b = math.random(256)-1
            local a = math.random(256)-1
            self.im:set(i,j,r,g,b,a)
        end
    end   
end

function Lim:draw()
    spriteMode(CORNER)
    sprite(self.im,self.x,self.y)
    strokeWidth(1)
    stroke(127, 127, 127, 255)
    noFill()
    rectMode(CORNER)
    --rect(self.x-.9,self.y-.9,self.w+1.8,self.h+1.8)
    rect(self.x-1,self.y-1,self.w+2,self.h+2)
end

@ruilov - is ist solved now? If this Happens to me its always the rectmode. The difference between CORNER and CORNERS might be your mistake too - because the width and height are smaller than 0 then :slight_smile:

Maxiking16, there was no issue for me. It’s just that the white seems to overpower the border on the screen sometimes

ipda41001, you need to do math.floor on those x,y variables. The type of thing you get when int/float are interchangeable

Thx