Question

If you search the web for fractal designs, you will find many inticate wonders beyond the Koch snowflake illustrated in this

/*
* File: HFractal.cpp
* ------------------
* This program draws an H-fractal on the graphics window.int main() {
*/
#include "gwindow.h"


/* Function prototypes */
void drawHFractal(GWindow & gw, double x, double y, double size, int order);


/* Main program */
int main() {
GWindow gw;
double xc = gw.getWidth() / 2;
double yc = gw.getHeight() / 2;
drawHFractal(gw, xc, yc, 100, 3);
return 0;
}


/*
* Function: drawHFractal
* Usage: drawHFractal(gw, x, y, size, order);
* -------------------------------------------
* Draws a fractal diagram consisting of an H in which each additional
* fractal layer draws half-size fractals at the four endpoints of each H.
*/
void drawHFractal(GWindow & gw, double x, double y, double size, int order) {
// @@@@
}

write a recursive function for @@@@

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
* =====================================================================================
*
*       Filename: HFractal.cpp
*    Description: draw H-Fractal in which repeated pattern is shaped like
*    an elongated letter 'H'
*
* =====================================================================================
*/
#include <cmath>
#include <iostream>
#include "random.h"
#include "gwindow.h"

using namespace std;

void drawHFractal(GWindow gw, double x, double y, double size, int order);

//void drawHFractal(GWindow gw, double & x, double & y, double   size, int order);
int main(void)
{
    GWindow gw(600,600);
    double xc = gw.getWidth()/2;
    double yc = gw.getHeight()/2;
    drawHFractal(gw, xc, yc, 100, 3);

    return 0;
}

void drawHFractal(GWindow gw, double x, double y, double size, int order)
//void drawHFractal(GWindow gw, double & x, double & y, double   size, int order)
{
    int upleft_x = x - size/2;
    int upleft_y = y - size/2;
    int downright_x = x + size/2;
    int downright_y = y + size/2;
    gw.drawLine(upleft_x, upleft_y, upleft_x, downright_y );
    gw.drawLine(upleft_x, y, downright_x, y);
    gw.drawLine(downright_x, upleft_y, downright_x, downright_y);
    if(order == 0)
    {
        return;
    }
    drawHFractal(gw, upleft_x, upleft_y, size/2, order-1);
    drawHFractal(gw, upleft_x, downright_y, size/2, order-1);
    drawHFractal(gw, downright_x, upleft_y, size/2, order-1);
    drawHFractal(gw, downright_x, downright_y, size/2, order-1);
}

Add a comment
Know the answer?
Add Answer to:
/* * File: HFractal.cpp * ------------------ * This program draws an H-fractal on the graphics wi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ 1. Your program should use named string constant for the file name to open the...

    C++ 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. (Lab2b.cpp) Write a...

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any pa...

    c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....

  • a ruby program problem **************************************************************************** Ruby These short language exercises are intended to help you to...

    a ruby program problem **************************************************************************** Ruby These short language exercises are intended to help you to explore new languages with differing paradigms and syntax. In this assignment you will complete a Ruby program. I will give you help on where and what to look for in Ruby to assist you. Write a Ruby program to solve the following problem: Open a file that has a list of scores between 0 and 100. There may be as many as 100 scores...

  • 10. Submission In this question you will work with a hash table that uses double hashing. The hash table is size 11, the primary hash function is h(K)-K mod 11, and the secondary hash function is hp(...

    10. Submission In this question you will work with a hash table that uses double hashing. The hash table is size 11, the primary hash function is h(K)-K mod 11, and the secondary hash function is hp(K)-(K mod9) +1 Take an empty hash table. Take your student number and split it into 4 2-digit integers. Insert each of these 2-digit numbers in the order in which they appear in your student number into the empty heap. Then insert the values...

  • In a new file located in the same package as the class Main, create a public...

    In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • Hello can someone help me in my code I left it as comment  task #0, task#1, task#2a...

    Hello can someone help me in my code I left it as comment  task #0, task#1, task#2a and task#2b the things that I am missing I'm using java domain class public class Pizza { private String pizzaCustomerName; private int pizzaSize; // 10, 12, 14, or 16 inches in diameter private char handThinDeep; // 'H' or 'T' or 'D' for hand tossed, thin crust, or deep dish, respecitively private boolean cheeseTopping; private boolean pepperoniTopping; private boolean sausageTopping; private boolean onionTopping; private boolean...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT