Advertisement
bekovski

algo_sat_1

May 10th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.50 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import algoanim.animalscript.AnimalCircleGenerator;
  7. import algoanim.animalscript.AnimalPointGenerator;
  8. import algoanim.animalscript.AnimalPolylineGenerator;
  9. import algoanim.animalscript.AnimalRectGenerator;
  10. import algoanim.animalscript.AnimalScript;
  11. import algoanim.animalscript.AnimalTextGenerator;
  12. import algoanim.animalscript.AnimalTriangleGenerator;
  13. import algoanim.primitives.Circle;
  14. import algoanim.primitives.Point;
  15. import algoanim.primitives.Polyline;
  16. import algoanim.primitives.Rect;
  17. import algoanim.primitives.SourceCode;
  18. import algoanim.primitives.Text;
  19. import algoanim.primitives.Triangle;
  20. import algoanim.primitives.generators.Language;
  21. import algoanim.properties.AnimationPropertiesKeys;
  22. import algoanim.properties.CircleProperties;
  23. import algoanim.properties.PointProperties;
  24. import algoanim.properties.PolylineProperties;
  25. import algoanim.properties.RectProperties;
  26. import algoanim.properties.SourceCodeProperties;
  27. import algoanim.properties.TextProperties;
  28. import algoanim.properties.TriangleProperties;
  29. import algoanim.util.Coordinates;
  30. import algoanim.util.Node;
  31. import algoanim.util.TicksTiming;
  32. import algoanim.util.Timing;
  33. import auxiliary.Vector2f;
  34.  
  35. public class SAT {
  36.    
  37.     public static final Color LINE_DEFAULT_COLOR    = Color.BLACK;
  38.     public static final Color VECTOR_DEFAULT_COLOR  = Color.BLACK;
  39.    
  40.     Language lang;
  41.    
  42.     Text text;
  43.     Point point;
  44.     Circle circle;
  45.     Polyline line;
  46.     Polyline edge;
  47.     Polyline vector;
  48.     Polyline separatingAxis;
  49.     Triangle triangle;
  50.    
  51.     // temp
  52.     Polyline[] vectors = new Polyline[3];
  53.    
  54.     SourceCode sc;
  55.     Timing timing;
  56.    
  57.     // might need these properties
  58.     TextProperties textProps;
  59.     RectProperties rectProps;
  60.     PointProperties pointProps;
  61.     CircleProperties circleProps;
  62.     PolylineProperties lineProps;
  63.     PolylineProperties vectorProps;
  64.     TriangleProperties triangleProps;
  65.    
  66.    
  67.     int x = 40;
  68.     int y = 140;
  69.     int startY;
  70.     int offsetY = 20;
  71.     String vertexName;
  72.     String neighbor1Name;
  73.     String neighbor2Name;
  74.    
  75.     List<Text> textList = new ArrayList<>();
  76.    
  77.     public void init() {
  78.         lang = new AnimalScript("Separating Axis Theorem (Circle-Triangle)", "Bekir Oezkara", 640, 480);
  79.         lang.setStepMode(true);
  80.        
  81.         timing = new TicksTiming(200);
  82.        
  83.         textProps = new TextProperties();
  84.         textProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, Color.BLACK);
  85.         textProps.set(AnimationPropertiesKeys.FONT_PROPERTY, new Font("Monospaced", Font.PLAIN, 12));
  86.        
  87.         rectProps = new RectProperties();
  88.         rectProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, Color.DARK_GRAY);
  89.         rectProps.set(AnimationPropertiesKeys.FILLED_PROPERTY, true);
  90.         rectProps.set(AnimationPropertiesKeys.FILL_PROPERTY, Color.LIGHT_GRAY);
  91.         rectProps.set(AnimationPropertiesKeys.DEPTH_PROPERTY, 2);
  92.        
  93.         pointProps = new PointProperties();
  94.         pointProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, Color.CYAN);
  95.        
  96.         circleProps = new CircleProperties();
  97. //      circleProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, Color.RED);
  98.         circleProps.set(AnimationPropertiesKeys.FILL_PROPERTY, Color.WHITE);
  99.        
  100.         lineProps = new PolylineProperties();
  101.         lineProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, LINE_DEFAULT_COLOR);
  102.        
  103.         vectorProps = new PolylineProperties();
  104.         vectorProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, VECTOR_DEFAULT_COLOR);
  105.         vectorProps.set(AnimationPropertiesKeys.FWARROW_PROPERTY, true);
  106.        
  107.         triangleProps = new TriangleProperties();
  108. //      triangleProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, Color.GREEN);
  109.         triangleProps.set(AnimationPropertiesKeys.FILL_PROPERTY, Color.WHITE);
  110.        
  111.         makeHeader();
  112.         makeSideBox();
  113.         drawCoordSystem();
  114.        
  115.     }
  116.    
  117.    
  118.     public boolean hasSA(auxiliary.Circle circle, auxiliary.Triangle triangle) {
  119.        
  120.         makeCircle(circle.center.x, circle.center.y, circle.radius);
  121.         makeTriangle(triangle.A, triangle.B, triangle.C);
  122.         lang.nextStep();
  123.        
  124.         startY = getY(circle, triangle);
  125.         y = startY;
  126.        
  127.         x = 910;
  128.         startY = 160;
  129.         y = startY;
  130.        
  131.         // vertices
  132.         vertexName = "A";
  133.         neighbor1Name = "B";
  134.         neighbor2Name = "C";
  135.         point = makePoint((int)triangle.A.x, (int)triangle.A.y);
  136.         textAndStep("Vertex A");
  137.         boolean separatedByVertexA = isVertexSA(circle, triangle, triangle.A);
  138.         point.hide();
  139.        
  140.         clearText();
  141.         y = startY;
  142.        
  143.         vertexName = "B";
  144.         neighbor1Name = "A";
  145.         neighbor2Name = "C";
  146.         point = makePoint((int)triangle.B.x, (int)triangle.B.y);
  147.         textAndStep("Vertex B");
  148.         boolean separatedByVertexB = isVertexSA(circle, triangle, triangle.B);
  149.         point.hide();
  150.        
  151.         clearText();
  152.         y = startY;
  153.        
  154.         vertexName = "C";
  155.         neighbor1Name = "A";
  156.         neighbor2Name = "B";
  157.         point = makePoint((int)triangle.C.x, (int)triangle.C.y);
  158.         textAndStep("Vertex C");
  159.         boolean separatedByVertexC = isVertexSA(circle, triangle, triangle.C);
  160.         point.hide();
  161.        
  162.         clearText();
  163.         y = startY;
  164.        
  165.         // edges
  166.         edge = makeLine(triangle.A, triangle.B, false);
  167.         edge.changeColor("", Color.PINK, null, null);
  168.         textAndStep("Edge from A to B");
  169.         boolean separatedByEdgeAB = isEdgeSA(circle, triangle, triangle.edgeAB, triangle.A, triangle.B, triangle.C);
  170.         edge.hide();
  171.        
  172.         clearText();
  173.         y = startY;
  174.        
  175.         edge = makeLine(triangle.A, triangle.C, false);
  176.         edge.changeColor("", Color.PINK, null, null);
  177.         textAndStep("Edge from A to C");
  178.         boolean separatedByEdgeAC = isEdgeSA(circle, triangle, triangle.edgeAC, triangle.A, triangle.C, triangle.B);
  179.         edge.changeColor("", Color.BLACK, null, null);
  180.        
  181.         clearText();
  182.         y = startY;
  183.        
  184.         edge = makeLine(triangle.B, triangle.C, false);
  185.         edge.changeColor("", Color.PINK, null, null);
  186.         textAndStep("Edge from B to C");
  187.         boolean separatedByEdgeBC = isEdgeSA(circle, triangle, triangle.edgeBC, triangle.B, triangle.C, triangle.A);
  188.         edge.hide();
  189.        
  190.         clearText();
  191.         y = startY;
  192.        
  193.         boolean result = separatedByVertexA || separatedByVertexB || separatedByVertexC || separatedByEdgeAB || separatedByEdgeAC || separatedByEdgeBC;
  194.         if(result) {
  195.             separatingAxis.changeColor("", Color.GREEN, null, null);
  196.             separatingAxis.show();
  197.         }
  198.         textAndStep("we found separating axis = " + result);
  199.         return result;
  200.     }
  201.    
  202.    
  203.     /**
  204.      *
  205.      * @param circle
  206.      * @param triangle
  207.      * @param vertex
  208.      * @return
  209.      */
  210.     private boolean isVertexSA(auxiliary.Circle circle, auxiliary.Triangle triangle, Vector2f vertex) {
  211.         line = makeLine(circle.center.x, circle.center.y, circle.center.x + circle.radius, circle.center.y, false);
  212.         textAndStep("radius = " + circle.radius);
  213.         line.hide();
  214.        
  215.         float distToCenter = vertex.dist(circle.center);
  216.         line = makeLine(vertex, circle.center, false);
  217.         textAndStep("distance to center = " + distToCenter);
  218.         line.hide();
  219.        
  220.        
  221.         Vector2f vertexToCenter = circle.center.sub(vertex);
  222.         vectors[0] = makeLine(vertex, circle.center, true);
  223.         textAndStep("vector from vertex to center = " + vertexToCenter);
  224.        
  225.         Vector2f vertexToNeighbor1;
  226.         Vector2f vertexToNeighbor2;
  227.        
  228.         if(vertex == triangle.A) {
  229.             vertexToNeighbor1 = triangle.B.sub(vertex); // AB
  230.             vertexToNeighbor2 = triangle.C.sub(vertex); // AC
  231.             neighbor1Name = "B";
  232.             neighbor2Name = "C";
  233.             vectors[1] = makeLine(vertex, triangle.B, true);
  234.             vectors[2] = makeLine(vertex, triangle.C, true);
  235.         }
  236.         else if(vertex == triangle.B) {
  237.             vertexToNeighbor1 = triangle.A.sub(vertex); // BA
  238.             vertexToNeighbor2 = triangle.C.sub(vertex); // BC
  239.             neighbor1Name = "A";
  240.             neighbor2Name = "C";
  241.             vectors[1] = makeLine(vertex, triangle.A, true);
  242.             vectors[2] = makeLine(vertex, triangle.C, true);
  243.         }
  244.         else if(vertex == triangle.C) {
  245.             vertexToNeighbor1 = triangle.A.sub(vertex); // CA
  246.             vertexToNeighbor2 = triangle.B.sub(vertex); // CB
  247.             neighbor1Name = "A";
  248.             neighbor2Name = "B";
  249.             vectors[1] = makeLine(vertex, triangle.A, true);
  250.             vectors[2] = makeLine(vertex, triangle.B, true);
  251.         }
  252.         else {
  253.             throw new IllegalArgumentException("The provided vertex: " + vertex + " does not match with any of the triangle's vertices.");
  254.         }
  255.        
  256.         textAndStep("vector from " + vertexName + " to " + neighbor1Name + " = " + vertexToNeighbor1);
  257.         textAndStep("vector from " + vertexName + " to " + neighbor2Name + " = " + vertexToNeighbor2);
  258.  
  259.         // they are on opposite sides if the dot product is less than zero
  260.         vectors[0].changeColor("", Color.LIGHT_GRAY, null, null);
  261.        
  262.         boolean isOppositeNeighbor1 = vertexToCenter.dot(vertexToNeighbor1) < 0;
  263.         vectors[1].changeColor("", Color.ORANGE, null, null);
  264.         textAndStep(neighbor1Name + " is on opposite side = " + isOppositeNeighbor1);
  265.         vectors[1].changeColor("", VECTOR_DEFAULT_COLOR, null, null);
  266.        
  267.         boolean isOppositeNeighbor2 = vertexToCenter.dot(vertexToNeighbor2) < 0;
  268.         vectors[2].changeColor("", Color.ORANGE, null, null);
  269.         textAndStep(neighbor2Name + " is on opposite side = " + isOppositeNeighbor2);
  270.        
  271.         vectors[0].hide();
  272.         vectors[1].hide();
  273.         vectors[2].hide();
  274.        
  275.         boolean radius_less_than_dist = circle.radius < distToCenter;
  276.         textAndStep("radius smaller than distance = " + radius_less_than_dist);
  277.        
  278.         boolean result = radius_less_than_dist && isOppositeNeighbor1 && isOppositeNeighbor2;
  279.         line = makeLine(vertex, circle.center, false);
  280.         line.changeColor("", result ? Color.GREEN : Color.RED, null, null);
  281.         if(result) {
  282.             separatingAxis =  makeLine(vertex, circle.center, false);
  283.         }
  284.         textAndStep("vertex is separating axis = " + result);
  285.         line.hide();
  286.         if(separatingAxis != null) {
  287.             separatingAxis.hide(); 
  288.         }
  289.         return result;
  290.     }
  291.    
  292.    
  293.     /**
  294.      *
  295.      * @param circle
  296.      * @param triangle
  297.      * @param edge
  298.      * @param start
  299.      * @param end
  300.      * @param other
  301.      * @return
  302.      */
  303.     private boolean isEdgeSA(auxiliary.Circle circle, auxiliary.Triangle triangle, Vector2f edge, Vector2f start, Vector2f end, Vector2f other) {
  304.         line = makeLine(circle.center.x, circle.center.y, circle.center.x + circle.radius, circle.center.y, false);
  305.         textAndStep("radius = " + circle.radius);
  306.         line.hide();
  307.        
  308.         Vector2f normalizedEdge = edge.normalize();
  309.         vector = makeLine(start.x, start.y, start.x + normalizedEdge.x, start.y + normalizedEdge.y, true);  // TODO: too small, does not show arrow in Animal !
  310.         vector.changeColor("", VECTOR_DEFAULT_COLOR, null, null);
  311.         textAndStep("normalized edge = " + normalizedEdge);
  312.         vector.hide();
  313.        
  314.         Vector2f vecToCircle;
  315.         if(edge == triangle.edgeAB) {
  316.             vecToCircle = circle.center.sub(triangle.A);
  317.             vector = makeLine(triangle.A, circle.center, true);
  318.         }
  319.         else if(edge == triangle.edgeAC) {
  320.             // TODO: why not C, or: when A, when C ?
  321.             vecToCircle = circle.center.sub(triangle.A);
  322.             vector = makeLine(triangle.A, circle.center, true);
  323.         }
  324.         else if(edge == triangle.edgeBC) {
  325.             vecToCircle = circle.center.sub(triangle.B);
  326.             vector = makeLine(triangle.B, circle.center, true);
  327.         }
  328.         else {
  329.             throw new IllegalArgumentException("The provided edge: " + edge + " does not match with any of the triangle's edges.");
  330.         }
  331.        
  332.         textAndStep("vector to circle = " + vecToCircle);
  333.         vector.hide();
  334.        
  335.         float dot = normalizedEdge.dot(vecToCircle);
  336.         line = makeLine(start.x, start.y, start.x + dot, start.y + dot, false);
  337.         textAndStep("dot product of normalizedEdge and vectorToCircle = " + dot);
  338.         line.hide();
  339.        
  340.         Vector2f closestPointToCircle;
  341.         if(dot <= 0) {
  342.             closestPointToCircle = start;
  343.         }
  344.         else if(dot >= edge.length()) {
  345.             closestPointToCircle = end;
  346.         }
  347.         else {
  348.             closestPointToCircle = normalizedEdge.mul(dot).add(start);
  349.         }
  350.        
  351.        
  352.         line = makeLine(start, closestPointToCircle, false);
  353.         textAndStep("closest point to circle = " + closestPointToCircle);
  354.         line.hide();
  355.        
  356.         // check if the other vertex (the one that is not part of the current edge) and the circle-center lie on opposite sides of the edge
  357.         Vector2f vecFromClosestPointToCircle        = circle.center.sub(closestPointToCircle);
  358.         vectors[0] = makeLine(closestPointToCircle, circle.center, true);
  359.         textAndStep("vector from closest point to circle = " + vecFromClosestPointToCircle);
  360.        
  361.         Vector2f vecFromClosestPointToOtherVertex   = other.sub(closestPointToCircle);
  362.         vectors[1] = makeLine(closestPointToCircle, other, true);
  363.         textAndStep("vector from closest point to other vertex = " + vecFromClosestPointToOtherVertex);
  364.        
  365.         boolean isOppositeOtherVertex               = vecFromClosestPointToCircle.dot(vecFromClosestPointToOtherVertex) < 0;
  366.         vectors[0].changeColor("", Color.BLUE, null, null);
  367.         vectors[1].changeColor("", Color.BLUE, null, null);
  368.         textAndStep("other vertex on opposite side of circle = " + isOppositeOtherVertex);
  369.        
  370.         vectors[0].hide();
  371.         vectors[1].hide();
  372.        
  373.         boolean radius_less_than_dist_to_closest_point = circle.radius < vecFromClosestPointToCircle.length();
  374.         textAndStep("radius less than distance to closest point = " + radius_less_than_dist_to_closest_point);
  375.        
  376.         boolean result = radius_less_than_dist_to_closest_point && isOppositeOtherVertex;
  377.         line = makeLine(closestPointToCircle, circle.center, false);
  378.         line.changeColor("", result ? Color.GREEN : Color.RED, null, null);
  379.         if(result) {
  380.             separatingAxis = makeLine(closestPointToCircle, circle.center, false);
  381.         }
  382.         textAndStep("is separating axis = " + result);
  383.         line.hide();
  384.         if(separatingAxis != null) {
  385.             separatingAxis.hide(); 
  386.         }
  387.         return result;
  388.     }
  389.    
  390.    
  391.     // ====================================================================================================================================
  392.     // ====================================================================================================================================
  393.    
  394.     private Circle makeCircle(float x, float y, float radius) {
  395.         return makeCircle((int)x, (int)y, (int)radius);
  396.     }
  397.    
  398.     private Circle makeCircle(int x, int y, int radius) {
  399.         return new Circle(new AnimalCircleGenerator(lang), transformCoords(x, y), transformRadius(radius), "circle", null, circleProps);
  400.     }
  401.    
  402.     private Triangle makeTriangle(Vector2f A, Vector2f B, Vector2f C) {
  403.         return makeTriangle(A.x, A.y, B.x, B.y, C.x, C.y);
  404.     }
  405.    
  406.     private Triangle makeTriangle(float Ax, float Ay, float Bx, float By, float Cx, float Cy) {
  407.         return makeTriangle((int)Ax, (int)Ay, (int)Bx, (int)By, (int)Cx, (int)Cy);
  408.     }
  409.    
  410.     private Triangle makeTriangle(int Ax, int Ay, int Bx, int By, int Cx, int Cy) {
  411.         return new Triangle(new AnimalTriangleGenerator(lang),
  412.                 transformCoords(Ax, Ay),
  413.                 transformCoords(Bx, By),
  414.                 transformCoords(Cx, Cy),
  415.                 "triangle",
  416.                 null,
  417.                 triangleProps);
  418.     }
  419.    
  420.     private Coordinates transformCoords(int x, int y) {
  421.         // TODO: refactor magic numbers
  422.         int newX = 600 + 40 * x;
  423.         int newY = 300 - 40 * y;
  424.         return new Coordinates(newX, newY);
  425.     }
  426.    
  427.     private int transformRadius(int radius) {
  428.         // TODO: refactor magic numbers
  429.         int newRadius = 40 * radius;
  430.         return newRadius;
  431.     }
  432.    
  433.     private Rect makeRect(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY) {
  434.         return makeRect((int)upperLeftX, (int)upperLeftY, (int)lowerRightX, (int)lowerRightY);
  435.     }
  436.    
  437.     private Rect makeRect(int upperLeftX, int upperLeftY, int lowerRightX, int lowerRightY) {
  438.         return new Rect(new AnimalRectGenerator(lang), new Coordinates(upperLeftX, upperLeftY), new Coordinates(lowerRightX, lowerRightY), "rect", null, rectProps);
  439.     }
  440.    
  441.     private Text makeText(String text, int x, int y) {
  442.         return new Text(new AnimalTextGenerator(lang), new Coordinates(x, y), text, "text", null, textProps);
  443.     }
  444.    
  445.     // TODO: in future probably not needed, possibly delete
  446.     private int getY(auxiliary.Circle circle, auxiliary.Triangle triangle) {
  447.         float lowest = circle.center.y + circle.radius;
  448.        
  449.         // origin at top left, hence ">"
  450.         if(triangle.A.y > lowest) {
  451.             lowest = triangle.A.y;
  452.         }
  453.         else if(triangle.B.y > lowest) {
  454.             lowest = triangle.B.y;
  455.         }
  456.         else if(triangle.C.y > lowest) {
  457.             lowest = triangle.C.y;
  458.         }
  459.        
  460.         return (int)lowest + offsetY;
  461.     }
  462.    
  463.     private void textAndStep(String text) {
  464.         textAndStep(text, this.x, this.y);
  465.     }
  466.    
  467.     private void textAndStep(String text, int x, int y) {
  468.         textList.add(makeText(text, x, y));
  469.         this.y += offsetY;
  470.         lang.nextStep();
  471.     }
  472.    
  473.     private void clearText() {
  474.         for(Text text : textList) {
  475.             text.setText("", null, null);
  476.         }
  477.        
  478.         textList = new ArrayList<>();
  479.     }
  480.    
  481.     private Point makePoint(int x, int y) {
  482.         return new Point(new AnimalPointGenerator(lang), new Coordinates(x, y), "point", null, pointProps);
  483.     }
  484.    
  485.     private Polyline makeLine(Vector2f from, Vector2f to, boolean isVector, boolean needsTransform) {
  486.         return makeLine((int)from.x, (int)from.y, (int)to.x, (int)to.y, isVector, needsTransform);
  487.     }
  488.    
  489.     private Polyline makeLine(float startX, float startY, float endX, float endY, boolean isVector, boolean needsTransform) {
  490.         return makeLine((int)startX, (int)startY, (int)endX, (int)endY, isVector, needsTransform);
  491.     }
  492.    
  493.     private Polyline makeLine(int startX, int startY, int endX, int endY, boolean isVector, boolean needsTransform) {
  494.         Node[] nodeArray;
  495.         if(needsTransform) {
  496.             nodeArray = new Node[] {
  497.                     transformCoords(startX, startY),
  498.                     transformCoords(endX, endY)
  499.             };
  500.         }
  501.         else {
  502.             nodeArray = new Node[] {
  503.                     new Coordinates(startX, startY),
  504.                     new Coordinates(endX, endY)
  505.             };
  506.         }
  507.        
  508.         return new Polyline(new AnimalPolylineGenerator(lang), nodeArray, "line", null, isVector ? vectorProps : lineProps);
  509.     }
  510.    
  511.     private void makeHeader() {
  512.         makeRect(430, 25, 790, 50);
  513.        
  514.         TextProperties titleProps = new TextProperties();
  515.         titleProps.set(AnimationPropertiesKeys.FONT_PROPERTY, new Font("Arial", Font.BOLD, 16));
  516.         new Text(new AnimalTextGenerator(lang), new Coordinates(450, 27), "Separating Axis Theorem (Circle-Triangle)", "title", null, titleProps);
  517.     }
  518.    
  519.     private void makeSideBox() {
  520.         makeRect(900, 150, 1300, 380);
  521.     }
  522.    
  523.     private void drawCoordSystem() {
  524.         int xAxis       = 300;
  525.         int xAxisStart  = 400;
  526.         int xAxisEnd    = 800;
  527.        
  528.         int yAxis       = 600;
  529.         int yAxisStart  = 500;
  530.         int yAxisEnd    = 100;
  531.        
  532.         makeLine(xAxisStart, xAxis, xAxisEnd, xAxis, false);    // x-axis (600px)
  533.         makeLine(yAxis, yAxisStart, yAxis, yAxisEnd, false);    // y-axis (400px)
  534.        
  535.         int offset = 40;    // 60px = 1cm
  536.        
  537.         // x-axis
  538.         for(int i=xAxisStart; i <= xAxisEnd; i+=offset) {
  539.             makeLine(i, xAxis-5, i, xAxis+5, false);
  540.         }
  541.        
  542.         // y-axis
  543.         for(int i=yAxisStart; i >= yAxisEnd; i-=offset) {
  544.             makeLine(yAxis-5, i, yAxis+5, i, false);
  545.         }
  546.     }
  547.    
  548.     // ====================================================================================================================================
  549.     // ====================================================================================================================================
  550.     // ====================================================================================================================================
  551.     // ====================================================================================================================================
  552.     // ====================================================================================================================================
  553.     // ====================================================================================================================================
  554.    
  555.     public static void main(String[] args) {
  556.         // careful: animalscript y-coord goes downwards (i.e. 110 is below 100)
  557.         SAT sat = new SAT();
  558.         sat.init();
  559.        
  560.         auxiliary.Circle C = new auxiliary.Circle(new Vector2f(-2, 1), 2);
  561.         auxiliary.Triangle T = new auxiliary.Triangle(new Vector2f(1, 1), new Vector2f(3, 1), new Vector2f(2, 4));
  562.         sat.hasSA(C, T);
  563.        
  564.         System.out.println(sat.lang);
  565.     }
  566.    
  567.    
  568.     public void showSourceCode() {
  569.         // first set the visual properties for the source code
  570.         SourceCodeProperties scProps = new SourceCodeProperties();
  571.         scProps.set(AnimationPropertiesKeys.CONTEXTCOLOR_PROPERTY, Color.BLUE);
  572.         scProps.set(AnimationPropertiesKeys.FONT_PROPERTY, new Font("Monospaced", Font.PLAIN, 12));
  573.         scProps.set(AnimationPropertiesKeys.HIGHLIGHTCOLOR_PROPERTY, Color.RED);
  574.         scProps.set(AnimationPropertiesKeys.COLOR_PROPERTY, Color.BLACK);
  575.        
  576.         // now create the source code entity
  577.         sc = lang.newSourceCode(new Coordinates(40, 240), "sourceCode", null, scProps);
  578.         // add code lines (the actual sorting algo)
  579.         // parameters: code itself, name (can be null), indention level, display options
  580.         sc.addCodeLine("line0", null, 0, null);
  581.         sc.addCodeLine("line1", null, 0, null);
  582.         sc.addCodeLine("line2", null, 0, null);
  583.         sc.addCodeLine("line3", null, 0, null);
  584.         sc.addCodeLine("line4", null, 0, null);
  585.         sc.addCodeLine("line5", null, 0, null);
  586.         sc.addCodeLine("line6", null, 0, null);
  587.         sc.addCodeLine("line7", null, 0, null);
  588.         sc.addCodeLine("line8", null, 0, null);
  589.         sc.addCodeLine("line9", null, 0, null);
  590.     }
  591. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement