_TITLE "Plot > Point mouse for coordinates" ' started 2019-09-14 B+ ' from: Remake Eval 2018-09-16 5:53 PM
' goals test remake eval and plot math functions
'2019-09-14 basic plot working, now for sensable ticks on axis
' OK maybe do some replotting with mousedown and setting up new rectangle area
' On the other hand we could plot data from a file?
debug = 0
'evaluate$ and evalW setup
DFlag = 0
EvalErr$ = ""
GlobalX = 5 'changeable
Split "int, sin, cos, tan, asin, acos, atan, log, exp, sqr, rad, deg,", ", ", fList()
Split "^, %, /, *, -, +, =, <, >, <=, >=, <>, or, and, not", ", ", oList()
'DIM x
plot "x^2, -50, 50"
'plot "sin(x)^2 + sin(x), -6.3, 6.3"
DIM func$
, LX
, UX
, dx
, dy
, x
, y
, LY
, UY
, clicks
, midY
, s$
, mx
, my
, gx
, gy
Split pList$, ",", p()
func$
= p
(1): LX
= VAL(p
(2)): UX
= VAL(p
(3)) dx = (UX - LX) / 1000
GlobalX = LX + x * dx
table
(x
) = VAL(Evaluate$
(func$
)) LY = table(x): UY = table(x)
IF table
(x
) < LY
THEN LY
= table
(x
) IF table
(x
) > UY
THEN UY
= table
(x
) dy = (UY - LY) / 500
clicks = (UX - LX) / 20
yCP 42, "Plot " + func$
yCP 640, "For x = " + dp2$(LX) + " to " + dp2$(UX) + " steps every " + dp2$(clicks)
clicks = (UY - LY) / 10
midY = 600 - (0 - LY) / dy
y = (table(x) - LY) / dy
LINE (x
+ 100, 600 - y
)-STEP(2, 2), &HFF0000FF, BF
PSET (x
+ 100, 600 - y
), &HFF0000FF gx = (mx - 100) / 1000 * (UX - LX) + LX
gy = (600 - my) / 500 * (UY - LY) + LY
yCP 80, "X = " + dp2$(gx) + ", Y = " + dp2$(gy)
'this preps e$ string for actual evaluation function and makes call to it,
'checks results for error returns that or string form of result calculation
'the new goal is to do string functions along side math
' isolateNeg = 0
b$ = "" 'rebuild string with padded spaces
'this makes sure ( ) + * / % ^ are wrapped with spaces, on your own with - sign
FOR i
= 1 TO LEN(e$
) 'filter chars and count () po = po - 1: b$ = b$ + " ) "
po = po + 1: b$ = b$ + " ( "
b$ = b$ + " " + c$ + " "
b$ = b$ + " " + c$ + " "
b$ = b$ + " " + c$
b$ = b$ + " " + c$
b$ = b$ + c$
Split b$, " ", ev()
c$ = evalW$(ev())
IF EvalErr$
<> "" THEN Evaluate$
= EvalErr$
ELSE Evaluate$
= c$
' the recursive part of EVAL
DIM fun$
, test$
, innerV$
, m$
, op$
PRINT "evalW rec'd a() as:" pop = find%(a(), "(") 'parenthesis open place
fun$ = "": lPlace = 1
test$ = a(pop - 1)
IF find%
(fList
(), test$
) > 0 THEN fun$ = test$: lPlace = pop - 1
fun$ = "": lPlace = pop
po = 1
IF a
(i
) = "(" THEN po
= po
+ 1 IF a
(i
) = ")" THEN po
= po
- 1 FOR i
= (pop
+ 1) TO (rPlace
- 1) index = index + 1
inner(index) = a(i)
IF find%
(oList
(), a
(i
)) > 0 THEN recurs
= -1 IF recurs
THEN innerV$
= evalW$
(inner
()) ELSE innerV$
= a
(pop
+ 1)
CASE "int": m$
= ls$
(INT(innerVal
)) CASE "exp" 'the error limit is inconsistent in JB IF -745 <= innerVal
AND innerVal
<= 709 THEN 'your system may have different results 'what the heck???? 708 works fine all alone as limit ?????
EvalErr$
= "EXP(n) only works for n = -745 to 709.":
EXIT FUNCTION EvalErr$
= "SQR only works for numbers >= 0.":
EXIT FUNCTION CASE "rad": m$
= ls$
(innerVal
* RAD
) CASE "deg": m$
= ls$
(innerVal
* DEG
) PRINT "lPlace, rPlace"; lPlace
, rPlace
arrSubst a(), lPlace, rPlace, m$
PRINT "After arrSubst a() is:" pop = find%(a(), "(")
'all parenthesis cleared
'ops$ = "% ^ / * + - = < > <= >= <> and or not" 'all () cleared, now for binary ops (not not binary but is last!)
op$ = oList(o)
p = find%(a(), op$)
EvalErr$ = "For a Mod b, b value < 2."
m$ = ls$(a ^ b)
EvalErr$ = "For a ^ b, a needs to be >= 0 when b not integer."
m$ = ls$(a / b)
EvalErr$ = "Div by 0"
CASE "*": m$
= ls$
(a
* b
) CASE "-": m$
= ls$
(a
- b
) CASE "+": m$
= ls$
(a
+ b
) CASE "not":
IF b
= 0 THEN m$
= "-1" ELSE m$
= "0" 'use b as nothing should be left of not arrSubst a(), p - 1, p + 1, m$
PRINT "a() reloaded after " + op$
+ " as:"
p = find%(a(), op$)
fun$ = ""
fun$ = fun$ + " " + a(i)
a(substLow) = subst: index = substLow + 1
a(index) = a(i): index = index + 1
'notes: REDIM the array(0) to be loaded before calling Split '<<<<<<<<<<<<<<<<<<<<<<< IMPORTANT!!!!
' bplus modifications of Galleon fix of Bulrush Split reply #13
' http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=1612.0
' this sub further developed and tested here: \test\Strings\Split test.bas
' 2018-09-16 modified for base 1 arrays
copy = mystr 'make copy since we are messing with mystr
'special case if delim is space, probably want to remove all excess space
copy
= MID$(copy
, 1, p
- 1) + MID$(copy
, p
+ 1) curpos = 1
arrpos = 1
dpos
= INSTR(curpos
, copy
, delim
) arr
(arrpos
) = MID$(copy
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos
= dpos
+ LEN(delim
) dpos
= INSTR(curpos
, copy
, delim
) arr
(arrpos
) = MID$(copy
, curpos
)
'assume a() is base 1 array so if find comes back as 0 then found nothing
'ltrim a number float
'FUNCTION xDP$ (x, DP)
' DIM xs$, dot AS INTEGER
' IF x < 0 THEN xs$ = STR$(x - .5 * 10 ^ -DP)
' IF x > 0 THEN xs$ = STR$(x + .5 * 10 ^ -DP)
' IF INSTR(xs$, "D") > 0 OR INSTR(xs$, "E") > 0 THEN EXIT FUNCTION 'not dealing with exponents today
' dot = INSTR(xs$, ".")
' IF xs$ = "" OR ABS(x) < .5 * 10 ^ -DP THEN xs$ = "0"
' IF dot THEN xDP$ = MID$(xs$, 1, dot) + MID$(xs$, dot + 1, DP) ELSE xDP$ = xs$
'END FUNCTION
SUB yCP
(y
, s$
) 'for xmax pixel wide graphics screen Center Print at pixel y row