Post Reply 
Complex Plotting App
02-13-2015, 02:52 AM
Post: #20
RE: Complex Plotting App
Color scheme change (Red to Yellow for now by limiting hue space range to 1/6 the original.. for black to red to yellow I think we have to define some other color space other than HSV which I am using now) plus some minor modifications:

1. define r as local in Plot() since I prefer overriding the plot key as was in the original code by danielmewes.
2. Flip Y axis
3. tune rangee to improve contours and logarithmic abs value tracking mask (I think both r and initial rangeee values should be configurable.. later on maybe we will implement setup screen)
4. also fixed RE contour to grey and IM contour to white for this version.

Example plot of (X+2)^2*(X-1-2*i)*(X+i), in the range +/- 4, +/- 3i:
   

Code below:
Code:

// SetHSV() and GetColor() based on a
// c++ program from :
// http://commons.wikimedia.org/wiki/File:Color_complex_plot.jpg
// by Claudio Rocchini
// http://en.wikipedia.org/wiki/Domain_coloring

SetHSV(h,s,v);
GetColor(v);
EvalF();

EXPORT Plot()
BEGIN
  local x1,x2,y1,y2,co;
  local dx:=(Xmax-Xmin)/320;
  local dy:=(Ymax-Ymin)/240;
  local z1;
  local a,b,b1,d,k,x,y;
  local r:=4;  //r is size of initial square which is 2^r by 2^r pixels

  d:=2^r;
  FOR x FROM 0 TO 320-d STEP d DO
    FOR y FROM 0 TO 240-d STEP d DO
      z1:=Xmin+x*dx+i*(Ymin+(240-d-y)*dy);
      co:=EvalF(z1);
      RECT_P(G0,x,y,x+d-1,y+d-1,co); 
    END;
  END;
IF r THEN
  FOR k FROM 1 TO r DO
    d:=2^(r-k);
    FOR x FROM 0 TO 160/d-1 DO
      FOR y FROM 0 TO 120/d-1 DO
        a:=x*2*d; b:=y*2*d; b1:=(120/d-1-y)*2*d+d;
        z1:=Xmin+a*dx+i*(Ymin+b1*dy);
        co:=EvalF(z1);
        RECT_P(G0,a,b,a+d-1,b+d-1,co);
        z1:=z1+d*dx;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b,a+2*d-1,b+d-1,co);
        z1:=z1+i*d*dy;
        co:=EvalF(z1);
        RECT_P(G0,a+d,b-d,a+2*d-1,b-1,co);
      END;
    END;
  END;
END;

  FREEZE;
  WAIT(-1);
END;

EvalF(z)
BEGIN
  IF RE(z) THEN
    RETURN(GetColor(F1(z)));
  ELSE
    RETURN(GetColor(F1(z+.001)));
  END;
END;

SetHSV(h, s, v)
BEGIN
    LOCAL r, g, b;
    LOCAL z, f, p, q, t, i;

    IF(s==0) THEN
       r:=v;
       g:=v;
       b:=v;
    ELSE
        IF(h==1) THEN h := 0; END;
        z := FLOOR(h*6);
        i := IP(z);
        f := h*6 - z;
        p := v*(1-s);
        q := v*(1-s*f);
        t := v*(1-s*(1-f));

        CASE
        IF i==0 THEN r:=v; g:=t; b:=p; END;
        IF i==1 THEN r:=q; g:=v; b:=p; END;
        IF i==2 THEN r:=p; g:=v; b:=t; END;
        IF i==3 THEN r:=p; g:=q; b:=v; END;
        IF i==4 THEN r:=t; g:=p; b:=v; END;
        IF i==5 THEN r:=v; g:=p; b:=q; END;
        END;
    END;

    r :=MIN(255,IP(256*r));
    g :=MIN(255,IP(256*g));
    b :=MIN(255,IP(256*b));
    RETURN RGB(r,g,b);
END;

GetColor(v)
BEGIN
    LOCAL a:=0;
    LOCAL m,ranges,rangee,k,sat,val;

    IF v≠0 THEN a:=ARG(v); END;
    WHILE (a<0) DO a := a+ (2*π); END;
    a := a/(2*π);

// RE Contour
    m := ABS(RE(v));
    ranges := 0;
    rangee := 0.5;

    WHILE(m>rangee) DO
        ranges := rangee;
        rangee := rangee * e;
    END;

    k:=(m-ranges)/(rangee-ranges);
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;
    IF (val > 0.9999) OR (sat >0.9999) THEN 
      //return SetHSV(a/6,sat,val);
      return RGB(200,200,200); 
    END;

