Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I recently purchased a new 84+CE, and have been playing with color in BASIC. I thought up of a simple plotter that uses the color as a sort of Z to plot "3d" functions in 2d, like a gradient. I have working code using 9 colors, even "dithering" in-between. Here is the code:

Input "Z=",Str1
Str1→|u //sets the z function to u for easy evaluation
//May want to use Y1 or some other function
Input "ZMIN=",I
Input "ZMAX=",J //sets upper and lower boundaries for the colors
{2,7,0,8,4,9,5,1,3}→L1 //9 colors in order minus 10: bk, navy, bl, lt bl, g, y, o, r, m
For(A,0,54 //55 "points" vertical
For(B,0,87 //88 "points" horizontal
Xmin+(3B+1)deltaX→X //calculate x and y values given A and B
Ymax-(3A+1)deltaY→Y //might should do this in the for loop declarations
|u→C //calculate Z with given x,y
(min(9,max(1,1+iPart((C-I)/(J-I)*9-.25+fPart((A+B)/2→C //calculate the level between 1-9
      //min and max bound the calcuation,
      //(C-I)/(J-I) gives a value from 0 to 1 if C falls within I and J
      //multiply by nine and add the -.25+fpart(A+B)/2 for checkerboard dithering
10+L1(C→C //index 1-9 of the color list, add to 10, gives color code.
Pt-On(X,Y,C //color that point!

It works pretty well, but is awfully slow. I have a few ideas to make it faster, but need some fresh eyes. Am I missing anything glaring that would make this much faster?
Add a step value in your two loops.
It will be a little bit hugly but speed will be improved.

You can also try to make an ICE version but you have to carefully manage divide operator because at this date, ICE manage integer value to improve speed for graphics. (and save all your programs before because if you make a big error, it can clean your memory. (well, your calculator's memory))
Precompute 9/(J-I) and L1. Do everything in one line to reduce interpreter overhead. Since the step in the For loops loses you A+B, you'll have to repeat this line and alternate a value between .75 and 1.25 to do dithering.

Input Input "Z=",Str1
Input "ZMIN=",I
Input "ZMAX=",J

At this point it's still pretty slow, but the loops are now tight and there's not much more to optimize. Change languages for a significant improvement.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum