Rebol3 Code Examplex


Peripheral drift illusion

Create a static image that appears to drift or rotate when viewed in peripheral vision, usually by arranging repeating luminance gradients.

Rebol [
    title: "Rosetta code: Peripheral drift illusion"
    file:  %Peripheral_drift_illusion.r3
    url:   https://rosettacode.org/wiki/Peripheral_drift_illusion
    needs: blend2d       ;; draw extension
]

n:    15
r:    800 / (3 * n)      ;; base unit: canvas divided into 3n equal parts
offs: 800 / 10 / n       ;; satellite offset distance
step: 360 * 2 / (n - 1)  ;; angle increment between cells

;; translate so first cell centre lands at (1.5r, 1.5r) instead of origin
cmds: compose [pen off translate (as-pair 1.5 * r 1.5 * r)]

repeat row n [
    repeat col n [
        x: (3 * (col - 1)) * r        ;; centre x of current cell
        y: (3 * (row - 1)) * r        ;; centre y of current cell
        angle: (col + row - 2) * step ;; rotation angle varies per cell position

        append cmds compose [
            fill-pen white
            circle (as-pair x + (offs * cosine angle) y + (offs * sine angle)) (r)
            fill-pen black
            circle (as-pair x + (offs * cosine (angle + 180)) y + (offs * sine (angle + 180))) (r)
            fill-pen 44.26.244
            circle (as-pair x y) (r)   ;; blue centre circle
        ]
    ]
]

img: make image! [800x800 141.177.56]  ;; green background
browse save %Peripheral_drift_illusion.png draw img cmds

Alternative version:

Rebol [
    title: "Rosetta code: Peripheral drift illusion"
    file:  %Peripheral_drift_illusion-Pinna_Brelstaff.r3
    url:   https://rosettacode.org/wiki/Peripheral_drift_illusion
    needs: blend2d       ;; draw extension
]

n:    7
r:    800 / (2 * n)
step: 360 *  2 / (n - 1)

cmds: compose [pen off translate (as-pair r r)]

repeat row n [
    repeat col n [
        x: (2 * (col - 1)) * r
        y: (2 * (row - 1)) * r
        angle: (col + row - 2) * step

        ;; draw rings outside-in so smaller rings appear on top
        for ring 5 1 -1 [
            ring-r: r * ring / 6
            offs:   r * 0.12            ;; fixed small offset for all rings
            a:      angle + (ring * 25) ;; each ring rotated incrementally more

            append cmds compose [
                fill-pen (either odd? ring [240.240.240] [20.20.20])
                circle (as-pair x + (offs * cosine a) y + (offs * sine a)) (ring-r)
            ]
        ]
    ]
]

img: make image! [800x800 100.100.100]
browse save %Peripheral_drift_illusion-Pinna_Brelstaff.png draw img cmds