pattern:random-keep
List of: Scheme Extensions
Subjects: Patterns
Contents: Kernel

Action: Creates a new pattern by applying a random keep filter to an existing pattern.

Filename: kern/kern_scm/pattern_scm.cxx

APIs: api_random_keep_pattern

Syntax: (pattern:random-keep pat fraction [merge=#t])

Arg Types: pat pattern

fraction real

merge boolean

Returns: pattern

Description: Applies a periodic keep filter to an existing pattern, merging with any existing filter or, optionally (with merge=#f), replacing it.


pat specifies a pattern.


fraction determines the fraction of pattern elements that are kept.


If merge is specified as false (#f), the existing pattern is replaced. The default value is true (#t).

Example: ; pattern:random-keep

; make a prism

(define height 1)

;; height

(define maj_rad 1)

;; maj_rad

(define min_rad 0.5)

;; min_rad

(define num_sides 3)

;; num_sides

(define prism


(solid:prism height maj_rad min_rad num_sides))

;; prism

; position the prism

(define origin (position 1 2 3))

;; origin

(define transform (entity:transform prism


(transform:axes


origin (gvector 1 0 0) (gvector 0 1 0))))

;; transform

; make a pattern

(define x-vec (gvector 4 0 0))

;; x-vec

(define num_x 12)

;; num_x

(define y-vec (gvector 0 4 0))

;; y-vec

(define num_y 12)

;; num_y

(define pat (pattern:linear x-vec num_x y-vec num_y))

;; pat

; modify the pattern

(define keep_fraction 0.5)

;; keep_fraction

(set! pat (pattern:random-keep pat keep_fraction))

;; #[pattern

;; trans-vec:"DOMAIN(X*VEC(4,0,0)+X2*VEC

;; (0,4,0),0,11,0,11)"

;; x-vec: "null_law"

;; y-vec: "null_law"

;; z-vec: "null_law"

;; scale: "null_law"

;; keep: "null_law"

;; [list]]

; apply the pattern to the prism

(define body (entity:pattern prism pat))

;; body
PDF/KERN/14SCI.PDF
HTM/DATA/KERN/KERN/14SCI/0081.HTM