Jump to content



Photo
- - - - -

[casio Basic] Drawing Cleaner, Dotted, Filled, Etc. Circles


  • Please log in to reply
No replies to this topic

#1 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 26 August 2011 - 06:56 PM

I thought this was a good post, so I moved it here since some of us can't view casio kingdom.

Original author: iwantanimac
Original post date: Sept 1, 2006


More manipulable circles

I stumbled upon this while trying to make a program in which you can make pie charts on the calc. You can create circles which are not only much cleaner than the original "Circle X,Y,r", but can be filled in, drawn dotted, made with thick edges, or even drawn only to a specific angle. It involves some pretty basic code and some maths you should all know and understand.

First, you need to understand that this code will draw circles fine on the default viewwindow (Which has square pixels and properly aligned coordinates) and can be easily adapted for most other square-pixeled viewwindows.

- Introduction
Firstly, i'll introduce you to the meat of the code. This will draw a very clean circle in the centre of the default ViewWindow (And will automatically change to it, so don't worry) Code:
ClearGraph 
 For 1->x to 360 step 1 
 F-Line rcosx,rsinx,rcosx,rsinx 
 Next

So essentially, we first clear the graph (This resets the ViewWindow, and is entirely optional), then we start a loop, which will continue to add 1 to x 360 times (The 1 comes from the step 2, not the 1->r).
Inside this loop, we have a very basic code. This is an F-Line, used because it doesn't mind coordinates outside your viewwindow and it can draw more than one pixel at a time. r is our radius variable, while x is our angle, in degrees.

- Speeding Up and dashed/dotted circles
Running this code by itself on your calculator (Using appropriate values for varialbes - try an r vlaue between 2 and 3.1) it will draw you up a nice circle in the centre of the screen, but it will take a while. You'll notice the edges are much cleaner and more circular than the default circle command.

The time can be cut down quite significantly by manipulating the step value. Doing this causes the calculator to skip that many degrees per loop, making it draw less.
The problem with this is, at larger radii the circle can appear broken or dotted. If this is the efect you are after, you cna set the step value higher. If not, you can still set the step value, but i recommend only up to about 5. If you do this, i'd also recommend you make it draw an extended line rather than a dot by using this alternative code: Code:
ClearGraph 
 For 1->x to 360 step 5 
 F-Line rcos(x-5),rsin(x-5),rcos(x+5),rsin(x+5) 
 Next

You'll notice this is five times as fast, but may draw slightly less "perfect"circles. You can also use this change in X value, along with a large step value to create dashed lines for your circles.

- Thick bordered circles
Creating thick bordered circles requires a simple manipulation of the r value for one end of the line, as follows: Code:
ClearGraph 
 For 1->x to 360 step 1 
 F-Line (r+t)cosx,(r+t)sinx,rcosx,rsinx 
 Next

This will draw a circle with lines t pixels thicker than usual. t can also be negative (This will make the line thickness start at the outside rather than inside)

- Filled In Circles
To create a filled in circle, you can simply set one coordinate of your F-Line to the centre of your circle. At defaults, this is (0,0), so we can do this: Code:
ClearGraph 
 For 1->x to 360 step 1 
 F-Line 0,0,rcosx,rsinx 
 Next



- Moving the circle
To move the circle, we must add a value to the total of the coordinate, as follows: Code:
ClearGraph 
 For 1->x to 360 step 1 
 F-Line (rcosx)+a,(rsinx+b),(rcosx+a),(rsinx+b) 
 Next
substitute a and b for your x and y values.

- Other Tricks
- Spirals
You can create a simple spiral drawer by replacing the circle code with the following: Code:
ClearGraph 
 For 1->x to 360 step 1 
 F-Line xcosx,xsinx,xcosx,xsinx 
 Next


- Random Circular Patterns
You can create a funny-looking circle by using the following code: Code:
ClearGraph 
 For 1->x to 360 step 1 
 If (Ran#*10)>5 
 Then r+0.1->r 
 Else r-0.1->r 
 IfEnd 
 F-Line rcosx,rsinx,rcosx,rsinx 
 Next
This will be unique every* time you run it. A cool visual toy.

I hope you found that useful. If you think my ramblings are too hard to understand, please let me know and i'll try to fix it up (I'm pretty tired at the time of writing, so it could be entirely incomprehensible). I tried to make this as beginner-friendly as possible, but i haven't included the reasons for using cos and sin, in case anyone doesn't know how they work (Which most of you should anyway) so if you really need that, let me know. Images are also coming soon.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users