Mediascripting on the Web (CSC 195 2014F) : Labs

Laboratory: Playing with PsAiF/R


  1. Issue the following instruction to make sure that your account is configured appropriately.

    $ /home/rebelsky/bin/csc151-setup
  2. Close your terminal window and open a new one. (That's the easiest way to incorporate those changes.)

  3. Make sure that your DrRacket launcher is configured to launch DrRacket from /opt/racket/bin/drracket. (You should be launching DrRacket 5.3.6, not 5.2.1.)

  4. Pick a location for your copy of psaifr. (I'd like you to have your own copy because it makes some other things easier.) For example, you might use /home/username/mediascript/psaifr

  5. Clone psaifr into that location

    $ git clone
  6. Issue the following instruction to tell Racket where to look for the new psaifr. You should, of course, substitute the path to the new folder you created in the previous step.

    $ raco link /home/username/mediascript/psaifr
  7. Create a sample Racket program of the following form to make sure that your changes worked. Grab your instructor if they don't.

    In the definitions pane:

    #lang racket
    (require gigls/unsafe)
    (require psaifr/main)

    In the interactions pane:

    (image-show (psaifr-greyscale-illustration 'x 100 10))

Reference: Racket Procedures

(psaifr-greyscale-image FUNCTION WIDTH HEIGHT BORDER)

Make a greyscale image using the given function. The interesting part of the image is WIDTHxHEIGHT, and that portion has a border of BORDER. The FUNCTION should take two numbers in the range [-1 .. 1] as input and return a number in the range [-1 .. 1] as output.

For example, (psaifr-greyscale-image (lambda (x y) (* x y)) 100 100 10)

(makefun SEXP)

Convert a description of a PsAiF/R function to a form usable by psaifr-greyscale-image.

For example, (makefun '(* x y))

(psaifr-greyscale-illustration SEXP SIZE FONTSIZE)

Makes one of the illustrations that includes the -1/1 labels in the given font size. Unlike psaifr-greyscale-image, expects you to type the function as an S expression.

Reference: PsAiF/R Functions

Zero parameter functions

-1, 0, 1, 0.5

Constant functions. Give a single color, from black (-1) to white (1).

x, y

Color based on the x value or the y value

One-parameter functions


Negate (flip) the value.


Negative numbers go to -1. Positive numbers go to 1. Numbers sufficiently close to zero to to 0.


Compute absolute value.

sine, cosine

These functions, rescaled appropriately: an input of -1 corresponds to -pi, and an input of 1 corresponds to pi.

Two-parameter functions


Multiplication. Duh.


Add two integers, capping to [-1 ... 1].


Add two integers, wrapping around when you reach 1 (or -1).


  1. Create images using a few of the operations above so that you can begin to understand their effects.

  2. Write instructions to make a big black triangle that occupies the upper-left portion of the image.

  3. Write instructions to make a big black triangle that occupies the upper-right portion of the image.

  4. Write instructions to make a black circle that occupies the center of the image.

  5. Write instructions to make a thick horizontal line.

  6. Write instructions to make a thicker vertical line.

  7. Write insturctions to make a thin diagonal line.

  8. If you have time remaining, start work on the assignment.

Copyright (c) 2014 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.