Is there a way you can create bit-mapped pictures using Guiserver?
Eg say I wanted to draw images by setting pixels to different colours, could I do that?
Pixel editing
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
got a few minutes to play with newlisp today... :)
I think there's over 50 000 filled rectangles in here!
Code is pretty basic - apart from michael's elegant complexity.
PS: The forum doesn't escape angle brackets in the CODE sections but when I replace them in with ampersand-codes they don't convert to angle brackets when displayed... ? Confused...
Code is pretty basic - apart from michael's elegant complexity.
Code: Select all
#!/usr/bin/env newlisp
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(define (Class:Class) (cons (context) (args)))
(new Class 'Complex)
(define (Complex:rad c)
(sqrt (add (pow (c 1) ) (pow (c 2)))))
(define (Complex:add a b)
(Complex (add (a 1) (b 1)) (add (a 2) (b 2))))
(define (Complex:mul a b)
(let (a.re (a 1) a.im (a 2) b.re (b 1) b.im (b 2))
(Complex
(sub (mul a.re b.re) (mul a.im b.im))
(add (mul a.re b.im) (mul a.im b.re)))))
(gs:init)
(set 'canvas-width 600 'canvas-height 400)
(gs:frame 'Mandelbrot 60 60 canvas-width canvas-height "Mandelbrot")
(gs:canvas 'MyCanvas 'Mandelbrot)
(gs:add-to 'Mandelbrot 'MyCanvas)
(gs:set-visible 'Mandelbrot true)
(seed (date-value))
(set 'colour-map (sort (transpose (list (random 0 1 255) (random 0 1 255) (random 0 1 255)))))
(define (do-cell x y c)
(set 'colour (if (>= c limit) '(0.0 0.0 0.0) (colour-map c)))
(set 'x (int (mul x scale)))
(set 'y (int (mul y -1 scale))) ; y goes upwards
(gs:fill-rect (string c) x y width width colour))
(define (escape x y)
(set 'z (Complex x y) 'c 0 'a z)
(while (and
(< (abs (:rad (set 'z (:add (:mul z z) a)))) 2)
(<inc> 80000 cells
(set 'scale (div canvas-width (sub max-x min-x)))
(set 'width (ceil (mul step scale)))
(for (y min-y max-y step)
(for (x min-x max-x step)
(do-cell x y (escape x y c)))
; end of row
(gs:update)))
(set 'start (time-of-day))
(set 'limit 100)
(plot)
(gs:set-text 'Mandelbrot (format "from %d/%d to %d/%d step: %0.4f scale: %0.4f cell-width: %d time: %0.4f " min-x min-y max-x max-x step scale width (div (- (time-of-day) start) 1000)))
(gs:listen)
Last edited by cormullion on Mon Jul 20, 2009 5:52 pm, edited 2 times in total.
The work around for ampersand escapes that I've found useful is to use the alternate &#; form.
--hsm
Code: Select all
<like this>
"Censeo Toto nos in Kansa esse decisse."—D. Gale "ℑ♥λ"—Toto
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Ideally, the code for Complex would be in an existing and fully tested file named complex.lsp, which would be loaded with (load "complex.lsp") and used the same way we use 5 or a string (just as you did). That would reduce it down to two lines ;-)cormullion wrote:Code is pretty basic - apart from michael's elegant complexity.
m i c h a e l
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
It works, thanks!hsmyers wrote:The work around for ampersand escapes that I've found useful is to use the alternate &#; form.Code: Select all
<like>
I'm not too worried about the speed of the complex numbers (or the size of the code :-). I think that all those rectangles are hard work...and I can't get better resolution because I run out of Java heap space...