home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iv26_w_3.zip / EXAMPLES / SQUARES / SQUARES.C < prev    next >
C/C++ Source or Header  |  1992-02-06  |  2KB  |  64 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Implementation of squares subject.
  25.  */
  26.  
  27. #include "squares.h"
  28. #include <time.h>
  29. #include <stdlib.h>
  30.  
  31.  
  32. Squares::Squares () {
  33.     head = nil;
  34. }
  35.  
  36. Squares::~Squares () {
  37.     register SquareData* p, * next;
  38.  
  39.     for (p = head; p != nil; p = next) {
  40.     next = p->next;
  41.     delete p;
  42.     }
  43. }
  44.  
  45. void Squares::Add (float cx, float cy, float size) {
  46.     register SquareData* s = new SquareData;
  47.     s->cx = cx;
  48.     s->cy = cy;
  49.     s->size = size;
  50.     s->next = head;
  51.     head = s;
  52.     Notify();
  53. }
  54.  
  55. static float Random () {
  56.     const int bigint = 1<<14;
  57.     int r = rand();
  58.     return float(r % bigint) / float(bigint);
  59. }
  60.  
  61. void Squares::Add () {
  62.     Add(Random()/2 + .25, Random()/2 + .25, Random()/2);
  63. }
  64.