Author Topic: Fractal Fun  (Read 23928 times)

0 Members and 1 Guest are viewing this topic.

Maverick®

  • Seagull
  • Posts: 14778
Re: Fractal Fun
« Reply #30 on: November 17, 2009, 06:29:18 PM »
Call yours Pterofractals!

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #31 on: November 17, 2009, 06:29:38 PM »
Ok, I'll help you on that, I think I was wrong to say that the rgb code is 16-bit,

The code is calculated as follows...

(2^16) * Red  +  (2^8) * Green + Blue

JCTER

  • Guest
Re: Fractal Fun
« Reply #32 on: November 17, 2009, 06:32:09 PM »
Ok, I'll help you on that, I think I was wrong to say that the rgb code is 16-bit,

The code is calculated as follows...

(2^16) * Red  +  (2^8) * Green + Blue

oh sweet.  that helps me so much.  the math to do that was what was killing me... it was a large leap for someone who is not educated on this stuff :( heh.

JCTER

  • Guest
Re: Fractal Fun
« Reply #33 on: November 17, 2009, 06:53:42 PM »
How did you specify your color?  I'm getting a big brain frozen.

Did you use a variable assigned as a list concatenated to combine the R,B,G once converted to decimal values?  I'm feeling like I shouldn't play with the big boys :P

Here is where I've started modifying but I'm super unsure about how to get the 'decimal number' to actually form itself from the R, G, B parts.

Code: [Select]
     (pnt (list x y) (1+ (rem i 255)))))

  (princ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;This is where JamesCannon starts botching it up;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq rgbcol '(* (expt 2 16) i)) 0 0)

(defun pnt (pt col)
  (entmakex
    (list (cons 0 "POINT") (cons 10 pt) (cons 420 rgbcol))))

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #34 on: November 17, 2009, 07:04:19 PM »
Ok, I'll let you have a lookie  :-P

Code: [Select]
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;                                                     ;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤;;
;;                                                     ;;
;;                                                     ;;
;;          --=={  Julia Set Fractal  }==--            ;;
;;                                                     ;;
;;  The function will create a representation of the   ;;
;;  Julia set by iteration of the funtion:             ;;
;;                                                     ;;
;;     f(z) = z^2 + c                                  ;;
;;                                                     ;;
;;  Where 'z' & 'c' are Complex. The fractal colour is ;;
;;  determined by the number of iterations taken to    ;;
;;  for the norm of the Complex Number to reach a      ;;
;;  limit (less than a maxmimum iteration number).     ;;
;;                                                     ;;
;;  'c' is constant for each calculation - which sets  ;;
;;  the Julia set apart from the Mandelbrot set, (in   ;;
;;  which 'c' is set to zero for each point).          ;;
;;                                                     ;;
;;  NOTE:-                                             ;;
;;  Fractal Calculation is CPU intensive and may take  ;;
;;  a long time to be generated.                       ;;
;;                                                     ;;
;;  With the current settings 272,000 points are       ;;
;;  generated. Increase the xInc and yInc to reduce    ;;
;;  this number, and lower the iteration limit to      ;;
;;  decrease the calculation time of each point.       ;;
;;                                                     ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                     ;;
;;  AUTHOR:                                            ;;
;;                                                     ;;
;;  Copyright © Lee McDonnell, November 2009.          ;;
;;                                                     ;;
;; { Contact: Lee Mac @ TheSwamp.org, CADTutor.net }   ;;
;;                                                     ;;
;;                                                     ;;
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;                                                     ;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤;;

(defun c:jfract (/ iLim xMin xMax yMin yMax xInc yInc x y a b i)
  (vl-load-com)
  (setvar "PDMODE" 0) (setvar "PDSIZE" 0)
 
  (setq iLim 255  ;; Iteration Limit

        xMin -1.7 xMax  1.7  ;; Image Size
        yMin -1.0 yMax  1.0

        xInc 0.005 yInc 0.005 ;; Resolution

        Re[c] -0.8   ;; Real Coefficient of Julia Constant

        Im[c] 0.156  ;; Imaginary Coefficient of Julia Constant

        )

  (setq x (- xMin xInc))
  (while (<= (setq x (+ x xInc)) xMax)
   
    (setq y (- yMin yInc))
    (while (<= (setq y (+ y yInc)) yMax)

      (setq i 0 a x b y) ;; Julia

      (while (and (< (norm a b) 4.)
                  (<= (setq i (1+ i)) iLim))

        (setq new (z^2 a b) a (+ (car new) Re[c]) b (+ (cadr new) Im[c])))

      (pnt (list x y) (rgb 0 0 (1+ (rem (* 10 i) 255))))))

  (princ))

(defun pnt (pt col)
  (entmakex
    (list (cons 0 "POINT") (cons 10 pt) (cons 420 col))))

(defun norm (x y)
  (+ (* x x) (* y y)))

(defun z^2 (x y)
  (list (- (* x x) (* y y)) (* 2 x y)))

(defun rgb (r g b)
  (+ (* 65536 r) (* 256 g) b))

The above should make a Blue one - I multiplied the iteration number (i) by 10 just to get more variation in the colour :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #35 on: November 17, 2009, 07:07:00 PM »
Btw, the list when defined with an apostrophe, as in:

Code: [Select]
(setq rgbcol '(* (expt 2 16) i)) 0 0)
Will not be evaulated, you would need to use the "list" function, when you need to evaluate terms inside a list  :wink:

Just curious, are you using the VLIDE/Notepad++/Vim etc or just plain Notepad?

JCTER

  • Guest
Re: Fractal Fun
« Reply #36 on: November 17, 2009, 07:08:47 PM »
  (+ (* 65536 r) (* 256 g) b))

d'oh

I was stuck on thinking I'd use strings, concatenate them, and convert it to a real or something... I'm ... clueless and awkward.

thank you so much!  I was thinking it wasn't an addition, for some reason, but a concatenation of RGB... I misunderstood what a 24bit number really means, I guess.


and I'm using plain notepad  :-D I got more comfortable using the VLIDE, but for some reason just didn't... this time... though I use Notepad++ for other things, too, and have used it for lisp before.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #37 on: November 17, 2009, 07:13:52 PM »
 (+ (* 65536 r) (* 256 g) b))

