Color plot of complex function (x^2-1) * (x-2-I)^2 / (x^2+2+2I), hue represents the argument, sat and value represents the modulus
วันที่
แหล่งที่มา
งานของตัว
ผู้สร้างสรรค์
Claudio Rocchini
การอนุญาต (การใช้ไฟล์นี้ใหม่)
CC-BY 2.5
เวอร์ชันอื่น
Source Code
C++
This is the complete C++ source code for image generation (you must change the fun funcion to plot another one). You need some complex class implementation.
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<complex.h>// floor /* based on c++ program from :[[:File:Color_complex_plot.jpg]]by Claudio Rocchinigcc d.c -lm -Wallhttp://en.wikipedia.org/wiki/Domain_coloring*/constdoublePI=3.1415926535897932384626433832795;constdoubleE=2.7182818284590452353602874713527;/*complex domain coloring Given a complex number z=re^{ i \theta}, hue represents the argument ( phase, theta ), sat and value represents the modulus*/intGiveHSV(doublecomplexz,doubleHSVcolor[3]){//The HSV, or HSB, model describes colors in terms of hue, saturation, and value (brightness).// hue = f(argument(z))//hue values range from .. to ..doublea=carg(z);//while(a<0)a+=2*PI;a/=2*PI;// radius of zdoublem=cabs(z);// doubleranges=0;doublerangee=1;while(m>rangee){ranges=rangee;rangee*=E;}doublek=(m-ranges)/(rangee-ranges);// saturation = g(abs(z))doublesat=k<0.5?k*2:1-(k-0.5)*2;sat=1-pow((1-sat),3);sat=0.4+sat*0.6;// value = h(abs(z))doubleval=k<0.5?k*2:1-(k-0.5)*2;val=1-val;val=1-pow((1-val),3);val=0.6+val*0.4;HSVcolor[0]=a;HSVcolor[1]=sat;HSVcolor[2]=val;return0;}intGiveRGBfromHSV(doubleHSVcolor[3],unsignedcharRGBcolor[3]){doubler,g,b;doubleh;doubles;doublev;h=HSVcolor[0];// hue s=HSVcolor[1];// saturation;v=HSVcolor[2];// = value;if(s==0)r=g=b=v;else{if(h==1)h=0;doublez=floor(h*6);inti=(int)z;doublef=(h*6-z);doublep=v*(1-s);doubleq=v*(1-s*f);doublet=v*(1-s*(1-f));switch(i){case0:r=v;g=t;b=p;break;case1:r=q;g=v;b=p;break;case2:r=p;g=v;b=t;break;case3:r=p;g=q;b=v;break;case4:r=t;g=p;b=v;break;case5:r=v;g=p;b=q;break;}}intc;c=(int)(256*r);if(c>255)c=255;RGBcolor[0]=c;c=(int)(256*g);if(c>255)c=255;RGBcolor[1]=c;c=(int)(256*b);if(c>255)c=255;RGBcolor[2]=c;return0;}intGiveRGBColor(doublecomplexz,unsignedcharRGBcolor[3]){staticdoubleHSVcolor[3];GiveHSV(z,HSVcolor);GiveRGBfromHSV(HSVcolor,RGBcolor);return0;}// doublecomplexfun(doublecomplexc){return(cpow(c,2)-1)*cpow(c-2.0-I,2)/(cpow(c,2)+2+2*I);}// intmain(){// screen (integer ) coordinateconstintdimx=800;constintdimy=800;// world ( double) coordinateconstdoublereMin=-2;constdoublereMax=2;constdoubleimMin=-2;constdoubleimMax=2;staticunsignedcharRGBcolor[3];FILE*fp;char*filename="complex.ppm";fp=fopen(filename,"wb");fprintf(fp,"P6\n%d %d\n255\n",dimx,dimy);inti,j;for(j=0;j<dimy;++j){doubleim=imMax-(imMax-imMin)*j/(dimy-1);for(i=0;i<dimx;++i){doublere=reMax-(reMax-reMin)*i/(dimx-1);doublecomplexz=re+im*I;// doublecomplexv=fun(z);// GiveRGBColor(v,RGBcolor);fwrite(RGBcolor,1,3,fp);}}fclose(fp);printf("OK - file %s saved\n",filename);return0;}
{{Information |Description=Color plot of complex function (x^2-1) * (x-2-I)^2 / (x^2+2+2I), hue represents the argument, sat and value represents the modulo |Source=Own work |Date=2007-08-07 |Author=Claudio Rocchini |Permission=CC-BY 2.5 }}
ไฟล, color, complex, plot, ไฟล, ประว, ไฟล, หน, าท, ภาพน, การใช, ไฟล, วนกลางขนาดของต, วอย, างน, กเซล, ความละเอ, ยดอ, กเซล, กเซล, ภาพท, ความละเอ, ยดส, งกว, 8206, กเซล, ขนาดไฟล, โลไบต, ชน, ดไมม, image, jpeg, ปภาพหร, อไฟล, เส, ยงน, นฉบ, บอย, คอมมอนส, รายละเอ, ยดด,. ifl prawtiifl hnathimiphaphni karichiflswnklangkhnadkhxngtwxyangni 600 600 phikesl khwamlaexiydxun 240 240 phikesl 480 480 phikesl duphaphthimikhwamlaexiydsungkwa 8206 800 800 phikesl khnadifl 203 kiolibt chnidimm image jpeg rupphaphhruxiflesiyngni tnchbbxyuthi khxmmxns raylaexiyddanlang epnkhxkhwamthiaesdngphlcak ifltnchbbinkhxmmxns khxmmxnsepnewbistinokhrngkarsahrbekbrwbrwmsuxesri thi khunsamarthchwyid enuxha 1 khwamyx 2 Source Code 2 1 C 2 2 C 3 karxnuyatichsiththi khwamyx khaxthibayColor complex plot jpg Color plot of complex function x 2 1 x 2 I 2 x 2 2 2I hue represents the argument sat and value represents the moduluswnthi 7 singhakhm ph s 2550aehlngthima ngankhxngtwphusrangsrrkh Claudio Rocchinikarxnuyat karichiflniihm CC BY 2 5ewxrchnxun Source Code C This is the complete C source code for image generation you must change the fun funcion to plot another one You need some complex class implementation include lt complex gt include lt fstream gt using namespace std const double PI 3 1415926535897932384626433832795 const double E 2 7182818284590452353602874713527 void SetHSV double h double s double v unsigned char color 3 double r g b if s 0 r g b v else if h 1 h 0 double z floor h 6 int i int z double f double h 6 z double p v 1 s double q v 1 s f double t v 1 s 1 f switch i case 0 r v g t b p break case 1 r q g v b p break case 2 r p g v b t break case 3 r p g q b v break case 4 r t g p b v break case 5 r v g p b q break int c c int 256 r if c gt 255 c 255 color 0 c c int 256 g if c gt 255 c 255 color 1 c c int 256 b if c gt 255 c 255 color 2 c complex lt double gt fun complex lt double gt amp c const complex lt double gt i 0 1 return pow c 2 1 pow c 2 i 2 pow c 2 2 2 i int main const int dimx 800 const int dimy 800 const double rmi 3 const double rma 3 const double imi 3 const double ima 3 ofstream f complex ppm ios binary f lt lt P6 lt lt endl lt lt dimx lt lt lt lt dimy lt lt endl lt lt 255 lt lt endl for int j 0 j lt dimy j double im ima ima imi j dimy 1 for int i 0 i lt dimx i double re rma rma rmi i dimx 1 complex lt double gt c re im complex lt double gt v fun c double a arg v while a lt 0 a 2 PI a 2 PI double m abs v double ranges 0 double rangee 1 while m gt rangee ranges rangee rangee E double k m ranges rangee ranges double sat k lt 0 5 k 2 1 k 0 5 2 sat 1 pow 1 sat 3 sat 0 4 sat 0 6 double val k lt 0 5 k 2 1 k 0 5 2 val 1 val val 1 pow 1 val 3 val 0 6 val 0 4 unsigned char color 3 SetHSV a sat val color f write const char color 3 return 0 C include lt stdio h gt include lt stdlib h gt include lt math h gt include lt complex h gt floor based on c program from File Color complex plot jpg by Claudio Rocchini gcc d c lm Wall http en wikipedia org wiki Domain coloring const double PI 3 1415926535897932384626433832795 const double E 2 7182818284590452353602874713527 complex domain coloring Given a complex number z re i theta hue represents the argument phase theta sat and value represents the modulus int GiveHSV double complex z double HSVcolor 3 The HSV or HSB model describes colors in terms of hue saturation and value brightness hue f argument z hue values range from to double a carg z while a lt 0 a 2 PI a 2 PI radius of z double m cabs z double ranges 0 double rangee 1 while m gt rangee ranges rangee rangee E double k m ranges rangee ranges saturation g abs z double sat k lt 0 5 k 2 1 k 0 5 2 sat 1 pow 1 sat 3 sat 0 4 sat 0 6 value h abs z double val k lt 0 5 k 2 1 k 0 5 2 val 1 val val 1 pow 1 val 3 val 0 6 val 0 4 HSVcolor 0 a HSVcolor 1 sat HSVcolor 2 val return 0 int GiveRGBfromHSV double HSVcolor 3 unsigned char RGBcolor 3 double r g b double h double s double v h HSVcolor 0 hue s HSVcolor 1 saturation v HSVcolor 2 value if s 0 r g b v else if h 1 h 0 double z floor h 6 int i int z double f h 6 z double p v 1 s double q v 1 s f double t v 1 s 1 f switch i case 0 r v g t b p break case 1 r q g v b p break case 2 r p g v b t break case 3 r p g q b v break case 4 r t g p b v break case 5 r v g p b q break int c c int 256 r if c gt 255 c 255 RGBcolor 0 c c int 256 g if c gt 255 c 255 RGBcolor 1 c c int 256 b if c gt 255 c 255 RGBcolor 2 c return 0 int GiveRGBColor double complex z unsigned char RGBcolor 3 static double HSVcolor 3 GiveHSV z HSVcolor GiveRGBfromHSV HSVcolor RGBcolor return 0 double complex fun double complex c return cpow c 2 1 cpow c 2 0 I 2 cpow c 2 2 2 I int main screen integer coordinate const int dimx 800 const int dimy 800 world double coordinate const double reMin 2 const double reMax 2 const double imMin 2 const double imMax 2 static unsigned char RGBcolor 3 FILE fp char filename complex ppm fp fopen filename wb fprintf fp P6 n d d n 255 n dimx dimy int i j for j 0 j lt dimy j double im imMax imMax imMin j dimy 1 for i 0 i lt dimx i double re reMax reMax reMin i dimx 1 double complex z re im I double complex v fun z GiveRGBColor v RGBcolor fwrite RGBcolor 1 3 fp fclose fp printf OK file s saved n filename return 0 karxnuyatichsiththi khapheca inthanaphuthuxlikhsiththikhxngphaphhruxsuxni xnuyatihichphaphhruxsuxniphayitenguxnikhtxipni xnuyatihkhdlxk aeckcayaela hruxddaeprexksarniphayitenguxnikhkhxngsyyaxnuyatexksaresrikhxngknu run 1 2 hruxrunid nbcaknithixxkodymulnithisxftaewresri odyimmiswnidhamaekikh immikhxkhwampkhnaaelapkhlng saenakhxngsyyaxnuyatrwmxyuinswnchux syyaxnuyatexksaresrikhxngknuhttp www gnu org copyleft fdl html GFDL GNU Free Documentation License true trueiflnixyuphayitsyyaxnuyat khriexthifkhxmmxns aebbaesdngthima xnuyataebbediywkn 3 0 tnchbbkhunsamarth thicaaebngpn thicathasaena aeckcay aelasngngandngklawtxip thicaeriyberiyngihm thicaddaeplngngandngklaw phayitenguxnikhtxipni aesdngthima khuntxngihekiyrtiecakhxngnganxyangehmaasm odyephimlingkipyngsyyaxnuyat aelarabuhakmikarepliynaeplng khunxacthaechnniidinrupaebbidkidtamkhwr aettxngimichinlksnathiaenawaphuihxnuyatsnbsnunkhunhruxkarichngankhxngkhun xnuyataebbediywkn hakkhunddaeplng epliynrup hruxtxetimnganni khuntxngichsyyaxnuyataebbediywknhruxaebbthiehmuxnkbsyyaxnuyatthiichkbnganniethannpayaesdngsthanalikhsiththinithukephimephuxihepniptamkarepliynaeplngsyyaxnuyatkhxngmulnithiwikimiediy cak GFDL ipyng GFDL khwbkhukb CC BY SA 3 0 http creativecommons org licenses by sa 3 0 CC BY SA 3 0 Creative Commons Attribution Share Alike 3 0 true trueiflnixyuphayitsyyaxnuyatkhriexthifkhxmmxns runaesdngthima 2 5 thwipkhunsamarth thicaaebngpn thicathasaena aeckcay aelasngngandngklawtxip thicaeriyberiyngihm thicaddaeplngngandngklaw phayitenguxnikhtxipni aesdngthima khuntxngihekiyrtiecakhxngnganxyangehmaasm odyephimlingkipyngsyyaxnuyat aelarabuhakmikarepliynaeplng khunxacthaechnniidinrupaebbidkidtamkhwr aettxngimichinlksnathiaenawaphuihxnuyatsnbsnunkhunhruxkarichngankhxngkhunhttps creativecommons org licenses by 2 5 CC BY 2 5 Creative Commons Attribution 2 5 true truekhunsamartheluxksyyaxnuyatdngklawtamtxngkarkhabrryayodyyxithyephimkhabrryaythrrthdediywephuxkhyaykhwamwaiflnimixairxngkvsColor wheel graph of the function f x x 2 1 x 2 i 2 x 2 2 2i ixethmthiaesdngxyuiniflniprakxbdwyphusrangbangkhathiimmiixethmwikisnethschuxphusrangsrrkh Claudio Rocchiniyuxaraexl https commons wikimedia org wiki user Rocchinichuxphuichwikimiediy RocchinisthanalikhsiththimilikhsiththisyyaxnuyatGNU Free Documentation License version 1 2 or later xngkvsCreative Commons Attribution ShareAlike 3 0 Unported xngkvsCreative Commons Attribution 2 5 Generic xngkvswnthisrang wnkxtng7 singhakhm 2007thimakhxngiflkarsrangdngedimodyphuxpohld prawtiifl khlikwnthi ewlaephuxduiflthipraktinkhnann wnthi ewlarupyxkhnadphuichkhwamehn pccubn06 06 23 minakhm 2556800 800 203 kiolibt YourmomblahHigher quality 16 46 7 singhakhm 2550800 800 59 kiolibt Rocchini Information Description Color plot of complex function x 2 1 x 2 I 2 x 2 2 2I hue represents the argument sat and value represents the modulo Source Own work Date 2007 08 07 Author Claudio Rocchini Permission CC BY 2 5 hnathimiphaphni hnatxipni oyngmathiphaphni karwiekhraahechingsxn karichiflswnklang wikixuntxipniichiflni karichbn ar wikipedia org تحليل عقدي karichbn ast wikipedia org Analis complexu karichbn be wikipedia org Kampleksny analiz karichbn bn wikipedia org জট ল স খ য karichbn ckb wikipedia org شیکاریی ئاوێتە karichbn cs wikipedia org Komplexni analyza karichbn cy wikipedia org Dadansoddi cymhlyg karichbn da wikipedia org Kompleks analyse karichbn en wikipedia org User Rocchini User talk Rocchini karichbn en wikibooks org Color Theory Color gradient karichbn en wikiversity org User Jtneill Gallery karichbn es wikipedia org Analisis complejo karichbn eu wikipedia org Analisi konplexu karichbn fa wikipedia org آنالیز مختلط karichbn gl wikipedia org Analise complexa karichbn hi wikipedia org गण त य व श ल षण सम म श र व श ल षण karichbn it wikipedia org Analisi complessa Mappa conforme Analisi matematica Colorazione del dominio karichbn it wikibooks org Analisi complessa Copertina karichbn ja wikipedia org 複素解析 karichbn lv wikipedia org Komplekss skaitlis karichbn mn wikipedia org Hereglegch Timur Noorog Kompleks analiz karichbn mt wikipedia org Analisi komplessa karichbn nl wikipedia org Functietheorie karichbn pl wikipedia org Liczby zespolone Matematyka karichbn pl wikibooks org C Czytanie i pisanie do plikow C Wersja do druku Programowanie w systemie UNIX c grafika karichbn si wikipedia org ස ක ර ණ ව ශ ල ෂණය ස ක ර ණ ස ඛ ය karichbn sk wikipedia org Komplexna analyza Portal Matematika Odporucane clanky 2011 Portal Matematika Odporucany clanok 17 2011 Portal Matematika Odporucany clanok 52 2011 Portal Matematika Obrazky tyzdna Univerzalne Portal Matematika Obrazok tyzdna 53 karichbn sq wikipedia org Analiza komplekse karichbn sr wikipedia org Kompleksna analiza karichbn sv wikipedia org Komplex analys karichbn tr wikipedia org Karmasik sayi Karmasik analiz karichbn uk wikipedia org Kompleksnij analiz Umovi Koshi Rimana karichbn ur wikipedia org مختلط تحلیل karichbn zh wikipedia org 定義域著色 dukarichthwolkephimetimkhxngiflni ekhathungcak https th wikipedia org wiki ifl Color complex plot jpg, wikipedia, วิกิ หนังสือ, หนังสือ, ห้องสมุด,