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

Assignment: Exploring PsAiF/R

This assignment gives you a chance to explore my soon-to-be-renamed PsAiF/R (Problem Solving, Abstract Images, and Functions/Racket) library.

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).


Do the lab on PSAiF/R. Doing so should get your account set up to work in PsAiF/R. That lab also has useful documentation.

Clone the GitHub repository at


  1. Create the file answers/yourname.rkt and put your answers to the various questions from the lab in that file.

  2. Create a few (at least two) examples of "interesting" images you can make with PsAiF/R. Put the code in the examples folder of the assignment repository. Feel free to put a sample image there, too.

  3. Pick something that you think is an interesting (but doable) problem and put a textual description of the goal, an image that illustrates the goal, or both in the problems folder.

  4. Add a solution to your problem to your answers folder.

For those with extra time

Option one: Extend PsAiF/R.

  1. Fork the repo at

  2. Look at the code in main.rkt and add something useful. (A typical useful thing would be a new function that we can show.)

  3. Figure out how to send a pull request.

Submitting your homework

Since your work is on GitHub, I can tell that you've turned it in. It even has a convenient time stamp.

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.