# HALTON SEQUENCE

Returns an array with a desired number of seemingly random and evenly distributed points on the plane. Points are distributed inside whatever object is passed to the function. Should no object be provided the points are spread over the active artboard. Create a Halton Sequence with the line:

var halton = new Halton(2, 3)

Numbers 2 and 3 are the primes that usually works best and produces best results. Try with non-primes and the outcome is VERY (to me anyway) surprising.

Generate *n* points inside object using:

halton.getPoints(object, n)

Note that point locations are in no way, shape or form random and will always yield the same result. To avoid repeat patterns an offset can be passed along in the .getPoints() method as such:

halton.getPoints(object, n, offset)

This number however, should be at least as high as your running total of points.

More on the Halton Sequence in this Wikipedia article.

var Halton = function(baseX, baseY){ this.x = baseX this.y = baseY this.getPoints = function(obj, count, offset){ var points = [], objekt = obj ? obj : document.activeArtboard size = objekt.bounds.size pointOffset = objekt.bounds.topLeft for(var i = 0 + offset; i < count + offset; i++){ var point = new Point(this.halton(i, this.x), this.halton(i, this.y)) * size + pointOffset if(obj){ if(objekt.contains(point)){ points.push(point) } } else { points.push(point) } } return points } this.halton = function(index, base){ var result = 0, f = 1 / base, i = index while(i > 0){ result = result + f * (i % base) i = Math.floor(i / base) f = f / base } return result } }

Back to Scripts