I am writing Mine Sweeper for the Ti 84 CE in basic. I am currently improving the version I had written entirely on the calculator itself and so far I've made it much faster via better algorithms. The one thing I can't seem to figure out is how to draw squares fast. My old method was to draw 9 lines, but I found that this took awhile. I then discovered that Pt-On commands were pretty fast at drawing pixels with the drawback that they have a limited amount of shapes.

(Using a window of X:0,264 Y:0,-164)


Current Method for drawing a 9x9 square:
For(J,4,­4,­1)
Line(D-4,C+J,D+4,C+J,ORANGE,1)
End


This is what I found to be the fastest for a 7x7 square, one of them draws a 7x7 square with a 3x3 hole in the middle, the other draws a 3x3 square to fill the hole. It seems to be faster than drawing lines:
Pt-On(X,Y,1,ORANGE)
Pt-On(X,Y,2,ORANGE)


The fastest I could come up with for a 9x9 square involved 5 steps:
Pt-On(X-1,Y-1,2,ORANGE)
Pt-On(X+1,Y+1,2,ORANGE)
Pt-On(X-1,Y+1,1,ORANGE)
Pt-On(X+1,Y-1,1,ORANGE)
Pxl-On(Y,X,ORANGE)


It is a bit slow, and I am unsure if it is faster than drawing 9 lines. Is there a faster way to do this? (I plan to create the whole game in pure Ti Basic)

Here are the steps in action along with the 3 special shapes that can be drawn with Pt-On
This is a neat problem, both for the 9x9 and the general case, but there's also a relatively boring solution that circumvents all of it.

First off, there is actually a 4th point type, which is just a single pixel. This can useful if you don't want to juggle graph and pixel coordinates, but it's also slower and you already use a standard graphing window.

Secondly, one can achieve a 9x9 square with just 4 primitives (not including Text( characters, though those come with some baggage), which is ergo smaller in bytes and still faster than pure Lines:



The black strip is the visible part of a 7x7 box, and the blue strip is a Line. Unfortunately, that Line makes the whole draw time take a hit, as after testing it took about 3 extra seconds to fill the whole screen with squares. I'd be interested, though, how you could draw larger squares with these primitives. Two is certainly optimal for a 7x7, and I'd bet 4 is for a 9x9; attempts to use a hacky diagonal line that need only 3 result in stray pixels the optimal value of 3 can be achieved using a one-wide diagonal line as found by womp.

Finally, though, there is the fact that GridLine exists. This command will fill the graphscreen with a grid of prescribed color, with the X-Y scales set by the Window vars Xscl and Yscl. The Background color then becomes your square color.

Even if you're only filling part of the screen with the squares (which I assume you would be in order to display other information to the player), you can simply fill just that section over with solid color or other elements. Better yet, you can just draw a partial grid yourself with Horizontal and Vertical, which are both faster than Line.

These will be the fastest ways to initialize the game state by far, but from there you will need ways to draw individual squares that get flagged or revealed (unless you just use Text everywhere), and then you can rely on whichever method depending on your optimization preference.
9x9 is a tricky one. I suspect a line with 2 squares would be faster.
kg583 wrote:
Finally, though, there is the fact that GridLine exists. This command will fill the graphscreen with a grid of prescribed color, with the X-Y scales set by the Window vars Xscl and Yscl. The Background color then becomes your square color.


I have done that in my program. I fill the screen with the Medium Gray Grid-Line to color the squares/tiles, then I drew Light Grey Rectangles with Lines to clear out the 2-3 pixels on the sides and ~20 pixels at the top.

Drawing the 9x9 squares is an issue since they take awhile to draw, so it takes a bit to move from one end of the board to another. This is because I have to draw 2 squares to move an orange selection square around.
The other more problematic issue is the Flood Fill Algorithm, which automatically clears tiles. The C version of MineSweeper can clear a large amount of tiles in less than a second, Ti Basic however takes over a minute sometimes to do so, since it has to individually fill in each tile, and calculate what order to fill them in.

Image of the game:
If you plan on displaying a lot of squares, I would recommend looking into Plot Sprites which are the fastest way to print out those points you pictures above. From my limited testing, they seem to be up to 25% faster than Pt-On().

You just need lists containing the x and y coordinates each point needs to be. Remember, lists can only be 999 elements in length, but you have 3 Plots to work with, each can be it's own color. If you need help, TI-Basic Dev might be of assistance: http://tibasicdev.wikidot.com/plotn
  
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 UTC - 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

 

Advertisement