Figuras Geometricas 2D, Código
Beschreibung
![constructor](structure/lego-blue.jpg)
Código del constructor
```
import java.awt.Color;
import org.opensourcephysics.display.DrawableShape;
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.PlottingPanel;
public class Geo {
Geo(){
Color fillColor = new Color(255, 128, 128, 128);
Color edgeColor = new Color(255, 0, 0, 255);
PlottingPanel panel = new PlottingPanel("x", "y", null);
panel.setSquareAspect(true);
DrawingFrame frame = new DrawingFrame(panel);
DrawableShape rectangle = DrawableShape.createRectangle(-3, -4, 4, 5);
rectangle.setTheta(Math.PI/4);
rectangle.setMarkerColor(fillColor, edgeColor);
panel.addDrawable(rectangle);
DrawableShape circle = DrawableShape.createCircle(3, 4, 6);
panel.addDrawable(circle);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
```
ID:(7539, 0)
Figuras Geometricas 2D, Explicación
Beschreibung
Para ello se incluye los import:
```
import java.awt.Color;
import org.opensourcephysics.display.DrawableShape;
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.PlottingPanel;
```
y dentro del código las definciones necesarias:
```
Color fillColor = new Color(255, 128, 128, 128);
Color edgeColor = new Color(255, 0, 0, 255);
```
Luego se debe crear el panel para dibujar
```
PlottingPanel panel = new PlottingPanel("x", "y", null);
panel.setSquareAspect(true);
DrawingFrame frame = new DrawingFrame(panel);
```
para crear y agregar un rectangulo
```
DrawableShape rectangle = DrawableShape.createRectangle(-3, -4, 4, 5);
rectangle.setTheta(Math.PI/4);
rectangle.setMarkerColor(fillColor, edgeColor);
panel.addDrawable(rectangle);
```
y crear un circulo
```
DrawableShape circle = DrawableShape.createCircle(3, 4, 6);
panel.addDrawable(circle);
```
Finalmente se cuelga el panel del frame:
```
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
```
ID:(7538, 0)