[Swansea Hackspace] openscad maths

Justin Mitchell justin at discordia.org.uk
Thu Oct 30 16:04:53 GMT 2014


On Thu, 2014-10-30 at 15:52 +0000, Ceri Clatworthy wrote:
> Wanted something like this:

>         On Thu, 2014-10-30 at 13:37 +0000, Ceri Clatworthy wrote:
>         > Hi, going crazy here ...
>         > I need something like:
>         
>         > test = 102; // 0x66
>         > if (test AND 1) {do something usefull @ poz 1};
>         > if (test AND 2) {do something usefull @ poz 2};
>         
>         > e.g. draw the binary representation of a 16 bit number in
>         > cubes/spheres !!!


after some further thought, it is possible...

val = 39317;

for (i = [15:-1:0])
{
	if ( floor(val / pow(2, i)) % 2 == 1 ) {
		translate([15-i,0,0]) cube([1,1,2]);
	} else {
		translate([15-i,0,0]) cube([1,1,1]);
	}
}






More information about the Hackspace mailing list