From 0a8b716ae27c4930a962d0c81beeb2049daaa4f8 Mon Sep 17 00:00:00 2001 From: vipoll Date: Sun, 18 Aug 2024 22:09:53 +0400 Subject: [PATCH] draw arrows to indicate line sides in sine (the lines push bodies only in one direction) --- src/mobileapplication3/elements/Sine.java | 33 +++++++++++++++++++++++ src/mobileapplication3/utils/Utils.java | 9 +++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/mobileapplication3/elements/Sine.java b/src/mobileapplication3/elements/Sine.java index 847b5c8..fc7ae83 100644 --- a/src/mobileapplication3/elements/Sine.java +++ b/src/mobileapplication3/elements/Sine.java @@ -5,7 +5,10 @@ */ package mobileapplication3.elements; +import javax.microedition.lcdui.Graphics; + import mobileapplication3.utils.Mathh; +import mobileapplication3.utils.Utils; /** * @@ -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; + } + } + } diff --git a/src/mobileapplication3/utils/Utils.java b/src/mobileapplication3/utils/Utils.java index 981cdff..f81319b 100644 --- a/src/mobileapplication3/utils/Utils.java +++ b/src/mobileapplication3/utils/Utils.java @@ -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); }