//IM Contour
    m := ABS(IM(v));
    ranges := 0;
    rangee := 0.5;

    WHILE(m>rangee) DO
        ranges := rangee;
        rangee := rangee * e;
    END;

    k:=(m-ranges)/(rangee-ranges);
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;
    IF (val > 0.9999) OR (sat >0.9999) THEN 
      //return SetHSV(a/6,sat,val);
      return RGB(255,255,255); 
    END;

//Domain Coloring
    m := ABS(v);
    ranges := 0;
    rangee := 0.01;

    WHILE(m>rangee) DO
        ranges := rangee;
        rangee := rangee * e;
    END;

    k:=(m-ranges)/(rangee-ranges);
    IF (k<0.5) THEN
        sat:=k*2;
    ELSE
        sat:=1 -(k -0.5) *2;
    END;
    val := sat;

    sat := 1 - (1-sat)^3; sat := 0.4 + sat*0.6;

    val := 1 - val;
    val := 1 - (1-val)^3;
    val := 0.6 + val*0.4;

    return SetHSV(a/6,sat,val);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Complex Plotting App - danielmewes - 12-30-2014, 09:17 AM
RE: Complex Plotting App - dwgg - 02-01-2015, 01:06 AM
RE: Complex Plotting App - Han - 02-01-2015, 04:01 AM
RE: Complex Plotting App - dwgg - 02-01-2015, 06:42 AM
RE: Complex Plotting App - Mark Hardman - 02-01-2015, 11:17 PM
RE: Complex Plotting App - dwgg - 02-02-2015, 03:43 PM
RE: Complex Plotting App - rprosperi - 02-02-2015, 04:54 PM
RE: Complex Plotting App - dwgg - 02-03-2015, 06:56 PM
RE: Complex Plotting App - danielmewes - 02-04-2015, 03:39 AM
RE: Complex Plotting App - dwgg - 02-06-2015, 04:21 AM
RE: Complex Plotting App - Han - 02-06-2015, 08:17 PM
RE: Complex Plotting App - Han - 02-07-2015, 06:02 AM
RE: Complex Plotting App - rprosperi - 02-07-2015, 03:38 PM
RE: Complex Plotting App - Han - 02-07-2015, 06:24 PM
RE: Complex Plotting App - rprosperi - 02-08-2015, 04:06 PM
RE: Complex Plotting App - Eddie W. Shore - 02-12-2015, 03:26 AM
RE: Complex Plotting App - rprosperi - 02-12-2015, 04:02 AM
RE: Complex Plotting App - Eddie W. Shore - 04-02-2015, 02:58 AM
RE: Complex Plotting App - Han - 04-02-2015, 12:10 PM
RE: Complex Plotting App - salvomic - 04-02-2015, 02:48 PM
RE: Complex Plotting App - Eddie W. Shore - 04-04-2015, 03:03 PM
RE: Complex Plotting App - dwgg - 02-12-2015, 06:29 AM
RE: Complex Plotting App - Han - 02-12-2015, 08:23 AM
RE: Complex Plotting App - dwgg - 02-13-2015 02:52 AM
RE: Complex Plotting App - Han - 02-13-2015, 10:04 PM
RE: Complex Plotting App - dwgg - 02-14-2015, 12:01 AM
RE: Complex Plotting App - dwgg - 02-14-2015, 11:43 AM
RE: Complex Plotting App - salvomic - 04-02-2015, 05:17 PM
RE: Complex Plotting App - Han - 04-02-2015, 05:40 PM
RE: Complex Plotting App - salvomic - 04-02-2015, 05:50 PM
RE: Complex Plotting App - Han - 02-14-2015, 07:14 PM
RE: Complex Plotting App - dwgg - 02-14-2015, 10:18 PM
RE: Complex Plotting App - Han - 02-17-2015, 01:34 AM
RE: Complex Plotting App - dwgg - 02-18-2015, 06:35 AM
RE: Complex Plotting App - Han - 02-18-2015, 04:41 PM
RE: Complex Plotting App - Han - 02-18-2015, 10:08 PM
RE: Complex Plotting App - dwgg - 02-19-2015, 02:06 AM
RE: Complex Plotting App - Han - 02-19-2015, 02:14 AM
RE: Complex Plotting App - Han - 03-17-2017, 07:28 PM
RE: Complex Plotting App - jtm - 06-30-2017, 03:48 AM
RE: Complex Plotting App - Han - 07-01-2017, 12:17 AM
RE: Complex Plotting App - FrankP - 12-25-2019, 12:26 PM



User(s) browsing this thread: 8 Guest(s)