Advertisement
Guest User

functions/methods day 1 in processing

a guest
May 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. void setup(){
  2.   size(640, 480);
  3.   double m = 0;
  4.   double b = 10;
  5.   //y = 2x + 4
  6.   for( double x = 0.0; x <= width; x++ ){
  7.     double y = f( m, b, x );
  8.     point( (float)x, (float)(height - y) );
  9.   }
  10.  
  11.   //y = ax^2 + bx + c
  12.   double a = -.2;
  13.   b = 16;
  14.   double c = 0;
  15.   for( double x = 0.0; x <= width; x++ ){
  16.     double y = f2( a, b, c, x);
  17.     point((float)x, (float)(height - y));
  18.   }
  19. }
  20.  
  21. double f2( double a, double b, double c, double x){
  22.   double y = a * (Math.pow(x, 2)) + b * x + c;
  23.   return y;
  24. }
  25.  
  26. double f( double m, double b, double x ){
  27.   double y = m * x + b;
  28.   return y;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement