How to draw a function curve in android? -


i have function, y = 50sin(x/50) + 100. want draw curve function, without additional info graph plotters, need wave on screen. x should correspond x parameter of screen , y y parameter of screen. here code of current view.

public class sinusoid extends view {     paint paint = new paint();      public sinusoid(context context) {         super(context);         paint.setcolor(color.red);     }      @override     public void ondraw(canvas canvas) {         //todo draw line using myfunction     }      private double myfunction(double x){         return 50 * math.sin(x / 50) + 100;     }  } 

now question is, should fill in todo?

please help, documentation or example useful.

thanks in advance.

the idea have this:

@override public void ondraw(canvas canvas) {     (int x=0; x<canvas.getwidth();x++) {          canvas.drawpoint(x,(float) myfunction(x),mpaint);     } } 

but you'll need adjust value of function given canvas height.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -