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
Related Tutorials/Questions & Answers:
recursions in guirecursions 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
recursions - Java Beginnersrecursions 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
Advertisements
GUIGUI How to
GUI in Net-beans ... ??
Please visit the following link:
http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
GUIGUI 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 componentGUI component How can a
GUI component handle its own events
gui questiongui 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 problemGUI 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
Java GUIJava 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
gui questiongui 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 problemGUI 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
ModuleNotFoundError: No module named 'gui'ModuleNotFoundError: No module named '
gui' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
gui'
How to remove the ModuleNotFoundError: No module named '
gui' error
Magic Matrix in GUIMagic Matrix in GUI I want program in java
GUI contain magic matrix for numbers
Maven Repository/Dependency: gj-gui | gj-guiMaven Repository/Dependency of Group ID gj-
gui and Artifact ID gj-
gui. Latest version of gj-
gui:gj-
gui dependencies.
#
Version
Release Date
You can read more at:
Maven
Tutorials
Flex SDK GUIFlex SDK GUI Hi.......
please give me ans of this question..
What classes do you typically extend in the Flex SDK for creating
GUI controls and why?
Thanks
GUI application programGUI application program Write a
GUI application program that meets the following requirements:
Create an array with 100 randomly chosen integers.
Create a textfield to enter an array index and another textfield to display
Java GUI - Java3DJava 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
Maven Dependency gj-gui >> 0.1You should include the dependency code given in this page to add Maven Dependency of gj-
gui >> gj-
gui version0.1 in your project
java gui-with jscroll panejava
gui-with jscroll pane Dear friends..
I have a doubt in my
gui application.
I developed 1 application. In this application is 1 Jscrollpane of height 600 and width 400. Normally it is showing 200 height and 400 width
java gui-with jscroll panejava
gui-with jscroll pane Dear friends..
I have a doubt in my
gui application.
I developed 1 application. In this application is 1 Jscrollpane of height 600 and width 400. Normally it is showing 200 height and 400 width
ModuleNotFoundError: No module named 'argus-gui'ModuleNotFoundError: No module named 'argus-
gui' Hi,
My Python... 'argus-
gui'
How to remove the ModuleNotFoundError: No module named 'argus-
gui' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'argus-gui'ModuleNotFoundError: No module named 'argus-
gui' Hi,
My Python... 'argus-
gui'
How to remove the ModuleNotFoundError: No module named 'argus-
gui' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'argus-gui'ModuleNotFoundError: No module named 'argus-
gui' Hi,
My Python... 'argus-
gui'
How to remove the ModuleNotFoundError: No module named 'argus-
gui' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'bottle-gui'ModuleNotFoundError: No module named 'bottle-
gui' Hi,
My Python... 'bottle-
gui'
How to remove the ModuleNotFoundError: No module named 'bottle-
gui' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'bottle-gui'ModuleNotFoundError: No module named 'bottle-
gui' Hi,
My Python... 'bottle-
gui'
How to remove the ModuleNotFoundError: No module named 'bottle-
gui' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'dlc-gui'ModuleNotFoundError: No module named 'dlc-
gui' Hi,
My Python...-
gui'
How to remove the ModuleNotFoundError: No module named 'dlc-
gui... to install padas library.
You can install dlc-
gui python with following command