Example07.java

  1. /*
  2.  *                      ..::jDrawingLib::..
  3.  *
  4.  * Copyright (C) Federico Vera 2012 - 2023 <fede@riddler.com.ar>
  5.  *
  6.  * This program is free software: you can redistribute it and/or modify it
  7.  * under the terms of the GNU General Public License as published by the
  8.  * Free Software Foundation, either version 3 of the License, or any later
  9.  * version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14.  * See the GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License along
  17.  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19. package com.dkt.graphics.extras.examples;

  20. import com.dkt.graphics.canvas.Canvas;
  21. import com.dkt.graphics.canvas.CanvasFrame;
  22. import com.dkt.graphics.elements.GVector;
  23. import com.dkt.graphics.extras.GAxis;
  24. import java.awt.Color;

  25. /**
  26.  *
  27.  * @author Federico Vera {@literal<fede@riddler.com.ar>}
  28.  */
  29. public class Example07 implements IExample {
  30.     @Override
  31.     public void run() {
  32.         CanvasFrame frame = new CanvasFrame(getName());
  33.         frame.setVisible(true);
  34.         frame.setSize(600, 600);
  35.         Canvas canvas = frame.getCanvas();
  36.         canvas.setCenterBounds(true);
  37.         canvas.setCenterOrigin(true);
  38.         canvas.setInvertYAxis(true);
  39.         canvas.setUseFullArea(false);
  40.         canvas.setDrawableSize(500, 500);

  41.         GAxis axis = new GAxis(-250, 250, -250, 250);
  42.         canvas.add(axis);

  43.         GVector v1 = new GVector(0, 0, 100, 0);
  44.         v1.setPaint(Color.RED);
  45.         GVector v2 = new GVector(100, 0, 100, 90);
  46.         v2.setPaint(Color.BLUE);
  47.         GVector v4 = new GVector(0, 0, -100, 45);
  48.         v4.setPaint(Color.BLUE);
  49.         GVector v3 = v1.add(v2, v4);
  50.         v3.setPaint(Color.GREEN);
  51.         canvas.add(v1);
  52.         canvas.add(v2);
  53.         canvas.add(v3);
  54.         canvas.add(v4);
  55.     }

  56.     @Override
  57.     public String getName() {
  58.         return "Vectors";
  59.     }
  60. }