aspose file tools*
The moose likes Programming Diversions and the fly likes Creating special shapes/patterns without using graphic Lib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Creating special shapes/patterns without using graphic Lib" Watch "Creating special shapes/patterns without using graphic Lib" New topic
Author

Creating special shapes/patterns without using graphic Lib

Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

hello there , I see various interesting programs (such as diamond pattern using "*") on the Internet. Several of them uses Maths functions to form a particular shape. Check out this one..


the above program prints a heart shape with "Happy Valentine's Day" message. They used the math functions to perform this task. If I want to print a particular shape without using a graphic library , say a cube how would I do that ? I need your guidance to understand such situation. What is "idx" in the above code ? I mainly get confused with For Loops with mathematical calculation. I find it very hard to understand. Sorry , If I sound like complete moron.. unlike you guys , I don't have an engineering degree. >


Back to Java , again.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1008
    
    3
Bobby Sharma wrote:hello there , I see various interesting programs (such as diamond pattern using "*") on the Internet. Several of them uses Maths functions to form a particular shape. Check out this one..
...
the above program prints a heart shape with "Happy Valentine's Day" message. They used the math functions to perform this task. If I want to print a particular shape without using a graphic library , say a cube how would I do that ? I need your guidance to understand such situation. What is "idx" in the above code ? I mainly get confused with For Loops with mathematical calculation. I find it very hard to understand. Sorry , If I sound like complete moron.. unlike you guys , I don't have an engineering degree. >


First, let me say that the second outer for loop (the "for(x=1..." one), whcih prints out the lower triangle of the heart, is not put together the way I would have done. Nonetheless...

The "idx" variable indicates what character within "message" is to be printed. e.g. When idx=1, the 'H' in " Happy Valentine's Day " will be printed.


As for how to draw other shapes, such a cube, it all depends on how exactly you want to output to look. If you really want to make something general-purpose enough to be able to draw the 2D projection of arbitrary 3D shapes, you could develop your own ray-tracing program. However, I suspect that such a project is more than you want to get involved in.

Let me add some specifics to your request so that we're all on the same page about what problem we're trying to solve:

How could you print a character graphics representation of an isometric projection of a cube of a given size? For instance for size=4, you would get the following:

(Edit: New version of output.)


I just picked '.', 'c' and 'M' more-or-less at random as "light", "medium" and "dark" fill characters.

Bobby, now that you know what you want, what do you think the next step is toward implementing it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating special shapes/patterns without using graphic Lib