• 11-23-2012, 12:45 AM
joker600
I need a code that draw this graphic ...

Attachment 4250
• 11-23-2012, 02:55 AM
DarrylBurke
This is a forum, not a code factory. Go through the tutorials and try it yourself, then if you have a specific question about your code you can ask it here.

Trail: 2D Graphics (The Java™ Tutorials)
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

How to ask questions the smart way

db
• 11-23-2012, 01:53 PM
joker600
I want to write a code that draw this graphic

http://s8.postimage.org/ocjangtgh/image.jpg

The code must be build using the following algorithms

Code:

```        void drawLine(Graphics g, int x1, int y1, int x2, int y2) {         int dx = x2 - x1;         int dy = y2 - y1;         putPixel(g, x1, y1);                 if (Math.abs(dx) > Math.abs(dy)) {                 float m = (float) dy / (float) dx;                 float b = y1 - m*x1;                 dx = (dx < 0) ? -1 : 1;                 while (x1 != x2) {                         x1 += dx;                         putPixel(g, x1, Math.round(m*x1 + b));                 }         } else        if (dy != 0) {                 float m = (float) dx / (float) dy;                 float b = x1 - m*y1;                 dy = (dy < 0) ? -1 : 1;                 while (y1 != y1) {                         y1 += dy;                         putPixel(g, Math.round(m*y1 + b), y1);                 }         }                         g.setColor(Color.black);                 g.drawLine(x1 * pixelSize, y1 * pixelSize, x2 * pixelSize, y2                                 * pixelSize);         }```
Code:

```        void drawCircle(Graphics g,int xCenter , int yCenter , int radius){                     int x, y=0, r2;                 r2 = radius * radius;         for (x = -radius; x <= radius; x++) {             y = (int) (Math.sqrt(r2 - x*x) + 0.5);             putPixel(g, xCenter + x, yCenter + y);             putPixel(g, xCenter + x, yCenter - y);         }                            g.setColor(Color.black);                 g.drawOval(xCenter, yCenter, r2, r2);                 }```
Honestly I don't know where to start,, any help please!
• 11-23-2012, 05:15 PM
DarrylBurke