Render graphics with a function

render function
(render function opacity)
(render function opacity rectangle)
(render function opacity p1 p2)

Renders an image composed of points which color is the function output. The function has to take two or three arguments at the input, :x and :y coordinates and optionally the current color :c. By default the image fills entire graphics window. Opacity of the image can be optionally provided, with values from 0 (transparent) to 100 (opaque). The image size can be optionally limited to the rectangle provided as a list or array of side coordinates {left_x right_x top_y bottom_y}. The image rectangle location can be provided also in form of two points, p1 and p2, given as 2-element lists or arrays {x y}.

The function output can be a color name, an index in the current palette of colors or a list or array of color compounds: {r g b} or {r g b opacity}. The range of values is from 0 (off) to 100 (full brightness), opacity values are from 0 (transparent) to 100 (opaque).

Example 1:

to fcolor :x :y
  let "d sqrt :x^2 + :y^2
  op 15 * :d

(render $fcolor 100 {-50 50 50 -50})

Output: a drawing in the graphics window.

Example 2:

to fcolor :x :y
  let "d sqrt (:x - xcor)^2 + (:y - ycor)^2
  let "dp :d * :p
  let "c newarray 4
  :c,1 := 50 * (1 + sin 1.1 * :dp)
  :c,2 := 50 * (1 + cos 1.3 * :dp)
  :c,3 := 50 * (1 + (cos 1.4 * :dp)^2)
  ifelse :d < 50 [:c,4 := 100 - 2 * :d] [:c,4 := 0]
  op :c

:pool_cfg,"refresh := false
repeat 300 [
  "p := 50 * sin 2*repcount
  (render $fcolor 100 {-50 50 50 -50})

Output: a drawing in the graphics window.

See also:

Table of Content