pastebin - collaborative debugging tool
blankb.kpaste.net RSS


SmolGraph
Posted by Anonymous on Tue 19th Dec 2017 23:11
raw | new post

  1. class smolGraph
  2. {
  3.  
  4.         public $screenWidth=1000;
  5.         public $screenHeight=1000;
  6.  
  7.         //what is the incoming data going to look like
  8.         public $minValueX;
  9.         public $maxValueX;
  10.         public $minValueY;
  11.         public $maxValueY;
  12.  
  13.         //Where does it live physicall on the screen
  14.         public $startX;
  15.         public $widthX;
  16.         public $startY;
  17.         public $heightY;
  18.  
  19.         //cartesian center relative to the X Y of physical screen
  20.         public $cartCenterX;
  21.         public $cartCenterY;
  22. }
  23.  
  24.  
  25.         $AGraph=new smolGraph();
  26.         $AGraph->minValueX=-25;
  27.         $AGraph->maxValueX=25;
  28.         $AGraph->minValueY=-25;
  29.         $AGraph->maxValueY=25;
  30.  
  31.         $AGraph->startX=100;
  32.         $AGraph->startY=100;
  33.         $AGraph->widthX=100;
  34.         $AGraph->heightY=100;
  35.  
  36.         $AGraph->cartCenterX=50;
  37.         $AGraph->cartCenterY=50;
  38.  
  39.         print_r($AGraph);
  40.  
  41.         graphBounds($AGraph,2,"#0000ff");
  42.  
  43.         graphLine($AGraph,0,0,25,25,1,"#000000");
  44.         graphLine($AGraph,-25,25,12,12,1,"#00ff00");
  45.         //graphLine($AGraph,0,0,25,0,1,"#000000");
  46.         //graphLine($AGraph,-25,-25,25,25,1,"#ff0000");
  47.  
  48.  
  49.         function graphBounds($GSET,$width,$color)
  50.         {
  51.                 global $SVGDOCUMENT;
  52.                 $x1=$GSET->startX;
  53.                 $x2=$GSET->startX+$GSET->widthX;
  54.  
  55.                 $y1=$GSET->startY;
  56.                 $y2=$GSET->startY+$GSET->heightY;
  57.                 $SVGDOCUMENT.="<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y1\" style=\"stroke:$color;stroke-width:$width;\" />\n"; //top
  58.                 $SVGDOCUMENT.="<line x1=\"$x2\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" style=\"stroke:$color;stroke-width:$width;\" />\n"; //right
  59.                 $SVGDOCUMENT.="<line x1=\"$x1\" y1=\"$y2\" x2=\"$x2\" y2=\"$y2\" style=\"stroke:$color;stroke-width:$width;\" />\n"; //bottom
  60.                 $SVGDOCUMENT.="<line x1=\"$x1\" y1=\"$y1\" x2=\"$x1\" y2=\"$y2\" style=\"stroke:$color;stroke-width:$width;\" />\n"; //left
  61.         }
  62.  
  63.         function graphLine($GSET,$x,$y,$h,$v,$width,$color)
  64.         {
  65.                 global $SVGDOCUMENT;
  66.  
  67.                 $x1=map($x,$GSET->minValueX,$GSET->maxValueX,$GSET->startX,$GSET->startX+$GSET->widthX)-($GSET->cartCenterX);
  68.                 $x2=map($h,$GSET->minValueX,$GSET->maxValueX,$GSET->startX,$GSET->startX+$GSET->widthX)-($GSET->cartCenterX);
  69.  
  70.                 // $y1=map($y,$GSET->minValueY,$GSET->maxValueY,$GSET->startY,$GSET->startY+$GSET->heightY)+$GSET->cartCenterY;
  71.                 // $y2=map($v,$GSET->minValueY,$GSET->maxValueY,$GSET->startY,$GSET->startY+$GSET->heightY)+$GSET->cartCenterY;
  72.                 $y1=map($y,$GSET->minValueY,$GSET->maxValueY,$GSET->startY+$GSET->heightY,$GSET->startY)+$GSET->cartCenterY;
  73.                 $y2=map($v,$GSET->minValueY,$GSET->maxValueY,$GSET->startY+$GSET->heightY,$GSET->startY)+$GSET->cartCenterY;
  74.                 $SVGDOCUMENT.="<line x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" style=\"stroke:$color;stroke-width:$width;\" />\n";
  75.         }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at