Jump to content

Drawing shapes (in C)

Can anyone point me to a good site where it shows you (the code) how do you do it... It's a classic problem, but I haven't been able to find anything useful.

Any help is appreciated :)

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/
Share on other sites

Link to post
Share on other sites

Do you plan to draw in the command line (ex: ASCII art) or are you using some kind of graphics library?

Exactly my question as well^.

 

Anyway,here is a very good playlist(not yet completed) of 3D Software Rendering,explaining lots of stuff.You'll learn a lot about how rendering really works. On the other hand, it is in Java,so you can't really use it too much.It's good for understanding rendering as a whole.

https://www.youtube.com/playlist?list=PLEETnX-uPtBUbVOok816vTl1K9vV1GgH5

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429094
Share on other sites

Link to post
Share on other sites

Exactly.

 

Anyway,here is a very good playlist(not yet completed) of 3D Software Rendering,explaining lots of stuff.You'll learn a lot about how rendering really works. On the other hand, it is in Java,so you can't really use it too much.It's good for understanding rendering as a whole.

https://www.youtube.com/watch?v=Y_vvC2G7vRo&list=PLEETnX-uPtBUbVOok816vTl1K9vV1GgH5

 

 

Do you plan to draw in the command line (ex: ASCII art) or are you using some kind of graphics library?

Actually it's just the simple drawing (printf) with *. Nothing to fancy. Things like this:

****

*  *

*  *

****

(imagine that is a hollow square).

Need it for school BTW.

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429119
Share on other sites

Link to post
Share on other sites

Do you have to use C? If you want to do graphics I'd recommend using Java it's much easier.

|| Processor: AMD Ryzen 5 2600 || RAM: 32GB (4x8GB) Corsair DDR4 Vengance (3000) || Motherboard: ASUS Prime B450-Plus || Graphics Card: Gigabyte RTX2070 || Storage: 750GB SSD (2 Drives), 3TB HDD (2 Drives) || Case: NZXT H500 || Power Supply: be quiet! Pure Power 11 600W || 

 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429120
Share on other sites

Link to post
Share on other sites

Actually it's just the simple drawing (printf) with *. Nothing to fancy. Things like this:

****

*  *

*  *

****

(imagine that is a hollow square).

Need it for school BTW.

Oh....

Does it need to have any user input?Like draw a triangle for "triangle" input or something?

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429127
Share on other sites

Link to post
Share on other sites

Oh I see ASCII, yeah. You're probably going to have to hard code that.

|| Processor: AMD Ryzen 5 2600 || RAM: 32GB (4x8GB) Corsair DDR4 Vengance (3000) || Motherboard: ASUS Prime B450-Plus || Graphics Card: Gigabyte RTX2070 || Storage: 750GB SSD (2 Drives), 3TB HDD (2 Drives) || Case: NZXT H500 || Power Supply: be quiet! Pure Power 11 600W || 

 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429133
Share on other sites

Link to post
Share on other sites

Oh....

Does it need to have any user input?Like draw a triangle for "triangle" input or something?

No. Unless the size counts.

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429140
Share on other sites

Link to post
Share on other sites

No. Unless the size counts.

Explain the problem you are trying to solve fully and I will give you a few hints. Don't expect anyone to do it for you though as it is homework.

|| Processor: AMD Ryzen 5 2600 || RAM: 32GB (4x8GB) Corsair DDR4 Vengance (3000) || Motherboard: ASUS Prime B450-Plus || Graphics Card: Gigabyte RTX2070 || Storage: 750GB SSD (2 Drives), 3TB HDD (2 Drives) || Case: NZXT H500 || Power Supply: be quiet! Pure Power 11 600W || 

 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429158
Share on other sites

Link to post
Share on other sites

No. Unless the size counts.

So you want to draw stuff like these?

"

*

**

***

"

 

"

****

*  * 

*  *

****

"

just print'em.What's so hard?

I don't know how it's in c,but in c++  : cout <<"****" << endl << "*  *" << endl << "*  *" << endl << "****";  (for a square)

Just print each line then go ahead and print a new line.

 

But what exactly are you trying to do???

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429196
Share on other sites

Link to post
Share on other sites

Explain the problem you are trying to solve fully and I will give you a few hints. Don't expect anyone to do it for you though as it is homework.

Well it's not homework, but we did do a couple of examples in school so I do know a basic concept (2 for loops, and a bunch of ifs) but I didn't fully understand it. 

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429205
Share on other sites

Link to post
Share on other sites

So you want to draw stuff like these?

"

*

**

***

"

 

"

****

*  * 

*  *

****

"

yup, exactly things like those

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429207
Share on other sites

Link to post
Share on other sites

Well it's not homework, but we did do a couple of examples in school so I do know a basic concept (2 for loops, and a bunch of ifs) but I didn't fully understand it.

I'm not sure what else you need to know to solve this problem?

|| Processor: AMD Ryzen 5 2600 || RAM: 32GB (4x8GB) Corsair DDR4 Vengance (3000) || Motherboard: ASUS Prime B450-Plus || Graphics Card: Gigabyte RTX2070 || Storage: 750GB SSD (2 Drives), 3TB HDD (2 Drives) || Case: NZXT H500 || Power Supply: be quiet! Pure Power 11 600W || 

 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429287
Share on other sites

Link to post
Share on other sites

just print'em.What's so hard?

I don't know how it's in c,but in c++  : cout <<"****" << endl << "*  *" << endl << "*  *" << endl << "****";  (for a square)

Just print each line then go ahead and print a new line.

 

But what exactly are you trying to do???

the trick is you need to do it so you can easily expand it (user definable size). So you need to put it in a for loop. And then of course you need some ifs and there's where it stops for me. It's those ifs that get me.

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429293
Share on other sites

Link to post
Share on other sites

the trick is you need to do it so you can easily expand it (user definable size). So you need to put it in a for loop. And then of course you need some ifs and there's where it stops for me. It's those ifs that get me.

It's really simple, think about it.

|| Processor: AMD Ryzen 5 2600 || RAM: 32GB (4x8GB) Corsair DDR4 Vengance (3000) || Motherboard: ASUS Prime B450-Plus || Graphics Card: Gigabyte RTX2070 || Storage: 750GB SSD (2 Drives), 3TB HDD (2 Drives) || Case: NZXT H500 || Power Supply: be quiet! Pure Power 11 600W || 

 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429339
Share on other sites

Link to post
Share on other sites

the trick is you need to do it so you can easily expand it (user definable size). So you need to put it in a for loop. And then of course you need some ifs and there's where it stops for me. It's those ifs that get me.

It's really simple.

Think about it.

Triangle :

*

**

***

****

On the n-th line you need to draw n chars.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
https://linustechtips.com/topic/250084-drawing-shapes-in-c/#findComment-3429370
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×