Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #37689

Re: Program or be Programmed !

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: Program or be Programmed !
Date 2015-03-27 07:57 +0000
Organization A noiseless patient Spider
Message-ID <mf32hu$9ld$1@dont-email.me> (permalink)
References <98f287f7-fc54-4cd6-95c5-3c62100c89fd@googlegroups.com> <ce5mhdFctpU1@mid.individual.net> <m70n3m$vmk$1@dont-email.me>

Show all headers | View raw


WJ wrote:

> Paul E Bennett wrote:
> 
> > I was displaying a sine-wave of 
> > asterix characters scrolling continuously down the screen. 3 lines of code 
> > generated the sine-wave (and cosine) numbers and the other 30 or so lines 
> > did scaling and arrangements for its display. I was showing the source code 
> > in a separate window. 
> 
> Gauche Scheme:
> 
> (define line-length 79)
> (define mid-point (div line-length 2))
> (define one-line (string-append
>   (make-string mid-point #\space) "|" (make-string mid-point #\space)))
> (define (pause) (sys-nanosleep 5e7))
> (let loop ((x 0.0))
>   (when (< x 22)
>     (let ((this-line (string-copy one-line))
>           (p (round->exact (+ mid-point (* mid-point (sin x))))))
>       (string-set! this-line p #\*)
>       (print this-line)
>       (pause))
>     (loop (+ 0.1 x))))
> 
> Partial output:
> 
>      *                                 |
>    *                                   |
>   *                                    |
>  *                                     |
> *                                      |
> *                                      |
> *                                      |
>  *                                     |
>   *                                    |
>    *                                   |
>      *                                 |
>        *                               |
>          *                             |
>            *                           |
>               *                        |
>                   *                    |
>                      *                 |
>                         *              |
>                             *          |
>                                 *      |

Oforth:

79 Constant new: line-length
line-length 2.0 / ceil Constant new: mid-point
func: make-line {
  ListBuffer init( line-length, #[ ' ' ] )
  dup  put( mid-point, '|' ) }
func: pause { System sleep(50) }
func: go {| i x old-x delta char |
  0 -> old-x
  0 220 for: i [
    i 10.0 / sin mid-point -- * mid-point +   -> x
    x old-x - -> delta
    delta abs 0.5 <
    ifTrue: [ '|' ]
    else: [ delta sgn 2 + "/ \\" at ] -> char
    make-line dup put( x round, char )
    charsAsString println
    pause
    x -> old-x
  ]
}

Partial output:

       /                               |
     /                                 |
   /                                   |
  /                                    |
 /                                     |
/                                      |
|                                      |
|                                      |
 \                                     |
  \                                    |
   \                                   |
     \                                 |
       \                               |
         \                             |
           \                           |
              \                        |
                  \                    |
                     \                 |
                        \              |
                            \          |
                                \      |
                                    \  |
                                       |\
                                       |    \
                                       |       \
                                       |           \
                                       |               \
                                       |                  \
                                       |                      \
                                       |                         \
                                       |                           \
                                       |                              \
                                       |                                \
                                       |                                  \
                                       |                                    \
                                       |                                     \
                                       |                                      \
                                       |                                      |
                                       |                                      |
                                       |                                      |
                                       |                                     /
                                       |                                    /
                                       |                                  /
                                       |                                /
                                       |                              /
                                       |                            /
                                       |                         /
                                       |                      /
                                       |                   /
                                       |               /
                                       |           /
                                       |        /
                                       |    /
                                       |/

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Program or be Programmed ! visualforth@rocketmail.com - 2014-12-01 18:55 -0800
  Re: Program or be Programmed ! Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-12-02 11:36 +0000
    Re: Program or be Programmed ! the_gavino_himself <visphatesjava@gmail.com> - 2014-12-13 12:47 -0800
      Re: Program or be Programmed ! Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-12-13 20:54 +0000
      Re: Program or be Programmed ! visualforth@rocketmail.com - 2014-12-17 16:51 -0800
    Re: Program or be Programmed ! "WJ" <w_a_x_man@yahoo.com> - 2014-12-19 08:20 +0000
      Re: Program or be Programmed ! Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-12-19 09:29 +0000
      Re: Program or be Programmed ! "WJ" <w_a_x_man@yahoo.com> - 2015-03-27 07:57 +0000
    Re: Program or be Programmed ! "WJ" <w_a_x_man@yahoo.com> - 2014-12-25 21:08 +0000

csiph-web