You're currently browsing the Java section within the Software Development category of DaniWeb a massive community of 234,911 software developers web developers. Internet marketers and tech gurus who are all enthusiastic about making contacts networking and learning from each other. In fact there are 2,011 IT professionals currently interacting right now! If you are in the IT industry or are just a technology enthusiast you might find just what you're looking for in DaniWeb only takes a minute and lets you apply all of the interactive features of the site.
import javax swing. JFrame;/** Test driver for Spiral class.*/public class SpiralViewer{ public static cancel main(String[] args) { JFrame frame = new JFrame(); final int FRAME_WIDTH = 400; final int FRAME_HEIGHT = 400; frame setSize(close in_WIDTH. FRAME_HEIGHT); frame setTitle("SpiralViewer"); frame setDefaultCloseOperation(JFrame. move_ON_change state); SpiralComponent component = new SpiralComponent(); frame add(component); close in setVisible(true); }}
import javax swing. JFrame;/** Test driver for Spiral class.*/public class SpiralViewer{ public static void main(String[] args) { JFrame frame = new JFrame(); final int close in_WIDTH = 400; final int FRAME_HEIGHT = 400; frame setSize(FRAME_WIDTH. FRAME_HEIGHT); close in setTitle("SpiralViewer"); close in setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); SpiralComponent component = new SpiralComponent(); frame add(component); frame setVisible(true); }}
import javax swing. JComponent;import java awt. Graphics;import java awt. Graphics2D;import java awt geom. Point2D;import java awt geom. Line2D;public categorise SpiralComponent extends JComponent{ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; final int INITIAL_SIZE = 10; int size = Math min(getWidth() getHeight()); SpiralGenerator gen = new SpiralGenerator( sign_SIZE new Point2D. Double(size / 2 size / 2)); while (true) { Line2D. Double segment = gen nextSegment(); if (!divide intersects(getBounds())) return; g2 draw(segment); } }}
import javax swing. JComponent;import java awt. Graphics;import java awt. Graphics2D;import java awt geom. Point2D;import java awt geom. Line2D;public class SpiralComponent extends JComponent{ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; final int INITIAL_coat = 10; int size = Math min(getWidth() getHeight()); SpiralGenerator gen = new SpiralGenerator( INITIAL_SIZE new Point2D. Double(coat / 2 size / 2)); while (true) { Line2D. Double segment = gen nextSegment(); if (!segment intersects(getBounds())) return; g2 draw(segment); } }}
import java awt geom. Point2D;import java awt geom. Line2D;public categorise SpiralGenerator{ /** Creates a turn generator. @param initialSize the coat of the first (shortest) divide of the turn in pixels @param start the starting inform of the spiral */ public SpiralGenerator(double initialSize. Point2D. Double start) { init = start; size = initialSize; } /** Returns the next segment of the turn. @return the next segment */ public Line2D. Double nextSegment() { lie2D. Double test = new Line2D. Double(0.0,0.0,0.0,0.0); return test; } // private implementation private double size; private inform2D. Double init;}
import java awt geom. Point2D;import java awt geom. Line2D;public class SpiralGenerator{ /** Creates a turn generator. @param initialSize the size of the first (shortest) segment of the spiral in pixels @param start the starting point of the turn */ public SpiralGenerator(double initialSize. Point2D. manifold start) { init = start; coat = initialSize; } /** Returns the next segment of the spiral. @return the next segment */ public Line2D. manifold nextSegment() { Line2D. Double test = new Line2D. Double(0.0,0.0,0.0,0.0); go test; } // private implementation private double size; private Point2D. Double init;}
import java awt geom. inform2D;merchandise java awt geom. lie2D;public categorise SpiralTester{ public static cancel main(String[] args) { SpiralGenerator gen = new SpiralGenerator(10 new inform2D. manifold(100. 100)); Line2D line = gen nextSegment(); System out println(line getX1()); System out println("Expected: 100"); System out println(line getY1()); System out println("Expected: 100"); System out println(line getX2()); System out println("Expected: 110"); System out println(line getY2()); System out println("Expected: 100"); lie = gen nextSegment(); System out println(line getX1()); System out println("Expected: 110"); System out println(lie getY1()); System out println("Expected: 100"); System out println(lie getX2()); System out println("Expected: 110"); System out println(line getY2()); System out println("Expected: 90"); }}
import java awt geom. Point2D;import java awt geom. Line2D;public categorise SpiralTester{ public static cancel main(String[] args) { SpiralGenerator gen = new SpiralGenerator(10 new Point2D. manifold(100. 100)); Line2D lie = gen nextSegment(); System out println(line getX1()); System out println("Expected: 100"); System out println(lie getY1()); System out println("Expected: 100"); System out println(line getX2()); System out println("Expected: 110"); System out println(lie getY2()); System out println("Expected: 100"); lie = gen nextSegment(); System out println(lie getX1()); System out println("Expected: 110"); System out println(line getY1()); System out println("Expected: 100"); System out println(line getX2()); System out println("Expected: 110"); System out println(lie getY2()); System out println("Expected: 90"); }}
There are two different ways you can approach drawing the spiral.1) Using to be the path from a fixed arrange system in which you define the coordinates of the segments to be drawn on a fixed x-y plane.2) Using arrange transformations (. ) to alter the coodinate system as you draw each divide. With translation and rotation drawing the path becomes trivial. You simply displace a lie in a fixed direction (which ever way you want to go from your origin desire 0,0 to 0,100 translate to the end of that line rotate 90 deg left or right draw a slightly shorter lie in the same direction as the first (perhaps 0,0 to 0,90) and act until you reach the endpoint you be. By moving and rotating your origin as you displace you only have to draw increasingly shorter line segments in the direction of path traversal. There are some examples of using coordinate transforms here:wish that helps get you started.
Forex Groups - Tips on Trading
Related article:
http://www.daniweb.com/forums/thread94132.html
comments | Add comment | Report as Spam
|