用python画数学函数图像教程_你知道哪些用计算机画数学函数图像的方法?

熟悉某种图片格式(jpg,bmp,etc)后生成所需图片(这个比较非主流,是以前刚学了C后,想到的办法)

42947555_3.jpg

C源码:

#include 

#include 

#include 

#include 

typedef unsigned char  BYTE;

typedef unsigned short WORD;

typedef unsigned long  DWORD;

typedef long                 LONG;

#pragma pack(2)

typedef struct {

WORD    bfType;

DWORD   bfSize;

WORD    bfReserved1;

WORD    bfReserved2;

DWORD   bfOffBits;

} BITMAPFILEHEADER;

typedef struct {

DWORD      biSize;

LONG       biWidth;

LONG       biHeight;

WORD       biPlanes;

WORD       biBitCount;

DWORD      biCompression;

DWORD      biSizeImage;

LONG       biXPelsPerMeter;

LONG       biYPelsPerMeter;

DWORD      biClrUsed;

DWORD      biClrImportant;

} BITMAPINFOHEADER;

void saveBitmap()

{

// Define BMP Size

const int height = 600;

const int width = 800;

const int size = height * width * 3;

double x, y;

int index;

// Part.1 Create Bitmap File Header

BITMAPFILEHEADER fileHeader;

fileHeader.bfType = 0x4D42;

fileHeader.bfReserved1 = 0;

fileHeader.bfReserved2 = 0;

fileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + size;

fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

// Part.2 Create Bitmap Info Header

BITMAPINFOHEADER bitmapHeader = {0};

bitmapHeader.biSize = sizeof(BITMAPINFOHEADER);

bitmapHeader.biHeight = height;

bitmapHeader.biWidth = width;

bitmapHeader.biPlanes = 3;

bitmapHeader.biBitCount = 24;

bitmapHeader.biSizeImage = size;

bitmapHeader.biCompression = 0; //BI_RGB

// Part.3 Create Data

BYTE *bits = (BYTE *)malloc(size);

// Clear

memset(bits, 0xFF, size);

//generate Sin Graph

for(x = 0; (x 

{

y=sin(x / 100.0) * 200 + 300;

//y=log(x*10.0+1.0)*10;

if ((y>0)&&( y<600))

{index = (int)y * 800 * 3 + (int)x * 3;

bits[index + 0] = 255; // Blue

bits[index + 1] = 0;   // Green

bits[index + 2] = 0; }  // Red

}

// Write to file

FILE *output = fopen("output.bmp", "wb");

if(output == NULL)

{

printf("Cannot open file!\n");

}

else

{

fwrite(&fileHeader, sizeof(BITMAPFILEHEADER), 1, output);

fwrite(&bitmapHeader, sizeof(BITMAPINFOHEADER), 1, output);

fwrite(bits, size, 1, output);

fclose(output);

}

printf("\n finished");

}

int main()

{

saveBitmap();

getch();

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值