Log In  

Cart #15344 | 2015-10-13 | Code ▽ | Embed ▽ | No License
10


I was experimenting with compression and created a simple shape drawing library. Even with the flood fills the cpu was barely affected, so this seems like a legitimate drawing tool, and only costs 10 tokens per drawn shape! Here's the documentation if anyone looks into the code:

shape(x, y, rotation, drawstring):
draws a shape on screen, starting the cursor at x,y, with rotation from 0 to 1 at the origin (cursor start pos).

drawstring: a set of commands to draw, as a string (1 token!).

drawstring commands:
"C" color - set drawing Color (for lines and fills). color is a hex value 0-F.
"T" x y - move cursor relative To current position, drawing nothing. x and y are chars from "0"-"9"-"A"-"G", which represent -8 to 8. So "T00" means "to -8, -8", and "TGG" means "to 8, 8".
"L" x y - draw Line from current position to next position. x and y are 0-9+A-G as described above.
"F" x y stopcolor - flood Fill a region with drawing color until you encounter stopcolor. This fully works with rotation by filling the next (rotated) position defined by x,y. x and y are 0-9+A-G as described above, color is a hex value 0-F.

I will probably improve this library if people are interested, but for now I thought it was a fun little idea that only took a few hours to implement. Triangles and hexagons are easy now! =)

P#15345 2015-10-13 03:21 ( Edited 2016-09-17 19:32)

1

Hi Innomin,

Storing the drawing commands in strings is a great idea--especially because it let's you use code space as opposed to having to store things in the sounds / sprite-sheet / map etc. I only wish there was a good way to get exportable text out of the program. On Windows, the debug print command doesn't actually print to the console/command prompt. :-(

For filling polygons, I have been working with a raster algorithm because it handles overlap better than a flood fill and you don't have to worry about starting points or leaks. (Well, really it just draws the whole polygon every time.) Here's what I based my code on: https://www.cs.rit.edu/~icss571/filling/example.html (I'm in the process of accelerating my code by pre-calculating what I can and trimming fat...)

One thing, it looks like CPU load is a little higher than you estimated (~1 frame)--need to check before and after drawing the polygons. Still, it's a great demo.

-ElectricGryphon

P#15396 2015-10-15 12:11 ( Edited 2016-03-25 02:43)
1

i know this post is a million years old, but just wanted to say thanks. this library with a little fiddling just solved a problem ive been banging my head against for hours

P#28682 2016-09-17 15:32 ( Edited 2016-09-17 19:32)

how do you do anything i only do javascript

P#76916 2020-05-19 17:28

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 07:39:44 | 0.009s | Q:19