Post Reply 
Complex Plotting App
12-25-2019, 12:26 PM
Post: #42
RE: Complex Plotting App
My personal 3D color view skills have problems interpreting complex function characteristics from the domain coloring scheme. Therefore, I played around with one imaginary and one real color intensity mapped directly linear to a given value range. Additionally the RGB color scheme is changed from ABS related black/white to real/imaginary related blue/red combination for values above a threshold value 'amin':
  • ABS(f(X)) < amin:
    white..black #000000..#FFFFFF = ABS(f(X)) 0 ...amin
  • ABS(f(X)) > amin:
    red #0000xx..#FF00xx = IM(f(X)) ymin...ymax
    blue #xx0000..#xx00FF = RE(f(X)) xmin...xmax
    black #000000 = IM(f(X)) < ymin and RE(f(X)) < xmin
    magenta #FF00FF = IM(f(X)) > ymax and RE(f(X)) > xmax
Axis and value display by tap and movement is added to the output graph. Below the code tested with Virtual Calculator 2.1.14181 (2018 10 16) on win 8 and 2.1.14294 (2019 10 25) on Android 7.1. Maybe useful for some of you.

Code:

#pragma mode( separator(.,;) integer(h-32) )

//EXPORT fX:="X^3"; // X gets x+i*y
//EXPORT xmin:=-5, xmax:=5, ymin:= −5, ymax:=5;
//EXPORT rmin:=-100, rmax:=350, imin:=-100, imax:=100;

//EXPORT fX:="Zeta(X)";
//EXPORT xmin:=−2, xmax:=1, ymin:=−4, ymax:=24;
//EXPORT rmin:=-4, rmax:=6, imin:=-4, imax:=6;

EXPORT fX:="(X+2)^2*(X-1-2*)*(X+)";
EXPORT xmin:=−4, xmax:=4, ymin:=−3, ymax:=3;
EXPORT rmin:=-100, rmax:=100, imin:=-100, imax:=100;

EXPORT amin:=0.1;
LOCAL  fxiy:=replace(fX,"X","(xmin+xi*x + *(ymax-yi*y))");
LOCAL  dx, dy, dreal, dimag, dabs;

PlotRes(r);

