Thread: plot xy bmp

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    18

    plot xy bmp

    hello guys i need to make a bmp file of plot xy
    those anyone has a little idea how i can do it ?
    TNx

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    505
    Quote Originally Posted by cbeginner12334 View Post
    hello guys i need to make a bmp file of plot xy
    those anyone has a little idea how i can do it ?
    TNx
    Go to my website and download bmp.c from the BabyX resource compiler. This contains a function for saving an array as a .bmp
    file.

    Now your problem is to create the plot as a raster.

    In C, it's usually easier to treat 2D arrays as 1D arrays, and do the
    indexing manually. That's because C's 2D arrays aren't good if
    the dimensions need to be flexible, which is usually the case.

    So set the whole buffer to your background colour, probably white.

    Now iterate over the x range, of your array. Say the bitmap is
    256 x 256. iterate from xi = 0 to 255.
    Now convert xi (pixel x) to x (logical x). Say your plot goes from 0
    to 1. logical x equals x1 / 255.0.
    Now calculate logical y, based on your function. say you are plotting
    x squared, logical y - logical x * logical x.
    Now convert logical y to pixel y. This is a similar operation to
    calculating logical x from pixel x, but in reverse.

    Now set the pixel to red, using the formula

    Code:
    buffer[ iy * width +x] = RED;
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to plot a graph using C
    By Katie_lin in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 02:38 PM
  2. 3D Plot
    By khdani in forum Game Programming
    Replies: 1
    Last Post: 08-05-2008, 04:09 PM
  3. The plot thickens
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 54
    Last Post: 03-22-2004, 07:29 PM
  4. Can someone tell me if I've lost the plot
    By Azuth in forum C Programming
    Replies: 1
    Last Post: 10-02-2002, 12:06 AM
  5. What Else can I do besides Plot Pixels?
    By Xterria in forum C++ Programming
    Replies: 13
    Last Post: 10-02-2001, 07:11 PM

Tags for this Thread