mr. engino Posted November 7, 2021 Share Posted November 7, 2021 I'm currently writing programs to use the Atari 8-bit emulator like a crude graphing calculator. While I figured out how to make graphs appear on the screen, I have some trouble with connecting the plotted points together to get a better sense of what I'm looking at. Drawto seems to be the correct command to use, but it doesn't always work out on every function I plot out; sometimes it works, and other times it causes a numerical overflow error trying to plot a number too big for the limited screen dimensions. Is there a trick to getting the points connected together that isn't super dependent on the function I define? Quote Link to comment Share on other sites More sharing options...
matosimi Posted November 7, 2021 Share Posted November 7, 2021 Your request is kind of funny, getting points connected together not depending on function you define. Sounds like random points connected with lines Ok, now the solution... I anticipate you are doing this in basic. You simply have to clip your coordinates to the size of screen. Easiest fix would be to check if coordinates of next point are positive numbers, and if so whether x coord. Is lower than 320 and y coord. lower than 192....(assuming gr.8) So if all these conditions applies then call drawto. If not, skip the point. Also very next valid point should be drawn with Plot and all the next valid ones with drawto again. Other fix, nicer but more complicated would be to calculate intersection between your line and screen bounds, by using simple goniometric calculations. I suppose if you are working on some graph calculator, you know how to calculate it since it is elementary school stuff. Don't forget to use DEG to switch to degrees. Then it is basically ATN of division of differences between x and y coordinates, that's the way to get the angle of the line to be drawn. Next step is to use the angle to calculate point of screen intersection using SIN and COS. It may require multiple variants depending on which screen bound the line crosses. 1 Quote Link to comment Share on other sites More sharing options...
Rybags Posted November 7, 2021 Share Posted November 7, 2021 (edited) Clipping coordinates likely won't be helpful as the gradient of the line would then be wrong (assuming line graph with connected points) The OS actually allows some overdraw in a destination for the DRAWTO then just spits up ERROR 141 once a coordinate is out of range so at least there you'll have the proper gradient. Problem is, negative values aren't allowed and the positive values have their bounds constrained - Y values can't go beyond 255 though big X values seem to be permitted. Probably the best you could do is constrain your graph so it stays onscreen. e.g. Calculate what the bar heights will be then scale them back. Similar deal if it's connected points in a line graph. Edited November 7, 2021 by Rybags Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted November 7, 2021 Share Posted November 7, 2021 Maybe the attached program does already what you like? If not, browsing through the Turbo-Basic source code could be helpful... Analysis.atr 2 Quote Link to comment Share on other sites More sharing options...
mr. engino Posted November 9, 2021 Author Share Posted November 9, 2021 On 11/7/2021 at 8:45 AM, Irgendwer said: Maybe the attached program does already what you like? If not, browsing through the Turbo-Basic source code could be helpful... Analysis.atr 90.02 kB · 6 downloads I was kinda hoping I could code my own, but I guess this'll do. I don't suppose there's an English translation? I'm not fluent in German. Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted November 9, 2021 Share Posted November 9, 2021 15 hours ago, mr. engino said: I was kinda hoping I could code my own, but I guess this'll do. I don't suppose there's an English translation? I'm not fluent in German. No English translation yet, but if you like to create one... ...most strings should go easily through Google translate and you could release a patched version? 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.