Skip to content

Conversation

@bdeket
Copy link
Contributor

@bdeket bdeket commented Aug 26, 2020

Among other things allows to make plots of fractals.
It is similar to contour-intervals, but for erratic functions (like fractals) I don't know how to get contour-intervals to display what I want.


Sample code:

#lang typed/racket
(require plot)
;; https://rosettacode.org/wiki/Mandelbrot_set#Racket
(define (iterations [a : Number][z : Number][i : Nonnegative-Integer]) : Nonnegative-Integer
  (define z′ (+ (* z z) a))
  (if (or (<= 255 i) (< 2 (magnitude z′)))
      i
      (iterations a z′ (+ i 1))))

(define (iter->color [i : Nonnegative-Integer]) : Plot-Color
  (if (= i 255)
      'black
      (list (* 5 (modulo i 15)) (* 32 (modulo i 7)) (* 8 (modulo i 31)))))

(define (mandelbrot [x : Real][y : Real]) : Plot-Color
  (define z (make-rectangular (* 1.0 x) (* 1.0 y)))
  (iter->color (iterations z 0 0)))

(plot (color-field mandelbrot -2.25 0.75 -1.25 1.25 #:samples 200))

Produces:

mandelbrot-plot

@alex-hhh
Copy link
Collaborator

Among other things allows to make plots of fractals.

Allow me to ask the reverse question. Except for plots of fractals, what other things can color-field be used for? Also, even for fractals, is there a particular need for displaying fractals on a plot surface? You could generate fractals using pictures (e.g using the dc pict constructor).

@bdeket
Copy link
Contributor Author

bdeket commented Aug 26, 2020

Regarding fractals:
the nice thing of doing it with plot is that zooming is there by default.

Other things that would be possible:
instead of making a vector-field, use color intensity for the length of the vector, and color for the angle
(I would not know how to do that with contours)

What I am mainly using it for:
making error plots of complex functions. Where the errors can be really erratic. and the zooming function of plot gives me the option to explore where the problems are

edit: and you get tick marks!

@alex-hhh alex-hhh changed the title color field add color-field 2D renderer Aug 27, 2020
Copy link
Collaborator

@alex-hhh alex-hhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request looks good to me. I added some comments for adding history entries to the documentation and removing some commented out code, once you address those, I will merge the changes.

@alex-hhh alex-hhh merged commit 05a3718 into racket:master Aug 27, 2020
@bdeket bdeket deleted the color-field branch September 22, 2020 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants