_TITLE "Plot v2_SierraKen > 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?
'2019-09-19 post plot 2 with better Y scale except when precision needs to go beyond 2 places!
' We practice with a LOG(x) example and learned LOG10(x) = LOG(x)/LOG(10) thanks to QB64 Help!
' Need to do with x scale what we did with y scale after solve prcision problem = picking the
' right precision for displays.
'2019-09-19 Plot v KenSierra add ABS function for Ashish, now with Opening inputs screen in main loop.
debug = 0
'evaluate$ and evalW setup
DFlag = 0
EvalErr$ = ""
GlobalX = 5 'changeable
Split "abs, int, sin, cos, tan, asin, acos, atan, log, exp, sqr, rad, deg, ", ", ", fList()
Split "^, %, /, *, -, +, =, <, >, <=, >=, <>, or, and, not", ", ", oList()
COLOR &HFFBBBBFF, &HFF000066 yCP 40, "Welcome to Plot v2_SierraKen by B+ 2019-09-19"
yCP 80, "Here is a listing of functions available so far:"
yCP 100, "abs, int, sin, cos, tan, asin, acos, atan, log, exp, sqr, rad, deg"
yCP 140, " Please enter a function to plot in terms of x, ie x^2 + 4*x + 3 (nothing quits) "
LOCATE 13, 40:
INPUT "Please enter lowest X for range "; lowX$
LOCATE 15, 40:
INPUT "Please enter highest X in range "; highX$
plot
fn$
+ "," + lowX$
+ "," + highX$
DIM func$
, LX
, UX
, dx
, dy
, x
, y
, LY
, UY
, clicks
, midY
, s$
, mx
, my
, gx
, gy
, p10
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 = " + xDP$(LX, 2) + " to " + xDP$(UX, 2) + " steps every " + xDP$(clicks, 2)
drawscale LY, UY
'clicks = (UY - LY) / 10
y = (table(x) - LY) / dy
'LINE (x + 99, 599 - y)-STEP(2, 2), &HFF0000FF, BF
PSET (x
+ 100, 600 - y
), &HFF0000FF 'use a fine line because we have very large x Range gx = (mx - 100) / 1000 * (UX - LX) + LX
gy = (600 - my) / 500 * (UY - LY) + LY
yCP 80, "X = " + xDP$(gx, 2) + ", Y = " + xDP$(gy, 2)
clicks = (UY - LY) / 10
p10 = -10
p10 = p10 + 1
p10 = p10 - 1
digit
= INT(clicks
/ (10 ^ p10
)) units = digit * 10 ^ p10
'PRINT p10, digit, units
midY = pixY(0, LY, UY)
ty = units
WHILE pixY
(ty
, LY
, UY
) >= 100 'from 0 + unit go up unit by unit gy = pixY(ty, LY, UY)
ty = ty + units
ty = -units
WHILE pixY
(ty
, LY
, UY
) <= 600 'from 0 - unit go down unit by unit gy = pixY(ty, LY, UY)
ty = ty - units
ty = 0
WHILE pixY
(ty
, LY
, UY
) < 600 'find first unit below or at bottom of graph ty = ty - units
ty = ty + units
' now go up drawing marks
WHILE pixY
(ty
, LY
, UY
) >= 100 gy = pixY(ty, LY, UY)
ty = ty + units
pixY = 600 - 500 * (graphY - lowY) / (UpY - lowY)
'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 "abs": m$
= ls$
(ABS(innerVal
)) 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
SUB yCP
(y
, s$
) 'for xmax pixel wide graphics screen Center Print at pixel y row
xx = x + .5 * 10 ^ -DP