
Napisałem program rysujący wykresy funkcji program działa z tym że dla niektórych funkcji wykres jest postrzępiony i nie wygląda to za ciekawie (wygląda jak by funkcja nie była ciągła)
oto kod mojego programu
Kod
import java.awt.*;
import java.applet.*;
public class Figury extends Applet {
int width, height;
public double fodx (double x) {
double y;
y = -0.1*(x+1)*(2-x)*(x-5);
return y;
}
public void init () {
//getContentPane().setLayout(null);
width = 800;
height = 600;
setSize(width, height);
}
public void paint(Graphics a) {
a.setColor(new Color(0,0,0));
a.drawLine (0, height / 2, width, height / 2);
a.drawLine (width/2, 0, width/2, height);
int skala_ox;
int y1 , y2;
skala_ox =5;
for(int i=-20; i < 20; i++){
y1 = (int) fodx(i);
y2 = (int) fodx(i+1);
a.setColor(new Color(255,0,0));
a.drawLine( i* skala_ox + (width /2 ) , -y1* skala_ox + (height / 2) , i* skala_ox + (width /2 ) , -y2* skala_ox + (height / 2));
}
}
}
import java.applet.*;
public class Figury extends Applet {
int width, height;
public double fodx (double x) {
double y;
y = -0.1*(x+1)*(2-x)*(x-5);
return y;
}
public void init () {
//getContentPane().setLayout(null);
width = 800;
height = 600;
setSize(width, height);
}
public void paint(Graphics a) {
a.setColor(new Color(0,0,0));
a.drawLine (0, height / 2, width, height / 2);
a.drawLine (width/2, 0, width/2, height);
int skala_ox;
int y1 , y2;
skala_ox =5;
for(int i=-20; i < 20; i++){
y1 = (int) fodx(i);
y2 = (int) fodx(i+1);
a.setColor(new Color(255,0,0));
a.drawLine( i* skala_ox + (width /2 ) , -y1* skala_ox + (height / 2) , i* skala_ox + (width /2 ) , -y2* skala_ox + (height / 2));
}
}
}
jeśli ktoś się kiedyś spotkał z podobnym problemem lub wie jak go rozwiązać to będę wdzięczny za pomoc
za każdą pomoc ...
he he jak to mówią umiesz liczyć licz na siebie

posiedziałem pokombinowałem i zrobiłem
Kod
import java.awt.*;
import java.applet.*;
public class Figury extends Applet {
int width, height;
public double fodx (double x) {
double y;
//y = -0.1*(x+1)*(2-x)*(x-5);
//y = 1/5*x*(x+3)*(2-x)*(x+1);
// y=(x+1)/(3*x+6);
//y = (3*x)/((x*x)-x+1);
//y = Math.sin(x*Math.PI+100)+20;
y= (x*x)-(3*x)+5;
return y;
}
public void init () {
//getContentPane().setLayout(null);
width = 800;
height = 600;
setSize(width, height);
}
public void paint(Graphics a) {
a.setColor(new Color(0,0,0));
a.drawLine (0, height / 2, width, height / 2);
a.drawLine (width/2, 0, width/2, height);
int skala_ox , zakres;
double y1 , y2 ,x1 ,x2;
//skala_ox = height/((height/2)-(int)fodx(50));
zakres = 20;
skala_ox =15;
x1=(zakres*-1) * skala_ox + (width /2 );
y1=(fodx(zakres*-1)) * skala_ox + (height / 2);
for(int i=zakres*(-1); i < zakres;i=i+1){
//y1 = (int) fodx(i);
y2 = fodx(i+1)* skala_ox + (height / 2);
x2 = i * skala_ox + (width /2 );
a.setColor(new Color(255,0,0));
//a.drawLine( (i)* skala_ox + (width /2 ) , -y1* skala_ox + (height / 2) , i* skala_ox + (width /2 ) , -y2* skala_ox + (height / 2));
a.drawLine( (int) x1 , (int) y1 , (int) x2 ,(int) y2);
x1= x2;
y1 = y2;
}
a.setColor(new Color(149,197,255));
a.drawLine(0,(height / 2)-(1*skala_ox), width ,(height / 2) - (1*skala_ox));
a.drawLine((1*skala_ox) + (width / 2), 0 ,(1*skala_ox) + (width / 2) ,height);
/*
double i = -20;
while (i < zakres) {
y1 = (int) fodx(i);
y2 = (int) fodx(i+1);
a.setColor(new Color(255,0,0));
a.drawLine( (int)i* skala_ox + (width /2 ) , -y1* skala_ox + (height / 2) , (int)i* skala_ox + (width /2 ) , -y2* skala_ox + (height / 2));
i = i + 0.01;
}
*/
}
}
import java.applet.*;
public class Figury extends Applet {
int width, height;
public double fodx (double x) {
double y;
//y = -0.1*(x+1)*(2-x)*(x-5);
//y = 1/5*x*(x+3)*(2-x)*(x+1);
// y=(x+1)/(3*x+6);
//y = (3*x)/((x*x)-x+1);
//y = Math.sin(x*Math.PI+100)+20;
y= (x*x)-(3*x)+5;
return y;
}
public void init () {
//getContentPane().setLayout(null);
width = 800;
height = 600;
setSize(width, height);
}
public void paint(Graphics a) {
a.setColor(new Color(0,0,0));
a.drawLine (0, height / 2, width, height / 2);
a.drawLine (width/2, 0, width/2, height);
int skala_ox , zakres;
double y1 , y2 ,x1 ,x2;
//skala_ox = height/((height/2)-(int)fodx(50));
zakres = 20;
skala_ox =15;
x1=(zakres*-1) * skala_ox + (width /2 );
y1=(fodx(zakres*-1)) * skala_ox + (height / 2);
for(int i=zakres*(-1); i < zakres;i=i+1){
//y1 = (int) fodx(i);
y2 = fodx(i+1)* skala_ox + (height / 2);
x2 = i * skala_ox + (width /2 );
a.setColor(new Color(255,0,0));
//a.drawLine( (i)* skala_ox + (width /2 ) , -y1* skala_ox + (height / 2) , i* skala_ox + (width /2 ) , -y2* skala_ox + (height / 2));
a.drawLine( (int) x1 , (int) y1 , (int) x2 ,(int) y2);
x1= x2;
y1 = y2;
}
a.setColor(new Color(149,197,255));
a.drawLine(0,(height / 2)-(1*skala_ox), width ,(height / 2) - (1*skala_ox));
a.drawLine((1*skala_ox) + (width / 2), 0 ,(1*skala_ox) + (width / 2) ,height);
/*
double i = -20;
while (i < zakres) {
y1 = (int) fodx(i);
y2 = (int) fodx(i+1);
a.setColor(new Color(255,0,0));
a.drawLine( (int)i* skala_ox + (width /2 ) , -y1* skala_ox + (height / 2) , (int)i* skala_ox + (width /2 ) , -y2* skala_ox + (height / 2));
i = i + 0.01;
}
*/
}
}
nie będę tłumaczył jak działa bo nie ot ot chodzi samemu można wywnioskować
program zamieszczam bo może sie to komuś przydać
gdyby ktoś wykorzystał i ulepszył po drodze to moja prośba to takiej osoby niech napisze co zostało ulepszone