NB. nplot (Nishikawa's plot tool) by T.Nishikawa 2008/2/22, 2/29 NB. multi graphs and coloring 2008/3/1 NB. npotpm = plus-minus plotting 2008/3/3 NB. zooming graph and scale 2008/3/5 NB. plot math function values, enable scaling and multi graphs draw NB. Usage: ============================================================================== NB. Set Scanning Range & Interval on X: NB. X =: steps _5 5 100 NB. Zooming Factor: NB. zf =: 150 NB. Exaple: nplot X,.(0.025*X^5)+(0.05*X^4)+(_0.6*X^3)+(_0.55*X^2)+(2.575*X)+(_1.5) NB. y=x^3-x+1: nplot X,. (X^3) + (-X) + (1) NB. (255 0 0) nplot X, (X^3) + (-X) + (1) NB. Sin_Curve: nplot X,.sin X NB. Rectangular Hyperbolic: nplot X,. 1%X NB. y=sqrt(x+2): nplot X,. %: X + 2 NB. YSQ =: %: X + 2 NB. nplot (X,.YSQ);(X,.-YSQ) NB. plus-minus plot: nplotpm X,.YSQ NB. red_line plot: (255 0 0) nplotpm X,.YSQ NB. ellipse: nplot (X,.YELLIP4);(X,.-YELLIP4) NB. COLOR nplotpm (X,.YELLIP3);(X,.YELLIP4);(X,.YELLIP5) NB. lemniscate: nplot (X,.YLEM16);(X,.-YLEM16) NB. nplotpm (X,.YLEM8);(X,.YLEM16);(X,.YLEM32) NB. COLOR nplotpm (X,.YLEM8);(X,.YLEM12);(X,.YLEM16);(X,.YLEM32) NB. ===================================================================================== NB. set range and interval require 'numeric trig' range =: _10 10 interval =: 200 X =: steps range, interval NB. _4 to 4 divided in 200 intervals NB. set zoom factor(zf) zf =: 150 NB. defaul: zf = 150 NB. change zoom factor NB. e.g. zoom 75(zoom_out), zoom 200(zoom_in) zoom =: 3 : 0 zf =: y. ) NB. adjust math values to pixels val2pixel =: 3 : 0 500 + zf * y. ) require 'gl2' NB. not require 'isigraph' NB. ngopen: renamed from gopen of isimain.ijs NB. open graphics window NB. y. = controlname;parentname NB. if either empty, default to 'isigraph' NB. e.g ngopen '' NB. ngopen '';'J Graphics' ngopen=: 3 : 0 y=: 2{.}.0;y. 'c n'=: (<'isigraph') ((# i.@#)y=<'') }y if. ( 0 2 0 3 0 NB. imaginary to zero im2z =: 3 : 0"0 imf =. 0 ~: {:"(1) +. y. imx =. imf # i.# y. 0 imx } y. ) NB. Examples ================================================================= NB. Square Root Function Curve YSQ =: %: X + 2 NB. nplot X,.YSQ NB. nplot (X,. YSQ);(X,. -YSQ) NB. Lemniscate Curve NB. Lemniscate Solution lemni =: 3 : 0"0 : x =. y. m =. x. r =. (-x^2) + _4 + %: (16 * x^2) + m if. r >: 0 do. %: r else. 0 end. ) YLEM8 =: 8 lemni X YLEM12 =: 12 lemni X YLEM16 =: 16 lemni X YLEM32 =: 32 lemni X NB. nplot (X,.YLEM16);(X,.-YLEM16) NB. Ellipse of Focii(_1, 0) and (1, 0) ellip =: 3 : 0"0 : x =. y. m =. x. r =. (-x^2) + _4 + 2*m if. r >: 0 do. -: %: r else. 0 end. ) YELLIP3 =: 3 ellip X YELLIP4 =: 4 ellip X YELLIP5 =: 5 ellip X NB. Color Data COLOR =: (255 0 0);(0 255 0);(0 0 255);(125 125 0) BLACK =: (0 0 0);(0 0 0);(0 0 0) NB. plot ======================================================================== nplot =: 3 : 0 NB. required draw subroutine if. 2 = $$y. do. 0 0 0 nplot y. else. BLACK nplot y. end. : ngopen 'isigraph';'nplot' if. 2 = $$y. do. x. draw im2z y. else. i =. 0 while. i < #y. do. yi =. im2z > i{y. xi =. > i{x. xi draw yi i =. i + 1 end. end. grid '' glshow '' ) NB. plus-minus plot ============================================================ nplotpm =: 3 : 0 NB. required draw subroutine if. 2 = $$y. do. 0 0 0 nplotpm y. else. BLACK nplotpm y. end. : ngopen 'isigraph';'nplot' if. 2 = $$y. do. X =. {."1 y. Y =. im2z {:"1 y. x. draw X,.Y x. draw X,.-Y else. i =. 0 while. i < #y. do. yi =. > i{y. xi =. > i{x. X =. {."(1) yi Y =. im2z {:"(1) yi xi draw X,.Y xi draw X,.-Y i =. i + 1 end. end. grid '' glshow '' ) draw =: 3 : 0 : DD =. val2pixel y. DA =. , (*/"(1) 0 <: DD) # DD glrgb x. glpen 1 0 gllines | DA ) NB. =========================================================================== NB. nplot_lemnis 16 nplot_lemnis =: 3 : 0 ngopen 'isigraph';'nplot' grid '' M =. y. Y16P =. M lemni X XY16P =. X,.Y16P XYP =. >. val2pixel , XY16P glines XYP NB. nplot XYP Y16M =. - M lemni X XY16M =. X,.Y16M XYM =. >. val2pixel , XY16M glines XYM glshow '' ) lemnis =: 3 : 0 m =. y. YYP =. m lemni X XYP =. X,.YYP GP =. >. val2pixel , XYP YYM =. - m lemni X XYM =. X,.YYM GM =. >. val2pixel , XYM GP;GM ) NB. nplem 4 8 16 32 nplem =: 3 : 0 m =. y. ngopen 'isigraph';'nplot' grid '' i =. 0 while. i < #m do. 'GP GM' =. lemnis i{m glines GP glines GM i =. i + 1 end. gshow '' ) NB. axis, grid and numbering NB. required wrtxt subroutine grid =: 3 : 0 glrgb 0 0 0 glpen 1 0 NB. draw axes ----------------------------------------------------------------------- gllines 0, 500, 1000, 500 NB. x-axis gllines 500, 0, 500, 1000 NB. y-axis NB. draw scale grid ----------------------------------------------------------------- ns =: 9 nsp =: >: i. ns nsm =: - >: i. ns gllines L:0 <"(1) ((val2pixel nsp),.490) ,. ((val2pixel nsp),.510) NB. xp-grid gllines L:0 <"(1) ((val2pixel nsm),.490) ,. ((val2pixel nsm),.510) NB. xm-grid gllines L:0 <"(1) (490,.(val2pixel nsp)) ,. (510,.(val2pixel nsp)) NB. yp-grid gllines L:0 <"(1) (490,.(val2pixel nsm)) ,. (510,.(val2pixel nsm)) NB. ym-grid NB. numbering scale grid --2008/3/5-------------------------------------------------- XPG =: _2<\"(1) (_10 + (val2pixel nsp),."(0) 490),. nsp NB. xp-number XMG =: _2<\"(1) (_10 + (val2pixel nsm),."(0) 490),. nsm NB. xm-number YPG =: _2<\"(1) (460,. (10 + val2pixel nsp)),. nsp NB. yp-number YMG =: _2<\"(1) (440,. (10 + val2pixel nsm)),. nsm NB. ym-number XYG =: XPG, XMG, YPG, YMG i =. 0 while. i < #XYG do. wrtxt i{XYG i =. i + 1 end. glshow '' NB. Old Version -------------------------------------------------------------------------- NB. gltextxy (490 + 150), 490 NB. numbering on x-axis NB. gltext '1' NB. gltextxy (490 + 2*150), 490 NB. gltext '2' NB. gltextxy (490 + 3*150), 490 NB. gltext '3' NB. gltextxy 30, 490 NB. gltext '_3' NB. gltextxy (30 + 150), 490 NB. gltext '_2' NB. gltextxy (30 + 300), 490 NB. gltext '_1' NB. gltextxy 460, (500 + 160) NB. numbering on y-axis NB. gltext '1' NB. gltextxy 460, (500 + 320) NB. gltext '2' NB. gltextxy 460, (500 + 480) NB. gltext '3' NB. gltextxy 440, (540 - 160) NB. numbering on y-axis NB. gltext '_1' NB. gltextxy 440, (540 - 320) NB. gltext '_2' NB. gltextxy 440, (540 - 480) NB. gltext '_3' ) wrtxt =: 3 : 0 gltextxy (L:0) 0{"(1) y. gltext (L:0) ":(L:0) 1{"(1) y. )