This assignment gives the student experience creating fat diagonal lines using fillOval. If the student ponders this situation, the student will realize that it is not all that easy to create fat lines which are diagonal. If the student were to desire fat horizontal or vertical lines, it would be easy for the student to simply use fillRect, but for fat diagonal lines, things are a little trickier.
EXAMPLE: The student will create an applet like the one shown here. This activity provides the student the opportunity to create fat diagonal lines. |
x |
ASSIGNMENT:
Here's the method to make a fat diagonal line:
public void drawDLine(Graphics g, int startx, int starty, int endx, int endy){ float xinc=(float)(startx-endx)/(float)45.0; float yinc=(float)(starty-endy)/(float)45.0; float currX=startx; float currY=starty; for(int c=0; c < 45; c++){ g.fillOval(Math.round(currX),Math.round(currY),5,5); currX-=xinc; currY-=yinc; } }
drawDLine(g, 100, 10, 190, 100);