recursions in gui

Ads
 

recursions in gui

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);

    }



}

} }

View Answers

Ads









Related Tutorials/Questions & Answers:
recursions - Java Beginners
recursions  Can somebody help me with these four questions. Please. i am learning recursions in Java. Question1. Trying to find the value of result when its (5) from this code. public int result(int n) { if (n==1
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
Advertisements
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the ??To:??, ??Subject:?? and ??Message:?? text. The ??To:??, and ??Subject:?? Text areas
GUI framework
GUI framework  what do u mean by GUI framework
GUI component
GUI component  How can a GUI component handle its own events
Convert the code to GUI
GUI code  GUI code
gui question
gui question  design a gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
GUI problem
GUI problem  Create a class called CDProgram and write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited: 80000.00 Years: 15 Interest Rate: 7.75 Hint
java gui
java gui   friends... good day.. i have doubt in java gui. ? i created 1 java gui application. That has two text fields jtext1,jtext2. case: user entered value in first textfield(jtext1) and pressed the enter key . the cursor
Convert the code to GUI
GUI Application example  GUI Application example
Convert the code to GUI
GUI Example  GUI Example code to learn
Java GUI
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Version of gj-gui>gj-gui dependency
List of Version of gj-gui>gj-gui dependency
gui question
gui question  design a gui application and write code to accept a string from the user in a textfeild and print using option pane whether it is a palindrome or not. hint: abba is a palindrome   import java.awt.*; import
GUI problem
GUI problem  How do I make a Jbutton which is shaped like a circle. This button needs to be clicked in order to change color.   import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
GUI Application Development   GUI Application Development
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
how to refresh my GUI page
how to refresh my GUI page  how to refresh a GUI in java
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
Artifacts of gj-gui
List of Artifacts of gj-gui maven depenency

Ads