# Please help me in this graphic!

Printable View

• 11-23-2012, 12:45 AM
joker600
Please help me in this graphic!
Help please!
I need a code that draw this graphic ...

Attachment 4250
• 11-23-2012, 02:55 AM
DarrylBurke
Re: Please help me in this graphic!
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
Please help me in this graphic!
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
Re: Please help me in this graphic!
Please go through the Forum Rules -- especially the second paragraph. Don't start a new thread every time you have a follow-on question.

Moreover, it's rude to ask another question without having first replied to responses on any earlier thread. I've merged the new thread here.

db
• 11-23-2012, 10:27 PM
joker600
Re: Please help me in this graphic!
I cannot edit on the first post! so I wanted to remove it (but I can't do that either!) to start new one showing the code I've tried to wrote (because you told me to try something)
Now I'm thinking of leaving the whole forum,, because nothing is work