Given T= {(x1, y1, 0), (x2, y2, 0), (x3, y3, 0)
- Pick an initial point p = (x,y,0) inside of the triangle
- count = 0
- While count < LIMIT
- Select one of the three vertices at random, v.
- Find point q halfway between p and v.
- Display a pixel at q
- q = p
- count++
function serpinski() { initialize_the_system(); p = find_initial_point(); for(i=0;i<LIMIT;i++) { q = generate_a_point(p); display_the_point(q); p = q; } }
function serpinski() { initialize_the_system(); p = find_initial_point(); for(i=0;i<LIMIT;i++) { q = generate_a_point(p); store_the_point(q); p = q; } display_all_points(); }
function serpinski() { initialize_the_system(); p = find_initial_point(); for(i=0;i<LIMIT;i++) { q = generate_a_point(p); store_the_point(q); p = q; } TransferPontsToGPU(); DisplayOnGPU();
var p1 = [this.width/2.0, 20]; var p2 = [20, this.height-20]; var p3 = [this.width-20, this.height-20]; this.tri = [p1, p2, p3]
Interp: function(a,b,s) { return a*s + b*(1-s); },
HalfPoint: function(p1,p2) { var x = this.Interp(p1[0],p2[0],.5); var y = this.Interp(p1[1],p2[1],.5); return [x,y]; },
RandPoint: function(p1, p2) { var s = Math.random(); var x = this.Interp(p1[0],p2[0],s); var y = this.Interp(p1[1],p2[1],s); return [x,y]; },
Redisplay: function() { this.Clear(); var p, q, v; this.ctx.fillStyle = this.color; var t1 = this.RandPoint(this.tri[0], this.tri[1]); p = this.RandPoint(t1, this.tri[2]); for (var i=0; i<this.count; i++) { var c = Math.floor(Math.random()*3); v = this.tri[c] q = this.HalfPoint(p,v); this.ctx.fillRect(q[0],q[1],2,2); p = q; } return; }
var p, q, v; var t1 = this.RandPoint(this.tri[0], this.tri[1]); p = this.RandPoint(t1, this.tri[2]); this.list= []; for (var i=0; i<this.count; i++) { var c = Math.floor(Math.random()*3); v = this.tri[c] q = this.HalfPoint(p,v); this.list.push(q); p = q; } return; },