Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Is there any way at all that I could make a checkerboard fill for a circle?

edited July 2014 in General Posts: 134

I made a very complex formula, connecting opposite sin,cos points on a circle but it takes up a lot of memory/space..could someone post a more efficient way of doing this if there is one? Thank you guys ^.^

Is there also any way to make the lines curve so the ball appears slightly 3 dimensional?

Tagged:

• Posts: 1,595

@Invad3rZIM There's definitely something of the sort on this forum, go digging in the search engine. Either way I don't think it will be fast with 3 dimensions unless you want to fake a third dimension using a shader (you'll need a shader either way unless you uv map the 3D mesh with a fit for size checker texture),

• Mod
edited July 2014 Posts: 5,396

@Invad3rZIM - The secret is to fake it. Try this.

``````function setup()
setupSphere()
end

function setupSphere()
--set up checkerboard pattern
w,n=400,5 --size of image and number of squares
img=image(w,w)
setContext(img)
background(0)
fill(255)
a=w/n
for i=1,n do
for j=1,n do
if (i+j)%2==0 then rect((i-1)*a,(j-1)*a,a,a) end
end
end
setContext()
m=mesh()
m:addRect(WIDTH/2,HEIGHT/2,w,w)   --add a rectangle to our mesh, the size you want (square)
m.texture=img
m:setColors(color(255))
end

function draw()
background(40, 40, 50)
m.shader.time=ElapsedTime/20 --vary the time speed to change the rotation speed of the sphere
m:draw()
end

uniform mat4 modelViewProjection;

attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;

varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
varying vec4 vPosition;

void main()
{
vColor=color;
vTexCoord = texCoord;
vPosition=position;
gl_Position = modelViewProjection * position;
}

]],

precision highp float;

uniform lowp sampler2D texture;
uniform float time;
uniform float fraction;

varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
varying vec4 vPosition;

void main()
{
//vec2 tc = vTexCoord.xy;
vec2 p = -1.0 + 2.0 * vTexCoord;
float r = dot(p,p);
float f = 0.5*(1.0-sqrt(1.0-r))/r;
vec2 uv;
uv.x = fraction+p.x*f + time;
uv.y = fraction+p.y*f + time;
vec4 c = texture2D( texture, vec2(mod(uv.x,1.0), mod(uv.y,1.0)));
gl_FragColor = vec4(c.xyz, 1.0);
}

]]}
``````
• Mod
Posts: 8,396

@Ignatz Nice job. I made this change, looks great.

``````    w,n=WIDTH,50 --size of image and number of squares
``````
• Mod
Posts: 5,396

@dave1707 - I found the code a while back on the net, it's very neat

• Posts: 134

So I need to learn shaders and meshes

• Mod
Posts: 3,295

very nice.

• Mod
Posts: 5,396