Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Creating special shapes/patterns without using graphic Lib

 
Ranch Hand
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. >
 
Rancher
Posts: 1196
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic