? Drawing Ellipses on SmileBASIC ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
💀

Drawing Ellipses on SmileBASIC

DEF ELLIPSE X,Y,SX,SY VAR R,I,R2 FOR I=0TO 360:R2=R R=RAD(I) GLINE X+SX*COS(R),Y+SY*SIN(R),X+SX*COS(R2),Y+SY*SIN(R2) NEXT END This basically has the same function that ellipse() does in processingJS, just ported to SmileBASIC.
Author
AnswerXOX
Updated
Rating
6 votes
Categories
Keywords
10 Comment(s) dfrost2 dfrost2 I have noticed something with this code.WHILE loops are faster than FOR loops.FORexample: I wrote this code to test the milliseconds it took to execute the following M=MILLISEC FOR I=0 TO 1000000 'Just let it loop NEXT PRINT MILLISEC-M 'Returned approximately 750. I=0'reset the counter to 0 M=MILLISEC WHILE I<1000001 INC I WEND PRINT MILLISEC-M 'Returned about 675 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website DEF ELLIPSE X,Y,SX,SY VAR R# VAR C#=SX,S#=0 FOR R#=0 TO 6.2831853 STEP 0.01 'or something VAR OC#=C# VAR OS#=S# C#=SX*COS(R#) S#=SY*SIN(R#) GLINE X+OC#,Y+OS#,X+C#,Y+S# NEXT END or something AnswerXOX AnswerXOX Great Page Hidden Achievements RNG Hidden Easter Eggs Second Year My account is over 2 years old Website can you do a benchmark perhaps and compare it using MILLISEC? I lost my SD card therefore my access to SmileBASIC 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website It's significantly faster (if you adjust it to use the same number of steps), and my new version is over 2x as fast: DEF ELLIPSE X,Y,SX,SY VAR R# VAR C#=SX,S#=0 FOR R#=0 TO PI()/2+PI()*2/360 STEP PI()*2/360 VAR OC#=C# C#=SX*COS(R#) S#=SY*SIN(R#) GLINE X+OC#,Y+OS#,X+C#,Y+S# GLINE X-OC#,Y-OS#,X-C#,Y-S# GLINE X-OC#,Y+OS#,X-C#,Y+S# GLINE X+OC#,Y-OS#,X+C#,Y-S# NEXT END yours: 299 per sec. mine: 392 per sec. new: 741 per sec. amihart amihart If you replace this line:GLINE X+SX*COS(R),Y+SY*SIN(R),X+SX*COS(R2),Y+SY*SIN(R2)With this line:GTRI X+SX*COS(R),Y+SY*SIN(R),X,Y,X+SX*COS(R2),Y+SY*SIN(R2)then it will draw a filled ellipse. c: AnswerXOX AnswerXOX Great Page Hidden Achievements RNG Hidden Easter Eggs Second Year My account is over 2 years old Website omfg, that's amazing 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website It would probably be faster just to use GPAINT, but then you'd have to do some extra things in case the ellipse had other stuff behind it, which might make it slower. MochaProbably MochaProbably Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies I made it so you can add #TRUE or #FALSE to the end of the function to make it filled or not. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website It would be faster to store the old X and Y coords so you don't have to recalculate SIN and COS every time. AnswerXOX AnswerXOX Great Page Hidden Achievements RNG Hidden Easter Eggs Second Year My account is over 2 years old Website True, this is just something I made It's not exactly perfect