? Turtle library + Anti-aliased line library ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Turtle library + Anti-aliased line library

Submitted
Updated
Author
niconii
Public Key
Q3V3SX6D
Min. Compat.
All
Version
1.0.1
Size
9 KB
Rating
5 votes
Description TURTLE.LIB is a library for drawing turtle graphics, as in the Logo programming language or Python's built-in turtle library. Basically, you control a pen or "turtle" that can move forward, backward, or turn left or right by some angle, and as it moves, it draws on the screen. Turtle graphics are more of an educational tool than something with practical use, but they can be fun to play around with. ALINE.LIB is a library that can draw anti-aliased lines. Like the other AA line library on this site, it is an implementation of Xiaolin Wu's line algorithm. However, this one allows for different colored lines, and simulates translucency for edges when overlapping other graphics, rather than always fading the edges to black. That said, it is still quite slow, and is most likely slower than the other due to these additional features. Since TURTLE.LIB depends on ALINE.LIB, both have been packaged together. Instructions To use turtle library: EXEC "PRG1:TURTLE.LIB" To use AA line library: EXEC "PRG1:ALINE.LIB" More documentation on usage is included in the respective libraries.
Categories
Keywords
  • turtle
  • anti-aliased
  • line
  • xiaolin
  • wu
18 Comment(s) HTV04 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website Can you port this to SmileBASIC 4? I would like to use the library there, but I don’t know how to port it myself. TheV360 TheV360 Pokemon Is Awesome! I love Pokemon! Express Yourself First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself It looks like it's compatible with SmileBASIC 4, so you can probably just download it. Just replace...
  1. All USE commands with similar EXEC commands (don't have to change syntax)
  2. All LOAD "PRGx:NAME",FLAG% commands with similar LOAD "NAME",x commands
  3. All RGBREAD commands with RGB commands (don't have to change syntax)
  4. All TRUE and FALSE system variables with similar #TRUE and #FALSE constants
  5. All #[COLOR] constants with similar #C_[COLOR] constants
Sounds complicated? It isn't! I did this in like 2 minutes (even easier if you have a keyboard) and now I have a pretty anti-aliased tree on my screen.
HTV04 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website Thanks! niconii niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies Here's the official SB4 port: 42EKEKKAV Although simply porting it from SB3 is easy enough, some changes have been made for the SB4 version, due to SB4 now having actual alpha capabilities. For instance, ALINE now takes the alpha of the color you give it into account. Some functions have been removed or made private due to being made obsolete. For example, APSET is no longer part of the API, since you can just use: GPSET X,Y,C,#G_ALPHA2 There's also a nice little demo program if you run MAIN.PRG.
12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I wonder if it would be faster to GSAVE the region where the line will be drawn, modify the array, and then GLOAD it back. HTV04 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website Hey, I’m planning to implement this in Solid Gunner Complete as an option for the line drawn between the ships. However, replacing the GLINEs with ALINEs causes the lines drawn by the game to stay on screen, even though the should be removed by the transparent ALINE. Is there a way to fix this? snail_ snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements Try using this library https://smilebasicsource.com/page?pid=518 HTV04 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website It doesn’t have color support, so I can’t make transparent lines that match the lines being drawn. niconii niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies The reason it doesn't work is because to simulate translucency, ALINE blends with whatever's underneath. Trying to draw an ALINE with color 0 over another one won't erase it, it will actually blend it with a black line (because ALINE ignores the alpha channel of the color given), darkening it a bit. (Even if it were changed to take the alpha channel into account, a transparent line wouldn't erase what's underneath, it'd simply draw nothing at all.) I've updated the library by adding a new command, ELINE. You can use it like this: 'Draw a red anti-aliased line ALINE 100,100,250,200,#RED 'Erase it ELINE 100,100,250,200,0 HTV04 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website Thank you so much! ELINE fixed the problem. niconii niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies Now, I should warn you, I was a bit surprised to learn you're using this for a real-time game like Solid Gunner Complete. I mean, hey, if it manages to perform well enough, that's great, but just keep in mind that ALINE is way slower than GLINE, so just be aware that it could lead to slowdowns. This benchmark should illustrate that: EXEC "PRG1:ALINE.LIB" 'Try making these smaller to generate shorter lines W=400 H=240 ACLS AVG=0 NUM=0 WHILE TRUE LINES=0 FRAME=MAINCNT WHILE MAINCNT==FRAME X0=RND(W):Y0=RND(H) X1=RND(W):Y1=RND(H) C=RND(&HFFFFFF) OR &HFF000000 'Try replacing ALINE with ELINE or GLINE ALINE X0,Y0,X1,Y1,C INC LINES WEND AVG=(NUM*AVG+LINES)/(NUM+1) INC NUM CLS COLOR #TWHITE,#TBLACK ?AVG COLOR #TWHITE,0 WEND This generates random lines on the screen and prints how many lines on average are drawn per frame. On my New 3DS:
  1. ALINE averages about 1.6 lines per frame.
  2. ELINE averages about 10.6 lines per frame.
  3. GLINE averages a whopping 1385 lines per frame.
If I clock it down to old 3DS speeds using CFW:
  1. ALINE averages about 1.0 lines per frame.
  2. ELINE averages about 2.1 lines per frame.
  3. GLINE averages about 297 lines per frame.
Now, it's a little better than it looks, since longer lines are more expensive than shorter ones, so modifying the benchmark to use a 50x50 region rather than 400x240 can get you up to about 10 lines per frame for ALINE on New 3DS. The huge difference in performance between ALINE and GLINE is just a consequence of the fact that GLINE uses native code to draw its lines, while ALINE is forced to use SmileBASIC, with relatively slow commands like GSPOIT (for color blending) and GPSET.
HTV04 HTV04 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Avatar Taboo I didn't change my avatar for 180 days Website Second Year My account is over 2 years old Website I did some thorough testing and it seems to work fine. Solid Gunner isn’t really a resource-heavy game, and only two lines are being drawn on screen, so there shouldn’t be any slowdowns. By the way, I also tested your anti-aliasing library on GAME2RPG. The title screen obviously took some time to draw all the lines, but it didn’t take too long. However, the tunnels rendered pretty fast. Needless to say, the game looked a lot better. You did a really good job on this anti-aliasing library, and I may use it for future projects, if that’s okay. niconii niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies Sure, use it for whatever you want. DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength @niconi, your test results are not very accurate since the coords are always random. You could fix this by making the coords constant or using RANDOMIZE so the coords are deterministic: RANDOMIZE 0, whatever 'should be a constant too EDIT lol I said "inaccurate" instead of "accurate", making it a double negative oof 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Good thing it's not very inaccurate DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength it's actually VERY inaccurate, since the slowest speed for drawing a line a(0,0,400,240) can be 433x slower than the fastest b(x,y,x,y) speed: b will draw 5 pixels a will draw 2161 pixels(i think), considering AA is basically a one radius blur (using probability) Yttria Yttria
I know that I can't take no more It ain't no lie, I wanna see you out that door Baby, bye, bye, bye...
It's interesting that you mention probability. "using probability..." the tests will measure the AVERAGE drawing time. 'splaining is now illegal.
12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Be careful about SWAPping function arguments, since the type depends on the value that is passed, not the variable name. If you pass an int and a float, it will just swap their values, not their types, so you'll lose some precision.