Image:Colour complex plot.jpg

From Wikipedia, the free encyclopedia

Wikimedia Commons logo This is a file from the Wikimedia Commons. The description on its description page there is shown below.
Commons is a freely licensed media file repository. You can help.

Dettagli

Description

Colour 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
( Reusing this image)

CC-BY 2.5


Source Code

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 <float.h>
 
const double PI = 3.1415926535897932384626433832795;
const double E  = 2.7182818284590452353602874713527;
 
#include <complex.h>
 
void SetHSV( double h, double s, double v, unsigned char colour[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>255) c = 255; colour[0] = c;
        c = int(256*g); if(c>255) c = 255; colour[1] = c;
        c = int(256*b); if(c>255) c = 255; colour[2] = c;
}
 
complex fun( complex & c ){
        return (c^0.5)*((1-c)^0.5);
}
 
int main(){
        const int dimx = 800; const int dimy = 800;
        const double rmi = -2; const double rma =  2;
        const double imi = -2; const double ima =  2;
 
        FILE * fp = fopen("complex.ppm","wb");
        fprintf(fp,"P6\n%d %d\n255\n",dimx,dimy);
 
        int i,j;
        for(j=0;j<dimy;++j){
                double im = ima - (ima-imi)*j/(dimy-1);
                for(i=0;i<dimx;++i){               
                        double re = rma - (rma-rmi)*i/(dimx-1);
                        complex c(re,im);
                        complex v = fun(c);   
                        double a = v.arg();
                        while(a<0) a += 2*PI; a /= 2*PI;
                        double m = v.mod();
                        double ranges = 0;
                        double rangee = 1;
                        while(m>rangee){
                                ranges = rangee;
                                rangee *= E;
                        }
                        double k = (m-ranges)/(rangee-ranges);
                        double sat = k<0.5 ? k*2: 1 - (k-0.5)*2;
                        sat = 1 - pow( (1-sat), 3); sat = 0.4 + sat*0.6;
                        double val = 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;
                        static unsigned char colour[3];
                        SetHSV(a,sat,val,colour);
                        fwrite(colour,1,3,fp);
                }
        }
        fclose(fp);
        return 0;
}

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation license, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled " GNU Free Documentation license".

Aragonés | العربية | Asturianu | Беларуская (тарашкевіца) | Български | বাংলা | ইমার ঠার/বিষ্ণুপ্রিয়া মণিপুরী | Brezhoneg | Bosanski | Català | Cebuano | Česky | Dansk | Deutsch | Ελληνικά | English | Esperanto | Español | Eesti | Euskara | فارسی | Suomi | Français | Gaeilge | Galego | עברית | Hrvatski | Magyar | Bahasa Indonesia | Ido | Íslenska | Italiano | 日本語 | ქართული | ភាសាខ្មែរ | 한국어 | Kurdî / كوردی | Latina | Lëtzebuergesch | Lietuvių | Bahasa Melayu | Nnapulitano | Nederlands | ‪Norsk (nynorsk)‬ | ‪Norsk (bokmål)‬ | Occitan | Polski | Português | Română | Русский | Slovenčina | Slovenščina | Shqip | Српски / Srpski | Svenska | తెలుగు | ไทย | Tagalog | Türkçe | Українська | اردو | Tiếng Việt | Volapük | Yorùbá | ‪中文(简体)‬ | ‪中文(繁體)‬ | +/-

Creative Commons License
Creative Commons Attribution icon
This file is licensed under Creative Commons Attribution 2.5 License
In short: you are free to distribute and modify the file as long as you attribute its author(s) or licensor(s).

You may select the license of your choice.

File history

Click on a date/time to view the file as it appeared at that time.

Date/Time Dimensions User Comment
current 09:46, 7 August 2007 800×800 (59 KB) Rocchini ({{Information |Description=Colour 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 }} )
The following pages on Schools Wikipedia link to this image (list may be incomplete):
The Schools Wikipedia was sponsored by a UK Children's Charity, SOS Children UK , and is a hand-chosen selection of article versions from the English Wikipedia edited only by deletion (see www.wikipedia.org for details of authors and sources). See also our Disclaimer.