d'oh

I was stuck on thinking I'd use strings, concatenate them, and convert it to a real or something... I'm ... clueless and awkward.

thank you so much!  I was thinking it wasn't an addition, for some reason, but a concatenation of RGB... I misunderstood what a 24bit number really means, I guess.

No problems mate - I didn't want to give you the solution right away, its always nice when you work towards it yourself  :-)  Much more satisfaction  :-)

and I'm using plain notepad  :-D I got more comfortable using the VLIDE, but for some reason just didn't... this time... though I use Notepad++ for other things, too, and have used it for lisp before.

Cool - it was only that I noticed a few of your brackets were out, 's all - so i was going to recommend you using the VLIDE or similar if you weren't already  :-)

wizman

  • Bull Frog
  • Posts: 290
Re: Fractal Fun
« Reply #38 on: November 17, 2009, 08:33:52 PM »
I'm enjoying your fractals lee, thanks for sharing... :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #39 on: November 17, 2009, 08:35:22 PM »
I'm enjoying your fractals lee, thanks for sharing... :-)

Thanks Wizman  :-)

Haven't seen you on here for a while - nice to speak to you again  :-)

wizman

  • Bull Frog
  • Posts: 290
Re: Fractal Fun
« Reply #40 on: November 17, 2009, 08:40:52 PM »
out of lisp for months andI got a lot of catching up to do lee, keep up your good work.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #41 on: November 18, 2009, 05:26:48 AM »
out of lisp for months andI got a lot of catching up to do lee, keep up your good work.

Thanks Wiz, I look forward to seeing your code again  :wink:

JCTER

  • Guest
Re: Fractal Fun
« Reply #42 on: November 18, 2009, 08:36:41 AM »
Not entirely what I expected, so I'll have to rethink my methods.

Still came out cool.. I'm gonna have fun playing with the colors :)


Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Fractal Fun
« Reply #43 on: November 18, 2009, 09:51:22 AM »
Yeah, I too need to work out a better way of using the RGB range - still looks pretty cool though  :wink:

JCTER

  • Guest
Re: Fractal Fun
« Reply #44 on: November 18, 2009, 09:57:55 AM »
Yeah, I too need to work out a better way of using the RGB range - still looks pretty cool though  :wink:
Code: [Select]
      (pnt (list x y) (rgb
(* i 1.2)                      ;;;;; red
 (expt i 1.1)                  ;;;;; green
 (1+ (rem (* 25 i) 255))))))   ;;;;; blue

I tried incorporating the iteration into it, but this seemed to come out not at all like I expected.  I was trying to get it to provide varying strengths of blue, without showing flat grey on the low iterations, and closer to black, instead... so fun to play with.  To quote Patrick from Spongebob Squarepants, and countless others before him:

Quote
MATH IS POWER!