User:Edouard

From POV-Wiki
Jump to navigation Jump to search

Working Material for a page about Halton Sequences in POV-Ray

Halton Sequence

// Macros
#macro halton( index, base )
	#local out = 0.0;
	#local fraction = 1.0 / base;
	#local i = index;
	#while( i > 0 )
		#local remainder = mod( i, base );
		#local out = out + (fraction * remainder);
		#local i = int(i / base);
		#local fraction = fraction / base;
	#end
	out
#end

#declare halton2D_current = 0;
#declare halton2D_seed = seed( 1 );
#macro halton2DGenerator( baseX, baseY, offsetX, offsetY, scaleX, scaleY, randomness )
	#while( rand( halton2D_seed ) < randomness )
		#declare halton2D_current = halton2D_current + 1;
	#end
	< halton( halton2D_current*scaleX + offsetX, baseX ), halton( halton2D_current*scaleY + offsetY, baseY ), 0 >
	#declare halton2D_current = halton2D_current + 1;
#end

#declare rand_seed = seed( 1 );
#macro rand2DGenerator( baseX, baseY, offsetX, offsetY, scaleX, scaleY, randomness )
	< rand( rand_seed ), rand( rand_seed ), 0 >
#end

light_group {
// Front Light
light_source { <0, 0, -4000> rgb 1 }

// Points 
#declare spheres_per_frame = 50;
#declare num_spheres = spheres_per_frame * frame_number;
#declare max_spheres = spheres_per_frame * 10;
#declare sphere_size = 0.012;
#declare i = 0;
#while ( i < num_spheres )
	sphere {
		halton2DGenerator( 2, 7, 0, 103, 1, 1, 0 ), sphere_size
		//halton2DGenerator( 2, 3, 103, 0, 1, 1, 0.4 ), sphere_size
		//halton2DGenerator( 5, 7, 100, 30, 7, 17, 0.3 ), sphere_size
		pigment { rgb <max_spheres-i, 0, i>/max_spheres } 
		//pigment { rgb 1 }
		finish { ambient 0.5 diffuse 0.5 }
		translate <sphere_size*1.5, sphere_size*1.5,-sphere_size>
	}
	#declare i = i + 1;
#end
}

// Rest of scene
light_group {
	#declare diam = 0.015;
	#declare axis_colour = rgb 0.9;
	cylinder { <-diam*3, 0, 0>, <1, 0, 0>, diam pigment { rgb axis_colour } }
	cylinder { <0, -diam*3, 0>, <0, 1, 0>, diam pigment { rgb axis_colour } }
	cone { <1, 0, 0>, diam * 2,  <1 + diam*5, 0, 0>, 0 pigment { rgb axis_colour } }
	cone { <0, 1, 0>, diam * 2,  <0, 1 + diam*5, 0>, 0 pigment { rgb axis_colour } }
	light_source { <2000, 2000, -4000> rgb 1 }
	text {
		ttf "timrom.ttf", str(num_spheres,0,0)
		0.3, <0.0, 0.0, 0.0>
		scale 0.2
		translate <0.37,-0.17,0>
		pigment { rgb axis_colour }
	}
}
camera {
	orthographic location < 0.5, 0.5, -5>
	right x * 1.3 up y * image_height/image_width * 1.3
	look_at < 0.5, 0.45, 0>
}