I need help in completing this. The art will be in contained in a JComponent that will reside in a JFrame and be drawn using simple drawing primitives and recursion to help divide the space into smaller and smaller rectangles. The art details: The following general algorithm will be used to generate your art: If the region is wider than half the initial size and the region is taller than half the initial height:
Use recursion to split the region into 4 smaller regions (a vertical split and a horizontal split) with both split locations chosen randomly. Else if the region is wider than half the initial size:
Use recursion to split the region into 2 smaller regions using a vertical line with the split location chosen randomly. Else if the region is taller than half the initial size:
Use recursion to split the region into 2 smaller regions using a horizontal line with the split location chosen randomly. Else if the region is big enough to split both horizontally and vertically, and both a horizontal and vertical split are randomly selected:
Use recursion to split the region into 4 smaller regions (a vertical split and a horizontal split) with both split locations chosen randomly. Else if the region is wide enough to split horizontally, and a horizontal split is randomly selected: Use recursion to split the region into 2 smaller regions using a vertical line with the split location chosen randomly. Else if the region is tall enough to split vertically, a vertical split is randomly selected: Use recursion to split the region into 2 smaller regions using a horizontal line with the split location chosen randomly. Else: Fill the current region (randomly, either white or colored, and if colored, with a random determination of red, light blue or yellow). Note: In the above art example 50 pixels is the choice for determining if a region is big enough to split (nothing under 50 pixels is split). Randomness: Given this part uses randomness each time your program repaints you�ll get a new piece of art. Use the following guidelines for your random choices: Colors: Use the following strategy to decide which color will be used to fill a region that will not be split further: Select a random value, r If r < 0.0833 then fill the region with red Else if r < 0.1667 then fill the region with skyblue Else if r < 0.25 then fill the region with yellow Else fill the region with white Split Points or Not: Use the following strategy to decide whether a region will be split or not (as outlined above some big regions are always split): Generate a random integer between your minimum region length (I use 50) and (the width of the region * 1.5). If the random integer is less than the width of the region then split the region ELSE do not split Split Point location: Choose the split point, randomly, somewhere between 33% and 67% across the region (or down the region if splitting in the other direction). Choose two random split points when splitting both horizontally and vertically (again between 33% and 67% across the width or height of the region).
public class Art extends JFrame { private int x,y; private int width, height; private int randomInteger;
public void paint (Graphics g )
{
super.paint(g);
//int Red = (int)(Math.random()*256);
//int Green = (int)(Math.random()*256);
//int Blue = (int)(Math.random()*256);
width = (int)(Math.random()*300);//w
height = (int)(Math.random()*400);//h
g.setColor(Color.black);
g.drawLine(0,height,300,height); //horizontal
g.drawLine(width,0,width,400); //vertical
int randomInt = ((int)(Math.random()*(width*1.5))+50);
}
public void recursion(Graphics g,int x,int y,int width,int height)
{
if(randomInteger <width)
{
x = (int)((Math.random()*(width*0.67))+(0.33));
y = (int)((Math.random()*(height*0.67))+(0.33));
int region_height = (int)(Math.round(height * y));
int region_width = (int)(Math.round(width * x)); //33% to 67%
int randomInt = (int)(Math.random()*((region_width*1.5)-50))+50;
g.setColor(Color.black);
if((width>800/2)&&(height>800/2))
{
g.setColor(Color.black);
recursion(g,x,region_height,width,region_height); // horizontal
recursion(g,region_width,y,region_width,height);
g.drawLine(0,y,width,y);
g.drawLine(x,0,x,height);
}
else if(width>800/2)
{
recursion(g,region_width,y,region_width,height);
g.drawLine(x+region_width,y,x+region_width,height-region_height);
}
else if(region_height>800/2)
{
//g.drawLine(x,height,width,height);
recursion(g,x,region_height,width,region_height);
//drawRecursion(g,region_width,region_height,width,region_height); // horizontal
//g.drawLine(x,region_height,width,region_height);//horizontal
g.setColor(Color.pink);
g.drawLine(x,y+region_height,x+width,y+region_height);
//g.drawLine(x,y,width,y);
}
else if((region_width > 50)&&(region_height > 50))
{
recursion(g,region_width,y,region_width,height);// vertical
recursion(g,x,region_height,width,region_height);
g.setColor(Color.red);
g.drawLine(x+region_width,y,x+region_width,y+height);
g.drawLine(x,y+region_height,x+width,y+region_height);
}
else if(region_width > 50)
{
//g.drawLine(width,y,width,height);
g.setColor(Color.magenta);
recursion(g,region_width,0,region_width,height);
g.drawLine(x+region_width,y,x+region_width,y+height);
//drawRecursion(g,region_width, region_height,region_width,height); // vertical
//g.drawLine(region_width,y,region_width,height);// vertical
//g.drawLine(x,y,x,height);
}
else if(region_height > 50)
{
//g.drawLine(x,height,width,height);
recursion(g,0,region_height,width,region_height);
g.drawLine(x,y+region_height,x+width,y+region_height);
}
}
} }