Skip to content

Commit

Permalink
draw arrows to indicate line sides in sine (the lines push bodies only
Browse files Browse the repository at this point in the history
in one direction)
  • Loading branch information
vipaoL committed Aug 18, 2024
1 parent 0922bb6 commit 0a8b716
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/mobileapplication3/elements/Sine.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/
package mobileapplication3.elements;

import javax.microedition.lcdui.Graphics;

import mobileapplication3.utils.Mathh;
import mobileapplication3.utils.Utils;

/**
*
Expand Down Expand Up @@ -334,4 +337,34 @@ public void recalcCalculatedArgs() {
calcAnchorPoint();
}

public void paint(Graphics g, int zoomOut, int offsetX, int offsetY) {
if (pointsCache == null) {
genPoints();
}

if (pointsCache.getSize() == 0) {
return;
}

short[] startPoint = pointsCache.getPoint(0);
for (int i = 0; i < pointsCache.getSize() - 1; i++) {
short[] endPoint = pointsCache.getPoint(i+1);
int x1 = xToPX(startPoint[0], zoomOut, offsetX);
int y1 = yToPX(startPoint[1], zoomOut, offsetY);
int x2 = xToPX(endPoint[0], zoomOut, offsetX);
int y2 = yToPX(endPoint[1], zoomOut, offsetY);
Utils.drawLine(g, x1, y1, x2, y2, LINE_THICKNESS, zoomOut);
if (i % 2 == 0) {
int dx = x2 - x1;
int dy = y2 - y1;
int l = Mathh.calcDistance(dx, dy);
int centerX = (x1 + x2) / 2;
int centerY = (y1 + y2) / 2;
int lzoomout = l * zoomOut;
Utils.drawArrow(g, centerX, centerY, centerX + dy * 50000 / lzoomout, centerY - dx * 50000 / lzoomout, LINE_THICKNESS/6, zoomOut);
}
startPoint = endPoint;
}
}

}
9 changes: 4 additions & 5 deletions src/mobileapplication3/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ public static String replace(String _text, String _searchStr, String _replacemen
public static void drawArrow(Graphics g, int x1, int y1, int x2, int y2, int thickness, int zoomOut) {
int dx = x2 - x1;
int dy = y2 - y1;
int ang = Mathh.arctg(dx, dy);
int arrowX = (x2*9 + x1) / 10;
int arrowY = (y2*9 + y1) / 10;
int arrowSideVecX = 2 * thickness * Mathh.cos(ang + 90) / zoomOut;
int arrowSideVecY = 2 * thickness * Mathh.sin(ang + 90) / zoomOut;
int arrowX = (x2*5 + x1) / 6;
int arrowY = (y2*5 + y1) / 6;
int arrowSideVecX = dy / 8;
int arrowSideVecY = -dx / 8;
drawLine(g, x1, y1, arrowX, arrowY, thickness, zoomOut, false, false);
drawTriangle(g, x2, y2, arrowX + arrowSideVecX, arrowY + arrowSideVecY, arrowX - arrowSideVecX, arrowY - arrowSideVecY, zoomOut);
}
Expand Down

0 comments on commit 0a8b716

Please sign in to comment.