Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
Cartesian.txt50 linesDownload Raw Back to Graphics
1 2//x must be global.3//Might as well make y global.4 5F64 x,y,y_last;6 7U0 Cartesian()8{9  U8 *st;10  I64 ch=0,h,v;11  Bool first;12  CDC *dc=DCAlias;13  do {14    DocClear;15    "Enter algebraic equation to graph.\n"16          "Example: y=2*x\n"17          "y=";18    if (st=GetStr) {19      if (*st) {20        h=Fs->pix_width/2;21        v=Fs->pix_height/2;22        dc->color=RED;23        GrLine(dc,h,0,h,2*v+1);24        GrLine(dc,0,v,2*h+1,v);25        first=TRUE;26        dc->color=BLACK;27        for (x=-h;x<=h;x++) {28          y=-ExePrint("ToF64(%s);",st)(F64);29          if (!first)30            GrLine(dc,x-1+h,y_last+v,x+h,y+v);31          y_last=y;32          first=FALSE;33        }34        ch=GetChar;35      } else36        ch=CH_SHIFT_ESC;37      Free(st);38    } else39      ch=CH_SHIFT_ESC;40    DCFill;41  } while (ch!=CH_SHIFT_ESC && ch!=CH_ESC);42  DCDel(dc);43}44 45Cartesian;46 47//For better performance, compile the expression entered by the48//user one time with LexExpression2Bin() and use Call().49//See ::/Demo/CompileDemo.HC.50