import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Rose { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub final Display display = new Display(); final Shell shell = new Shell(display); shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { final Rectangle rectangle = shell.getClientArea(); final GC gc = e.gc; gc.setForeground(new Color(display, 255, 0, 0)); final double radius = rectangle.width / 2 - 5; final int n = 1000; int lastx = 0, lasty = 0; for (int i = 0; i < n; ++i) { final double theta = 2 * Math.PI * i / n; final double r = Math.cos(3 * theta) * radius; final int x = (int) (rectangle.width / 2 + r * Math.cos(theta)); final int y = (int) (rectangle.height / 2 + r * Math.sin(theta)); if (i > 0) { gc.drawLine(lastx, lasty, x, y); } lastx = x; lasty = y; } } }); shell.setText("Draw in a shell"); shell.setSize(700 + 4 + 4, 700 + 34); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }