Notifications
Clear all

[Closed] checker based geometry

 rdg

Hi,

I’d like to share a snippet:
It generates black and white sphere based on a checker algorithm [1].
Well, there are some inconsistencies like the offset and – probably – rounding errors or conceputal flaws in my iplementation but it produces funny patterns.
As long as you don’t need a generic checker.

You can change the frequency and the segcount to get different results.

(
	-- Georg Duemlein
	--  http://www.preset.de/ 
	-- ---
	frequency = 4
	-- ---
	segCount = 15
	thePlane = plane()
	thePlane.width = thePlane.length = 200
	thePlane.widthsegs = thePlane.lengthsegs = segCount
	segHalf = segCount as float / 2
	-- ---
	theSphere = sphere()
	theSphere.radius = 10

	-- ---
	
	-- ---
	convertToPoly thePlane
	
	-- randFace = random 1 thePlane.numfaces
	
	for y = 1 to segCount do (
		for x = 1 to segCount do (
			xval = 1. / segCount * x 
			yval = 1. / segCount * y
			xmod = mod (xval * frequency) 1
			ymod = mod (yval * frequency) 1		
			currFace = segCount * (y - 1) + x
			faceCenter = polyop.getFaceCenter thePlane currFace
			if xmod < .5 then (
				if ymod < .5 then (
					tempSphere = reference theSphere
					tempSphere.pos = faceCenter 
					tempSphere.wirecolor = white
				)else(
					tempSphere = reference theSphere
					tempSphere.pos = faceCenter
					tempSphere.wirecolor = black
				)
			)else(
				if ymod < .5 then (
					tempSphere = reference theSphere
					tempSphere.pos = faceCenter 
					tempSphere.wirecolor = black
				)else(
					tempSphere = reference theSphere
					tempSphere.pos = faceCenter 
					tempSphere.wirecolor = white
				)
			)
		)
	)
	delete theSphere
	delete thePlane
)

Georg

[1] http://www.renderman.org/RMR/Shaders/RCShaders/checker.sl