Josh Schoenwald
//
// Josh Schoenwald -- Task 05 -- accad 756 -- Due 10/22/02
//
// Plot 250,000 pixels
var w = 500; //dimenstions for my beautiful picture
var h = 500;
var RC = new RasterCanvas(w, h, Units.PIXELS); //instantiate raster canvas for use
//fills background region with gradient
function bg (w, h) {
var x, y = 0; //variables for height, width, and color changes
var redpen = 1;
var greenpen = 1;
var bluepen = 1
var redincrement = (redpen - .61) / h; //sets increment values for red gradient
var greenincrement = (greenpen - .61) / h; //sets increment values for green gradient
var blueincrement = 0; //sets increment values for blue gradient
while ((x < w) && (y < h)) { //iterates in space of area provided by params
RC.setPenColor(redpen, greenpen, bluepen);
RC.drawLine(0, y, w, y); //draws line across screen
y += 1; //iterates y value for loop
redpen -= redincrement; //colors fade from light to dark (brightness)
greenpen -= greenincrement;
bluepen -= blueincrement;
}
return(y); //returns ending y-value for use later
}
//takes in 2 options and the current value. Switches
//between the two each time the function is called
function chgcolor(tile1, tile2, val) {
for (var j = 0; j < 3; j++) { //iterates 3 times corresponding to r, g, b values
if (val[j] == tile1[j]) { //if value is equal to tile1, make it equal to tile2 instead
val[j] = tile2[j];
}
else val[j] = tile1[j]; //otherwise (value == tile2) make value equal to tile1
}
}
//fills remaining area (ground) with checkerboard pattern
function ground (starty, tile1, tile2) {
newheight = h - starty; //defines newheight to be height of checkered area
var numxtiles = 14; //specifies number of columns
var numytiles = numxtiles * (newheight / w); //assures perfect square tiles
var x_tile_thresh = w / numxtiles; //determines x boundaries for columns
var y_tile_thresh = newheight / numytiles; //determines y boundaries for rows
var p1 = new Array(); //variables for fillPoly to draw boxes
var p2 = new Array();
var p3 = new Array();
var p4 = new Array();
var feather = 0; //specifies number of units (pixels) to feather boxes
var val = new Array(0, 0, 0); //actual color of tile, preset to tile1
for (var x = 0; x < w; x += x_tile_thresh) { // iterates until end of canvas
chgcolor(tile1, tile2, val); //switches 'val' to alternate tile color
feather = 0; //no feathering this time
for (var y = starty; y < h; y += y_tile_thresh) { //iterates until bottom of canvas
RC.setPenColor(val[0], val[1], val[2]); //sets the pen color based on 'val'
p1[0] = x; //set values for drawing boxes with fillpoly
p2[0] = x + x_tile_thresh;
p3[0] = x + x_tile_thresh;
p4[0] = x;
p1[1] = y;
p2[1] = y;
p3[1] = y + y_tile_thresh;
p4[1] = y + y_tile_thresh;
RC.fillSoftPoly(new Array(p1, p2, p3, p4), feather); //draws box & feathers
chgcolor(tile1, tile2, val); //alternates 'val' for next tile color
feather += 0 / numytiles; //feathers equally from 0 to some number of pixels
}
}
}
//draws the stem of the flower
function stem (x, y) {
var endy = y + 100; //draws down 100 pixels
var softy = .8; //specifies # pixels to feather stem
RC.setPenColor(.2, .78, .2); //sets stem color
RC.setPenWeight(10); //sets stem thickness
RC.drawSoftLine(x, y, x, endy, softy); //draws stem
return(endy); //returns ending y-value for use later on
}
//draws vase
function vase (x, y, color) {
var xshift = 100; //beginning x-value for vase
var yshift = 157; //beginning y-value for vase
var feather = 0; //no feathering, but it's there if I want it
var p1 = new Array(); //points for defining vase edges
var p2 = new Array();
var p3 = new Array();
var p4 = new Array();
RC.setPenColor(color[0], color[1], color[2]); //sets pen color for vase
p1[0] = x; //defines vase corners x-values
p2[0] = x + xshift
p3[0] = x + (xshift * (2 / 3)); //sets width of bottom of vase to be 1/3 that of top
p4[0] = x + (xshift * (1 / 3)); //" "
p1[1] = y; //defines vase corners y-values
p2[1] = y;
p3[1] = y + yshift;
p4[1] = y + yshift;
RC.fillSoftPoly(new Array(p1, p2, p3, p4), feather); //draws vase
}
//converts polar coords to cartesian for computations
function polarToCartesian(distance, radianAngle) {
var x = distance * Math.cos(radianAngle);
var y = distance * Math.sin(radianAngle);
return new Array(x, y);
}
//draws the pretty flower
function flower (centerx, centery, radius, numpetals) {
var dist = .008; //specifies width between calls to RC.setpixel
RC.setPenColor(249/255, 132/255, 6/255); //sets flower color
for (var angle = 0; angle < Math.PI; angle += dist) { //performs one complete revolution
var limit = Math.sin(numpetals * angle) * radius; //total distance travelled
var cart = polarToCartesian(limit, angle); //stores cartesian values
RC.setPixel(centerx + cart[0], centery + cart[1], 1); //draws petals
}
}
var starty = bg(500, 300); //draws background
//normalizes photoshop color values
function ps (color) {
color = color / 255;
return(color);
}
var color1 = new Array(ps(10), ps(27), ps(102)); //sets 1st tile color
var color2 = new Array(ps(158), ps(160), ps(13)); //sets 2nd tile color
ground(starty, color1, color2); //draws floor, starting at the ending y-value of the background
var curLayer = RC.newArtLayer(LayerKind.NORMAL); //creates a new layer
var startstemx = 140; //sets x-value for beginning stem
var startstemy = 100; //sets y-value for beginning stem
var startvasey = stem(startstemx, startstemy); //draws stem
var color = new Array(.78, .2, .2); //sets color of vase
vase(startstemx - 45, startvasey, color); //positions lip of vase under stem
flower(startstemx, startstemy - 40, 55, 11); //draws flower w/ 13 petals, 55 units long
// release object referencess
RC = null;
//Rest of code (Utility Object) commented out