? Perfectly Filled Circles ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Perfectly Filled Circles

It can be difficult to draw a perfectly filled circle. Once the center of the circle goes off the screen, GPAINT can no longer be used. When other objects are inside the circle's border, GPAINT does not fill the entire circle. With this function, we can guarantee that the circle will get completely filled every time it is drawn. 'DRAWS A PERFECTLY FILLED CIRCLE 'C IS FILL COLOR AND B IS BORDER COLOR DEF FCIRCLE X,Y,R,C,B GCIRCLE X,Y,R,8 'IF CIRCLE IS ALREADY WITHIN BOUNDS IF X>=0&&Y>=0&&X<400&&Y<240 THEN GPAINT X,Y,C,8 GCIRCLE X,Y,R,B RETURN ENDIF VAR DX=MAX(0,MIN(X,399))-X VAR DY=MAX(0,MIN(Y,239))-Y VAR DT=MAX(1,SQR(DX*DX+DY*DY)) DX=X+DX/DT*(R-2) DY=Y+DY/DT*(R-2) GPAINT DX,DY,C,8 GCIRCLE X,Y,R,B END FCIRCLE -100,-100,300,#RED,#WHITE
Author
Simeon
Updated
Rating
8 votes
Categories
Keywords
  • circle
  • circles
  • fill
  • filled
4 Comment(s) 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 Be careful with bounds checking. When you are near the edge, make sure that it's not off by a pixel or 2, which would cause the whole screen to be filled. snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Graphics pages are actually 512x512 (bigger than the screen) and the entire area is drawable, so you should be using that as your bounds check. Otherwise, pretty good. I had used a similar method before but hadn't bothered to do any bounds checking. chicken chicken OSP Contest 1 Contest Participant I participated in the first SmileBASIC Source OSP Contest! Second Year My account is over 2 years old Website Good Page Hidden Achievements So, if the center of the circle is within bounds, then it just GPAINTs? I'm confused, because that still doesn't solve the problem with overlapping shapes. snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself GPAINT border mode solves this. If you include a "border color" as the last argument to the GPAINT call, the paint continues over every color until it reaches the border color, instead of constraining to a contiguous area of color. You can see he draws the circle with a color value of 8, and then specifies that as the paint border.