Circles.js (system script)

From Spheriki

Jump to: navigation, search

Use the system script circles.js by Eric Duvic to draw circles.


Contents

Usage

RequireSystemScript("circles.js");


Variables and functions of circles.js

  • LineCircle(radius, color)
    • draws a circle outline of the given radius (in pixels) using the color object 'color'. Returns an image object containing the circle.
  • Circle(radius, color)
    • same as LineCircle(), except the circle is filled with the given 'color'.
  • GradientCircle(radius, color1, color2)
    • same as Circle() but 'color1' and 'color2' smoothly change between center and periphery of the circle.


Examples

First, the example stores the image returned by the function LineCircle() in a variable. The image is drawn onto the screen afterwards.

 RequireSystemScript("circles.js");
 var myCircle = LineCircle(100, CreateColor(255,0,0));
 myCircle.blit(0,0);
 FlipScreen();

If you think you don't need to use a variable, merge the 2nd and 3rd line to:

 LineCircle(100, CreateColor(255, 0, 0)).blit(0,0);


Notes

  • LineCircle(), Circle() and GradientCircle() don't draw anything to the screen buffer. You have to blit the image object they return and call FlipScreen() afterwards to see something. The image returned can be stored in a variable for later re-use to save processing time since drawing of circles is usually time consuming (see the examples). The image will have a height and width of twice the given radius.
  • The Sphere directory docs/system_scripts/ contains a small doc (circles.txt).
  • Drawing functions for other graphics primitives can be found in the Sphere API and in graphics.js (system script).


Known bugs

  • During tests the circle images drawn by Circle() and GradientCircle() appeared to have their rightmost pixel column and their bottommost pixel line missing. It made the circle appear not exactly circular, especially when drawing circles with small radius. See the Spherical Pastebin for a fixed version.
Personal tools