@Dwins @dave1707 is right to suggest rawGet / rawSet
The image is different on your iPad mini / iPad Air because you are rendering (and subsequently analysing) fewer pixels on the mini. If you want to analyse all pixels on both devices. Then you can use the following code:
(This will produce a higher fidelity, but still pixellated, circle on the iPad Air.)
function setup()
size = 7
img = image(size,size)
setContext(img)
noSmooth()
ellipse(size/2,size/2,size)
setContext()
-- The raw size on non-retina devices will
-- be the same as the size
local rawSize = size * ContentScaleFactor
for i = 1,rawSize do
for j = 1,rawSize do
r,g,b,a = img:rawGet(i,j)
if a > 0 then
img:rawSet(i,j,color(255))
end
end
end
end
function draw()
background(40, 40, 50)
strokeWidth(5)
sprite(img,WIDTH/2,HEIGHT/2,size*32)
end
There is a global variable called ContentScaleFactor
. On a non-retina display, this will be 1
where on a retina display it will be 2
(or 3
for iPhone 6+).
I expect you want the same result (same number of pixels) on both devices. In that case we need to start with an image size that is evenly divisible by all our possible scale factors, the closest one we have is 12
(divisible by 2 and 3).
function setup()
size = 12.0 -- Divisble by 2 and 3
-- Divide the size by the content scale factor
-- This means our image will be:
-- 12 points, 12 pixels on non-retina
-- 6 points, 12 pixels on 2x retina
-- 4 points, 12 pixels on 3x retina
local imgSize = size / ContentScaleFactor
-- Create an image with the same number of pixels
-- regardless of device screen density
img = image(imgSize,imgSize)
setContext(img)
noSmooth()
ellipse(imgSize/2,imgSize/2,imgSize)
setContext()
-- The raw size is just the undivided size
local rawSize = size
for i = 1,rawSize do
for j = 1,rawSize do
r,g,b,a = img:rawGet(i,j)
if a > 0 then
img:rawSet(i,j,color(255))
end
end
end
end
function draw()
background(40, 40, 50)
strokeWidth(5)
sprite(img,WIDTH/2,HEIGHT/2,size*32)
end