EXPORT Plot()
BEGIN
LOCAL mymouse,mykey,entr,x,y;

 entr:=Entry; Entry:=1; // avoid textbook entry interpretation of fX
 IF input(
    { {fX,  [2],{10,90,0}},
      {xmin,[0],{30,15,1}},
      {xmax,[0],{80,15,1}},
      {ymin,[0],{30,15,2}},
      {ymax,[0],{80,15,2}},
      {rmin,[0],{30,15,3}},
      {rmax,[0],{80,15,3}},
      {imin,[0],{30,15,4}},
      {imax,[0],{80,15,4}},
      {amin,[0],{30,15,5}}
    },
    "Complex Plot Setup",
    {
      "f(X)",
      "Xmin=", "Xmax=",
      "Ymin=", "Ymax=",
      "REmin", "REmax",
      "IMmin", "IMmax", 
      "min|f(X)|"
    },
    { "Enter function (X as independant)",
      "Enter minimum horizontal value",
      "Enter maximum horizontal value",
      "Enter minimum vertical value",
      "Enter maximum vertical value",
      "Enter minimum real f(X) value",
      "Enter maximum real f(X) value",
      "Enter minimum imaginary f(X) value",
      "Enter maximum imaginary f(X) value",
      "Switch from BlackWhite ABS to RedBlue IM/RE"
     } )
 THEN
 
  RECT();
  fxiy:=replace(fX,"X","(xmin+dx*x + *(ymax-dy*y))");
  dx   :=(xmax-xmin)/320;
  dy   :=(ymax-ymin)/240;
  dreal:=255/(rmax-rmin);
  dimag:=255/(imax-imin);
  dabs :=255/(amin);

  PlotRes(16);
  // PlotRes(8);
  PlotRes(4);
  //PlotRes(2);
  //PlotRes(1);

  LINE_P(G0, 320/(xmin-xmax)*xmin, 0, 320/(xmin-xmax)*xmin, 240, #0); // y axis 
  LINE_P(G0, 0, 240/(ymax-ymin)*ymax, 320, 240/(ymax-ymin)*ymax, #0); // x axis

  TEXTOUT_P(" ESC to cancel. Tap + directional pad to show values.                  ",G0,0,0,2, #0h,500,#FFFFFF);
 
  // black text shadow ...
  TEXTOUT_P(xmin+","+ymax, G0,                              0+1,     13+1, 1, #0);
  TEXTOUT_P(xmin+","+ymin, G0,                              0+1, 240-10+1, 1, #0);
  TEXTOUT_P(xmax+","+ymax, G0, 320-size(str(xmax+","+ymax))*4+1,     13+1, 1, #0);
  TEXTOUT_P(xmax+","+ymin, G0, 320-size(str(xmax+","+ymin))*4+1, 240-10+1, 1, #0);
  // ... and white text to sign (x,y) edge values
  TEXTOUT_P(xmin+","+ymax, G0,                              0  ,     13  , 1, #FFFFFF);
  TEXTOUT_P(xmin+","+ymin, G0,                              0  , 240-10  , 1, #FFFFFF);
  TEXTOUT_P(xmax+","+ymax, G0, 320-size(str(xmax+","+ymax))*4  ,     13  , 1, #FFFFFF);
  TEXTOUT_P(xmax+","+ymin, G0, 320-size(str(xmax+","+ymin))*4  , 240-10  , 1, #FFFFFF);

  x:=−3; y:=-3; // avoid 1st inversion by position out of screen
  WHILE 1 DO
   mymouse:= mouse();
   mykey:=getkey(); 
   IF size(mymouse(1)) OR mykey≠−1 then // mouse activ
    INVERT_P(G0, x-1,y-1,x+1,y+1); // revert previous mark
    CASE 
     IF mykey== 2 THEN y := y-2; END; // up
     IF mykey==12 THEN y := y+2; END; // down
     IF mykey== 7 THEN x := x-2; END; // left
     IF mykey== 8 THEN x := x+2; END; // right
     IF mykey== 4 THEN RETURN; END; // esc
     IF mykey==-1 THEN // no key thus we arrived here by a tap
      x := mymouse(1,1);
      y := mymouse(1,2); 
     END;
    END;
    TEXTOUT_P(" ESC to cancel.    f (  "+TRUNCATE(xmin+dx*x + *(ymax-dy*y),-3)+"   ) =   "+
                                         TRUNCATE( CAS(EVAL(fxiy)),-3 )+"          ",
              G0,0,0,2, #0h,500,#FFFFFFh  );
    INVERT_P(G0, x-1,y-1,x+1,y+1); // mark by color inversion
   END;
  END; // while
 END; // input
 Entry:=entr;
END;

LOCAL PlotRes(r)
BEGIN
LOCAL x,y,color;

 FOR x FROM 0 TO 320-r STEP r DO
  FOR y FROM 0 TO 240-r STEP r DO
   TEXTOUT_P(" ESC to cancel. Plot col "+x+"/320, row "+y+"/240, resolution "+r+".                  ", G0,0,0,2, #0h,500,#FFFFFFh  );
   CASE
    IF ( ABS( CAS(EVAL( fxiy )) ) < amin ) THEN
     color:=RGB( MIN( 255, 255-(ABS( CAS(EVAL( fxiy )) )*dabs) ),
                 MIN( 255, 255-(ABS( CAS(EVAL( fxiy )) )*dabs) ),
                 MIN( 255, 255-(ABS( CAS(EVAL( fxiy )) )*dabs) ) );
    END;
    DEFAULT
     color:=RGB( MIN( 255, MAX(0, (  IM( CAS(EVAL(fxiy)) )-imin  )*dimag) ),
                 0,
                 MIN( 255, MAX(0, (  RE( CAS(EVAL(fxiy)) )-rmin  )*dreal) ) );
   END;
   RECT_P(G0,x,y,x+r-1,y+r-1,color);
   IF ISKEYDOWN(4) THEN RETURN; END;
  END;
 END;
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: 2 Guest(s)