• fullscreen
  • Math2Da.pde
  • 
    float result = 0;
    float resultScreen = 0; 
    
    void setup() {
      size(420, 340);
      background(153);
      PFont myFont = createFont("FFScala", 12);
      textFont(myFont);
    } // function 
    
    void draw() {
      ShowCoor(); 
      function1(); 
      function2();
    } // function 
    
    void ShowCoor() {
      stroke (0,254,254);
      fill (0,254,254);  
      strokeWeight(4);   // Thicker
      line(0, height, 0, 0);
      text ("x", width-10, height-10);
      line(0, height, width, height);
      text ("y", 10, 10);
      strokeWeight(1);   // thin
    } // function 
    
    void function1(){
      boolean firstTime=true; 
      float oldResultX =0;
      float oldResultY =0;
      stroke (222,0,0);
      for (int i = 0; i < 340; i = i+1) {
        // line(30, i, 80, i);
        result = 3*i*i + 5 ; 
        resultScreen = height - result * 0.001;
        point ( i, resultScreen ) ; 
        if (firstTime){
          oldResultX=i; 
          oldResultY=resultScreen;
          firstTime=false; 
        } // if 
        line (oldResultX,oldResultY,i,resultScreen);
        oldResultX=i; 
        oldResultY=resultScreen;
      } // for
      fill (222,0,0);
      text ("y=3*x*x+5", 220, 115);
      // println ("done 1.");
    } // function 
    
    void function2(){
      boolean firstTime=true; 
      float oldResultX =0;
      float oldResultY =0;
      stroke (0,254,0);
      for (int i = 0; i < 340; i = i+1) {
        // line(30, i, 80, i);
        result = 3*i*i*i + 5 ; 
        resultScreen = height -  result * 0.001;
        point ( i, resultScreen ) ; 
        if (firstTime){
          oldResultX=i; 
          oldResultY=resultScreen;
          firstTime=false; 
        }
        line (oldResultX,oldResultY,i,resultScreen);
        oldResultX=i; 
        oldResultY=resultScreen;
      } // for 
      fill (0,254,0);
      text ("y=3*x*x*x+5", 50, 15);    
      // println ("done 2.");
    } // function 
    
    
    
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    polar

    Function Plotter 2D

    Add to Faves Me Likey@! 1
    You must login/register to add this sketch to your favorites.

    This is a Function Plotter in 2D for Math-functions. It shows two formulas in comparison in different colors. It is at the moment pretty much y=x^3 and y=x^2.

    You need to login/register to comment.