精華區beta NTUNL 關於我們 聯絡資訊
拿來練習BGI做的,logistic mapping的程式,請見笑。 (Comments不是我不加,我要去準備量物啦!) (出現BGI不能啟始的,請自己改一下initgraph的path。) #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <graphics.h> int Take_five(double input) { if(input>639.5) { closegraph(); printf("input= %f\n",input); printf("The point which to draw exceeds the maximum resolution!!\n"); exit(-1); } else { if((input-(int)input)>=0.5) return (int)input+1; else return (int)input; } } void main(void) { int i,N=5000, graphdriver, graphmode; double a=3.3, X,Y,dX=5E-5, X_0=0.4,X_N,X_N_1; printf("Enter iteration N= "); scanf("%d",&N); printf("Enter a= "); scanf("%lf",&a); printf("Enter initial X_0= "); scanf("%lf",&X_0); detectgraph(&graphdriver,&graphmode); initgraph(&graphdriver,&graphmode,"D:\\Turbo-C\\"); setbkcolor(WHITE); setcolor(GREEN); line(0,0,0,479); line(0,479,639,479); for(X=0;X<=1;X+=dX) { Y=a*X*(1-X); putpixel(Take_five(X*639),Take_five(479-Y*479),RED); } X_N=X_0; X_N_1=a*X_N*(1-X_N); line(Take_five(X_N*639),479,Take_five(X_N*639),Take_five(479-X_N_1*479)); for(i=0;i<=N;i++) { setcolor(i%14+1); line(Take_five(X_N*639),Take_five(479-X_N_1*479),Take_five(X_N_1*639), Take_five(479-X_N_1*479)); X_N=X_N_1; X_N_1=a*X_N*(1-X_N); line(Take_five(X_N*639),Take_five(479-X_N*479),Take_five(X_N*639), Take_five(479-X_N_1*479)); } printf(" N= %d\n a= %f\n X_0= %f",N,a,X_0); getch(); closegraph(); } -- 我 愛 Andes -- ☆ PHYSICS:A HUMAN ENTERPRISE ☆           ★物理,全人類的事業★         -- ※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw) ◆ From: h12.s12.ts31.hi