Stop the Presses, LJ Index and more.
Listing. Fun With Sines
// gcc -Wall -O2 sine.c -lvgagl -lvga -lm
#include <vga.h> /* vgalib */
#include <vgagl.h> /* advanced */
#include <math.h> /* sines! */
#include <stdlib.h> /* malloc */
#define VGAMODE G320x200x256
GraphicsContext *physical_screen;
GraphicsContext *virtual_screen;
GraphicsContext *scroll_board;
int main(void)
  double a, b, c, d; /* amp, phase, period, shift */
  double aa,bb,cc,dd; /* random values for fun */
  short int p_pos, t_pos; /* pixel & text */
  short int x,y,z; /* y coord, x & z counters */
  char key; /* to wait for keypress */
/* The following text between quotes should be all
   one line. Ignore wrapping */
  char text[] = "....................................Hello happy world and welcome to another episode of Stupid Programming Tricks. This is our scrolltext, well the idea is that you replace this text with your megagreetings list or the number to your pirate BBS. I wrote this one on Conectiva Linux which has the coolest characters but SVGALIB won't print them properly. Please experiment with different values, and try plugging sines into other sines, you can create the most remarkable though often illegible effects. Shout outs to Rigor Mortis (Riggie!), Red Sector, Triad, Fairlight, Quartex, Cynas, DM, RAiD and everyone else who's still alive! Hy3n4 m4s f1n4 out.........................................";
  double textl=sizeof(text); /* text length */
  vga_init(); /* here begin standard inits */
  vga_setmode(VGAMODE); /* we'll allocate our */
  gl_setcontextvga(VGAMODE); /* graphics areas */
  gl_clearscreen(0); /* better clear the screen */
  scroll_board = malloc( (WIDTH/8+1)*8*8*BYTESPERPIXEL);
  scroll_board = gl_allocatecontext(); /* ready */
  a=b=c=d=x=y=0; /* amp, phase, period, shift */
  t_pos=p_pos=0; /* text & pixel position */
  aa=rand()%64+16.0; bb=rand()%64+16.0;
  cc=rand()%64+16.0; dd=rand()%128+128.0;
  /* main loop */
  for (key=0; key==0; key=vga_getkey()) {
    p_pos += 2; /* adjust speed here */
    /* this redraws the text at each new letter */
    while (p_pos > 8) {
      gl_writen(0,0,WIDTH/8, &text[t_pos]);
      t_pos++; /* advance text */
      p_pos-=8; /* reset p_pos */
      if (t_pos >= textl)
         t_pos=0; /* reset t_pos */
    /* These equations produce readable text
     * but please experiment to witness the
     * potential of illegible sine scrolling
    x+=1; /* a counter for more phase shift */
    for (z=0; z<320; z++) {
      a = 24*sin((z+x)/aa)+24;
      b = 64*sin((x)/bb)+32;
      c = cc*sin((z+x)/cc)+128;
      d = (32-a)*sin((x-z)/dd)+124-a;
      y = a*sin((z+b)/c)+d; /* standard format */
      gl_copyboxfromcontext(scroll_board, z+p_pos,
         0, 1, 8, z, y);
    gl_copyscreen(physical_screen); /* update */
    gl_clearscreen(0); /* otherwise it smears */
    vga_waitretrace(); /* hold still a*/
  return 0; /* on principle ;) */
  1. Total number of patented applications listed by the U.S. Patent & Trademark Office as of June 30, 1999: 2,090,902

  2. Percentage of those patents with foreign origins: 43%

  3. Position of Japan among foreign countries holding U.S. patents: #1

  4. Percentage of foreign-origin patents held by Japan: 41%

  5. Position of IBM among U.S. patent holders: #1

  6. Number of patents held by IBM: 20,725

  7. Position of Canon among U.S. patent holders: #2

  8. Number of patents held by Canon: 18,043

  9. Number of Japanese companies among the top ten U.S. patent holders: 6

  10. Number of patents held by Microsoft: 1,167

  11. Number of patents held by Walker Asset Management Corporation (best known for Priceline.com): 36

  12. Number of patents in which the name “Amazon.com” is mentioned: 9

  13. Number of patents held by Amazon.com: 7

  14. Number of patents that mention the word “Linux”: 49

  15. Percentage of those in which Linux is used to demonstrate the patent's purpose: 100%

  16. Revenues from patent licensing in 1990: $15 billion US

  17. Revenues from patent licensing in 1998: $100 billion US

  18. Number of shares of Microsoft stock owned by Bill Gates: 780 million

  19. Number of shares of Microsoft stock owned by Paul Allen: 260 million

  20. Number of shares Bill Gates filed with securities regulators to sell: 300,000

  21. Percentage change in the stock price of RHAT in the five weeks after the antitrust ruling: +218

  22. Number of feet by which Arctic sea ice has thinned since 1976: 4

  23. Number of colonies of Antarctic Adélie penguins that have disappeared since 1988: 11


Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up and watch now

Sponsored by Skybot