Point

From Spheriki

Jump to: navigation, search

Plots a single pixel point on the video buffer with the given color.


Contents

Usage

Point(x, y, color);
  • x Number. The screen x-coordinate of the point to be plotted, ranging from 0 (left, inclusive) to the screen width (right, exclusive, obtained via GetScreenWidth()).
  • y Number. The screen y-coordinate of the point to be plotted, ranging from 0 (top, inclusive) to the screen height (bottom, exclusive, obtained via GetScreenHeight()).
  • color A Sphere Color object, holding the desired color of the point.


Examples

Point(GetScreenWidth() / 2, GetScreenHeight() / 2, CreateColor(255, 255, 0));
FlipScreen();
GetKey();

The above example plots a single yellow pixel in the middle of a screen, makes it visible, and waits for a key press.


var screen_width = GetScreenWidth();
var screen_height = GetScreenHeight();

for (var y = 0; y < screen_height; ++y)
{
  for (var x = 0; x < screen_width; ++x)
  {
    var red = Math.floor(Math.random() * 256);
    var green = Math.floor(Math.random() * 256);
    var blue = Math.floor(Math.random() * 256);
    Point(x, y, CreateColor(red, green, blue));
  }
}

FlipScreen();
GetKey();

The above example fills the screen with completely random colors, displays it, and waits for the user to press a key.


// Figure 8 point animation

var screen_width = GetScreenWidth();
var screen_height = GetScreenHeight();
var white = CreateColor(255, 255, 255);
var start_time = GetTime();
var period = 2000;

// Clear key buffer
while (AreKeysLeft()) GetKey();

// Animation loop
while (!AreKeysLeft())
{
  var state = (GetTime() - start_time) / period;
  var x = Math.floor(Math.cos(state * Math.PI * 2) * 0.5 * screen_width) + screen_width * 0.5;
  var y = Math.floor(Math.sin(state * Math.PI * 4) * 0.5 * screen_height) + screen_height * 0.5;
  Point(x, y, white);
  FlipScreen();
}

The above example will show a single point travelling in a figure 8 path, until the player presses a key.


Notes

  • Like all drawing functions, the FlipScreen() function must be called for the video buffer to be seen by the player.
  • If color has an alpha value less than 255, the plotted point will be blended with whatever color is already there.
  • To plot a point at a position on a Sphere map within the map engine, remember to convert the map coordinates to screen coordinates using MapToScreenX(map_x) and MapToScreenY(map_y).


See also



Personal tools