473,849 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

drawing using C

Hi folks,

I need to write a short program which gets a few parameters and draws a
diagram in the text file. Basically what I need is a guidance on how I
put stream indicator to the required position. What I mean is that I
need to draw a character at the (x,y) coordinate. But how do I bring
the indicator to this position. I tried to use fsetpos(fp, y*80+x) but
then when I draw the character by fputs("_",fp) I see it on the first
line with y*80+x offset instead of y-th line with x offset. I'd
appriciate any idea. Thanks.

LM

May 2 '06 #1
9 1871
liorm opined:
Hi folks,

I need to write a short program which gets a few parameters and draws
a diagram in the text file. Basically what I need is a guidance on
how I put stream indicator to the required position. What I mean is
that I need to draw a character at the (x,y) coordinate. But how do I
bring the indicator to this position. I tried to use fsetpos(fp,
y*80+x) but then when I draw the character by fputs("_",fp) I see it
on the first line with y*80+x offset instead of y-th line with x
offset. I'd appriciate any idea. Thanks.


If you can draw your diagram sideways (i.e. make it YX not XY) then
every line is for one X, and you can put a character (say an 'o') Y
spaces away from the beginning of the line. Obviously, you can also
have axes, labels etc. For example, Y = X could look like:

-5 0 5
--------------------o--------------------> Y
|o
| o
| o
| o
| o
| o
| o
V
X

The only things you need would be basic `printf()` et al.

--
I could dance till the cows come home. On second thought, I'd rather
dance with the cows till you come home.
-- Groucho Marx

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

May 2 '06 #2
Vladimir Oka opined:
liorm opined:
Hi folks,

I need to write a short program which gets a few parameters and
draws a diagram in the text file. Basically what I need is a
guidance on how I put stream indicator to the required position.
What I mean is that I need to draw a character at the (x,y)
coordinate. But how do I bring the indicator to this position. I
tried to use fsetpos(fp, y*80+x) but then when I draw the character
by fputs("_",fp) I see it on the first line with y*80+x offset
instead of y-th line with x offset. I'd appriciate any idea. Thanks.


If you can draw your diagram sideways (i.e. make it YX not XY) then
every line is for one X, and you can put a character (say an 'o') Y
spaces away from the beginning of the line. Obviously, you can also
have axes, labels etc. For example, Y = X could look like:

-5 0 5
--------------------o--------------------> Y
|o
| o
| o
| o
| o
| o
| o
V
X

The only things you need would be basic `printf()` et al.


OK, I may have not been clear enough. Here's some meta-code:

You go through all Xs in turn, one line dedicated to each. You
calculate corresponding Y. A marker ('o') is put after N spaces, where
N corresponds to Y (depending on desired scale). You can decorate with
labels and/or axes to taste. All you need are loops for Xs,
calculation of Ys and Ns, and a `printf()`.
--
Fortunate is he for whom the belle toils.

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

May 2 '06 #3
I don't really get how this helps me. I still need to know how to bring
myself to a certain coordinate, whether it is (X,Y) or (Y,X). As I
mentioned above I tried fsetpos and fseek, but both of them leave me on
the first line of the output file. How can I skip lines to get to the
required coordinate?

May 2 '06 #4
Thanks.
I don't really get how this helps me. I still need to know how ito
bring myself to the required coordinate, whether it is (X,Y) or (Y,X).
As I mentioned above I tried fsetpos and fseek but both of them left me
on the first line of the text file, while I need to skip lines to reach
the coordinate.

May 2 '06 #5
On 2006-05-02, liorm <li***@ti.com > wrote:
Thanks.
I don't really get how this helps me. I still need to know how ito
bring myself to the required coordinate, whether it is (X,Y) or (Y,X).
As I mentioned above I tried fsetpos and fseek but both of them left me
on the first line of the text file, while I need to skip lines to reach
the coordinate.


You misunderstand how text files work.

Probably the easiest thing to do would be to draw it in an array of char
arrays in memory and then print it out.
May 2 '06 #6
Thanks, this is a great idea!

May 2 '06 #7
liorm opined:

You need to quote some context (what was said, and by whom).
Thanks.
I don't really get how this helps me. I still need to know how ito
bring myself to the required coordinate, whether it is (X,Y) or
(Y,X). As I mentioned above I tried fsetpos and fseek but both of
them left me on the first line of the text file, while I need to skip
lines to reach the coordinate.


Let's say you want to plot Y = 2*X for X from 0 to 4. You can do that
by printing one line to a text file representing Y position on the
graph that corresponds to X=0, then the next for X=1, and so forth.

