Generative cheese

javascriptopenjscadgenerative

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// title: Cheese
// author: K.Golinski
// revision: 0.001
// tags: Cheese, Yellow

var holesNum = 80;
var height = 0.5;
var width = 9;
var depth = 5;

function main() {
  var cheese = cube({size: [width,depth,height], center: true});
  for(var i=0;i<holesNum;i++) {
      cheese = cheese.subtract(
        sphere({r: height/2.0+Math.random()*(height/2.0), center:true})
          .translate(
      	    [-width/2.0+Math.random()*width,
      	     -depth/2.0+Math.random()*depth,
      	     -height/2.0+Math.random()*height
      	    ]
      	    )
      );
  }
  return cheese.setColor(1,215/255,0);
}