Tuesday, July 31, 2012

Houses Generated by Scripts

Working on some scripts for creating houses.  This one uses Illustrator.  Pretty rough at this point.
POVRay code (use at your own risk):



global_settings {max_trace_level 5}
background {rgb <1,1,1>}
//camera {orthographic location <30-15*clock,0,0> rotate <clock*60,clock*30,clock*360> look_at <0,0,0> angle 22}
camera {orthographic location <0,20,-40> look_at <0,0,0> angle 20}
light_source {<80,100,40> rgb .5 }
light_source {<20,200,20> rgb .8 }
    
height_field {
    png "house_roofs.png"
    //smooth 
    translate <-.5,0,-.5>
pigment {
      gradient y       //this is the PATTERN_TYPE
      color_map {
        [0.0  color <.2,.1,.0>]
        [0.5  color <.2,.1,.0>]
        [0.7  color <.9,.4,.2>]
        [0.9  color <.9,.3,.2>]
        [1.0  color <.9,.3,.1>]
      }                     }
    scale <17, 1, 17>
    finish {roughness .1 specular .5 ambient .2}
  }



A collection of houses generated from the following gray scale.


This is the JavaScript that drives the Illustrator program.  Use at your own risk.

/**********************************************************
Roofs.js


DESCRIPTION


This script creates the roofs for a random village
**********************************************************/


var thisDoc = app.documents.add();
var artLayer = thisDoc.layers.add();


var gray = Math.random()*50+50; 
var myGradient = createGradient(gray);
var lineColor = new RGBColor();
lineColor.red = gray + 50;
lineColor.green = gray + 50;
lineColor.blue = gray + 50;
for (j = 0; j != 20; ++j)
 {
  var piRef = artLayer.pathItems;
  var roofGroup = artLayer.groupItems.add();


// Make both sides of a roof and a center line
  for ( i = 0; i != 2 ; ++i )
  {
// Create the roof shape
  var rect = artLayer.pathItems.rectangle(150, 220+75*i, 75, 110);
rect.filled = true;
rect.stroked = false;
rect.fillColor = myGradient;
redraw();
  rect.rotate(180*i)
  rect.moveToBeginning(roofGroup);
  }
  var pathRef = piRef.add()
pathRef.setEntirePath( new Array(
new Array(295, 40),
new Array(295,150)));
pathRef.stroked = true;
pathRef.strokeColor = lineColor;
  pathRef.moveToBeginning(roofGroup);


  roofGroup.resize(Math.random()*10+10,Math.random()*10+10)
  roofGroup.rotate(Math.random()*100)
  roofGroup.translate(Math.random()*200,Math.random()*200)


}


function createGradient(gray)
{


// Create color objects for both ends of the gradient
var startColor = new RGBColor();
var endColor = new RGBColor();
var gray1 = gray+50

startColor.red = gray;
startColor.green = gray;
startColor.blue = gray;
endColor.red = gray1;
endColor.green = gray1;
endColor.blue = gray1;



// Create a new gradient
// A new gradient always has 2 stops
var theGradient = app.activeDocument.gradients.add();
theGradient.name = "myGradient";
theGradient.type = GradientType.LINEAR;



// Modify the first gradient stop
theGradient.gradientStops[0].rampPoint = 0;
theGradient.gradientStops[0].midPoint = 50;
theGradient.gradientStops[0].color = startColor;



// Modify the last gradient stop
theGradient.gradientStops[1].rampPoint = 100;
theGradient.gradientStops[1].color = endColor;



// Construct an Illustrator.GradientColor object referring to the
// newly created gradient
var myGradientColor = new GradientColor();
myGradientColor.gradient = theGradient;
return myGradientColor;
}

No comments:

Post a Comment