X Y Output
0 0 "o"
1 2 " o"
2 4 " o"
3 6 " o"
4 8 " o"

Catch my drift? You can output leading blanks in a loop:

for (X = 0; X < 5; ++X) {
Y = 2 * X;
for (n = 0; n < (Y-1); ++n)
printf(" ");
printf("o\n");
}

would do the trick for any given Y (you may want you use `fprintf()`
unless it's OK to just redirect `stdout` to a file).

As I said, you can make it as fancy as you wish, with scaling, labels,
etc.

As Jordan pointed out, you seem to have a misconception about text
files. They are not grids that you can fill in to taste. You have to
build them line by line.

--
Sigh. I like to think it's just the Linux people who want to be on
the "leading edge" so bad they walk right off the precipice.
(Craig E. Groeschel)

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

May 2 '06 #8
liorm wrote:
Thanks, this is a great idea!


See below.
Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
May 2 '06 #9
"liorm" <li***@ti.com > writes:
I need to write a short program which gets a few parameters and draws a
diagram in the text file. Basically what I need is a guidance on how I
put stream indicator to the required position. What I mean is that I
need to draw a character at the (x,y) coordinate. But how do I bring
the indicator to this position. I tried to use fsetpos(fp, y*80+x) but
then when I draw the character by fputs("_",fp) I see it on the first
line with y*80+x offset instead of y-th line with x offset. I'd
appriciate any idea. Thanks.


It's possible on many systems to control the cursor position (for
example, jump to (0, 0), write some characters, jump to (10, 20),
write some more characters, etc.). There's just no way to do this in
standard C. If you want this kind of control, as used by a
full-screen text editor, look for "curses", "ncurses", or something
similar.

But if you want the diagram in a text file rather than on a display,
this doesn't help you. For that, see the other replies in this
thread.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2544
by: Leif K-Brooks | last post by:
I'm considering writing a fairly basic vector drawing program using PyGTK. What's the best way to render it? What I'm thinking of is having everything render on a PIL image, then display that in the GTK window or save it depending on what's being done. Is that the best strategy? Will it be fast enough?
2
391
by: James Coburn's Grey Helmet Hair | last post by:
When I try to compile my GTK# app, the compiler says: jbailo@linux:~/mono> mcs buttons.cs -r gtk-sharp.dll -r glib-sharp.dll -r -o buttons.exe error CS2001: Source file 'buttons.exe' could not be opened Compilation failed: 1 error(s), 0 warnings jbailo@linux:~/mono> mcs buttons.cs -r gtk-sharp.dll -r glib-sharp.dll -o buttons.exe buttons.cs(8) error CS0246: The namespace `System.Drawing' can not be found (missing assembly reference?)
2
12350
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and send to back feature etc. How can I do this .. where should I start?
4
12351
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text (centered in the label) on this label. My font on this label is Courier new - hence fixed width character cells.
7
8752
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as returning a bitmap instance. In my asp.net code I think I should call this method to return a bitmap and then somehow stream it using the response object to the Webcontrols.image. Is that right? The image object is on a page with a number of...
0
3562
by: Hasim AH | last post by:
Hi .. Just getting interested to learn C# and needs help. I want to write C# application so that the program will execute and draw graphics when the user select the drawing menu from the main menu, SigDraw. Here is the codes:- using System; using System.Drawing; using System.Collections;
11
11281
by: dongarbage | last post by:
Hi there, I'm very much a C# novice. How do you do freehand drawing on a panel with a mouse in c#? Thanks, Don
1
3992
by: YouPoP | last post by:
I am doing an app (C# 2.0) where you can draw in a panel with your mouse in "real time". I actually have 2 problems; 1- it does not really is "real time", if your mouse move fast or very fast the line is added after a very small delay. 2-Because I use AddLine(), it adds very short lines from one point to another and it does not give a very good result. Also because of this and my "not real time" problem, when the mouse moves fast it adds...
2
2332
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no response object but how do I write it to screen? Dim objBitmap As New System.Drawing.Bitmap(400, 440) Dim objGraphics As System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBitmap) objGraphics.Clear(Drawing.Color.White)
7
3569
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the excellent transforms specified on Bob Powell's site, I still wonder if there's an easier way of centering it than the following procedure? Here is what I do now (it's awkward but it works): 1) I follow the transforms specified on Bob Powell's...
0
9741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10666
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9501
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7070
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4545
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4140
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.