代码文本:
#include "stdio.h"
double fun(int n){
int m,s
for(s=1,m=nm--s*=10)
return n>1 ? 9.0/(7*s-25)+fun(n-1) : 0.2
}
int main(int argc,char *argv[]){
int n
printf("Enter n(int 0<n<11)...\nn=")
if(scanf("%d",&n)==1 &&n>0 &&n<11)
printf("S(%d) = %.10g\n",n,fun(n))
else
printf("Input error, exit...\n")
return 0
}
framebuffer(帧缓冲)。
帧的最低数量为24(人肉眼可见)(低于24则感觉到画面不流畅)。
显卡与帧的关系:由cpu调节其数据传输速率来输出其三基色的配比。
三基色:RGB(红绿蓝)。
在没有桌面和图形文件的系统界面,可以通过C语言的编程来实现在黑色背景上画图!
用下面的代码,在需要的地方(有注释)适当修改,就能画出自己喜欢的图形!
PS:同样要编译运行后才能出效果。
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stdlib.h>
#define RGB888(r,g,b) ((r &0xff) <<16 | (g &0xff) <<8 | (b &0xff))
#define RGB565(r,g,b) ((r &0x1f) <<11 | (g &0x3f) <<5 | (b &0x1f))
int main()
{
int fd = open("/dev/fb0", O_RDWR)
if(fd <0){
perror("open err. \n")
exit(EXIT_FAILURE)
printf("xres: %d\n", info.xres)
printf("yres: %d\n", info.yres)
printf("bits_per_pixel: %d\n", info.bits_per_pixel)
size_t len = info.xres*info.yres*info.bits_per_pixel >>3
unsigned long* addr = NULL
addr = mmap(NULL, len, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0)
if(addr == (void*)-1){
perror("mmap err. \n")