Here's a nice little Jako example which draws a circle (oval, strickly 
speaking!) using VT100 control codes, which means that it should work in 
xterms, gnome-terminals, consoles and konsoles.

Nice to have so many projects creating parrot byte code!

Regards,

Nick

#
# circle.jako           Nick Glencross <[EMAIL PROTECTED]>
#
#
# Draw a circle on a VT100-compatible screen
#
# The algorithm is based on:
#
#    cos(theta+delta) =
#            cos(theta) -
#            [alpha*cos(theta) + beta*sin(theta)]
#
# and
#
#    sin(theta+delta) =
#            sin(theta) -
#            [alpha*sin(theta) - beta*cos(theta)]
#
# where
#
#    alpha = 2*sin^2(delta/2) and beta = sin(delta)
#
# (See Numerical Recipes in C)
#
# In this program the value of delta is chosen to be 1/(1<<n) such
# that it is small enough that
#
#    alpha is approx. 0
# and
#    beta is approx. delta
#
#

const int width  = 80;
const int height = 24;

const str escape = "\033";

# Clear the screen
sub clear () {
  print(escape, "[H");
  print(escape, "[2J");
}

var int half_width;
var int half_height;
var int scale_width;
var int scale_height;

half_width  = width/2;
half_height = height/2;

scale_width = 140000/width;
scale_height= 140000/height;

# A simple point plotting function
sub plot (int x, int y) {
  x /=  scale_width;
  y /=  scale_height;

  x += half_width;
  y += half_height;

  print(escape, "[$y;$x", "H*");
}

# Moves the cursor back to the bottom line
sub reset_cursor () {
  print(escape, "[$height;0H");
}

clear();

var int Tcos;
var int Tsin;

Tcos = 65536;
Tsin = 0;

var int Tcos_delta;
var int Tsin_delta;

var int i;
i=0;

 # Loop approx. 2*PI*2^6 times plotting points on a circle
while (i<=403) {

  plot(Tsin, Tcos);

  Tcos_delta=Tsin>>6;
  Tsin_delta=Tcos>>6;

  Tcos -= Tcos_delta;
  Tsin += Tsin_delta;

  i++;
}

reset_cursor();

Reply via email to