Write a program that uses recursion to draw squares- one square on the corner of each square. You can write an applet or a standalone GUI program. Either is fine.
Your program should have instance data that defines:
the initial size of the largest square
the minimum length of a size of a square
by what factor you shrink the size for each round of squares
Your program will include a recursive method to draw a square.
The method should draw one square (the small part of the problem it solves now).
The method should then recursively call itself to draw the four squares at the corner of the current square. (The sides of these smaller squares are reduced by some factor.)
The recursive method should be initially invoked once from the paint or paintComponent method.
What parameters should that method have?
What initial values are sent into the first call to this method?
When does the method stop (what is the base case)?
In my sample below, I use an initial side length of 200, a minimum side length of 10, and I cut the size of a side in half each time.
You do not have to use these values- experiment with your own.
In the sample, I fill the square in gray and then draw the outline in black. You are not required to do this.
I include a couple versions of the sample output below. You only need to submit one version of your program.
I recommend first getting the program working with using a method to draw a single square.
I strongly recommend sketching out the coordinates on paper before attempting to put them into code.
I have provided template code that you can use to start from for an applet or a standalone program. You are not required to use this.
(15 points) Instead of drawing a square, draw a different polygon (e.g., any closed-sided figure but not a circle, square, or rectangle). It could be a triangle, parallelogram, trapezoid, be creative!
Note: If completing the extra credit, you do not need to do both the square version and the extra credit- you can complete only the extra credit.
If you want to see what this looks like with fewer squares, to get a better sense of what is going on, here are two images that use a minimum side length of 50 and 100.
¿Buscas ganar algo de dinero?
- Establece tu presupuesto y el plazo
- Describe tu propuesta
- Recibe dinero por tu trabajo
Ofertas en este proyecto
Hi, I have good knowledge of C/C++/Java/Python programming on Linux, Windows and Mac OS. I have knowledge about Mathematics , and any Computer related concept such as Algorithms, Data Structures, Networking, Cryptography, Databases, Operating Systems , Compilers, Data Mining etc. I also have experience related to web. Feel free to discuss your project with me in these domains or any other relevant domain. I ensure 24*7 Support.
Partido de la costa, Argentina
- Android 4.0+ Development . - Java Development. - Python Development. - Web Service Development using PHP/MySQL, JSON.
Hello, We are a team of skilled dedicated people and our passion is simply to excite ourselves with every project that we do. Our team work experience is of more than 5 years combined while enthusiasm and fresh creative minds is the driving force for our team. Every single team member is the task manager who takes complete ownership and that mentality is set in everyone who works on your project. We are a dynamic learning organization willing to accept changes, challenges, hurdles and see an opportunity out of it both for tasks and clients alike. One for all and all for one is the comradely that is experienced in within the team which shows in our projects where we are always directed to make your story , a successful one.
Hi I can do any work in time and also try my best to do perfectly. I am an Engineer and experience in online marketing.
Doing software development for last 20 year. The work in java , oracle ,mysql, C++ languages is undertaken. Web site designing and web page development
Have 5+ Years of programming experience in Java,J2EE, Struts , Spring, Hibernate, JSP . Also have experience in JSF.
Skilled in Web Application Development as well as Stand Alone Applications. Well versed in different front ends and languages like C++/ Java/ .net/ pHp, etc. as well as back ends including MySQL, Oracle, etc.