Results 1 to 5 of 5
Thread: Please help me in this graphic!
- 11-22-2012, 11:45 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
- 11-23-2012, 01:55 AM #2
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
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 11-23-2012, 12:53 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Please help me in this graphic!
I want to write a code that draw this graphic
The code must be build using the following algorithms
Java 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); }
Java 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); }
- 11-23-2012, 04:15 PM #4
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.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 11-23-2012, 09:27 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
I need help with Graphics
By Wizard0860 in forum New To JavaReplies: 4Last Post: 02-16-2017, 07:42 PM -
SVG graphics
By Lacrim in forum Advanced JavaReplies: 2Last Post: 06-09-2012, 12:54 AM -
Graphics 2D
By scopene in forum Java 2DReplies: 0Last Post: 03-26-2012, 01:21 AM -
Drawing a graphics onto another Graphics ?
By Ziden in forum Java AppletsReplies: 0Last Post: 01-08-2011, 07:30 PM -
Help me with graphics
By 7oclock in forum New To JavaReplies: 12Last Post: 04-04-2009, 11:20 PM
Bookmarks