Mandelbrot

Your contraptions, images, w/e

Mandelbrot

Postby echo1001 » Tue Dec 22, 2009 7:08 pm

A Mandelbrot set scripted in lua. Simple but cool...

1920x1200 resolution with 3000 iterations, took around 2 minutes to render.
result.png


Code: Select all
require 'gd'
local dime = {1920,1200}
--local dime = {400,400}
local im = gd.createTrueColor(dime[1], dime[2])
local white = im:colorAllocate(255, 255, 255)
local black = im:colorAllocate(0, 0, 0)
local MinRe = -2
local MaxRe = 1
local MinIm = -1.2
local MaxIm = MinIm + (MaxRe-MinRe) * dime[2]/dime[1]
local Re_factor = (MaxRe-MinRe)/(dime[1]-1);
local Im_factor = (MaxIm-MinIm)/(dime[2]-1);
local MaxIterations = 3000

for y=0, dime[2] do
   local c_im = MaxIm - y*Im_factor
   for x=0, dime[1] do
      local c_re = MinRe + x*Re_factor
      local Z_re = c_re
      local Z_im = c_im
      local isInside = true
      local d = 0
      for n=0, MaxIterations do
         local Z_re2 = Z_re*Z_re
         local Z_im2 = Z_im*Z_im
         
         if Z_re2 + Z_im2 > 4 then
            isInside = false;
            d = n
            break
         end
         
         Z_im = 2*Z_re*Z_im + c_im
         Z_re = Z_re2 - Z_im2 + c_re
         
      end
      if isInside then
         im:setPixel(x,y, white)
      else
         local mul = (d < MaxIterations/2) and (d / MaxIterations) * 100 or 0
         local mul2 = (d > MaxIterations/2) and d / MaxIterations or 0
         local col = im:colorResolve(0,mul2*255,mul*255)
         im:setPixel(x,y,col)
      end
   end
   print((y/dime[2])*100 .. "%")
end

im:png("result.png")
"He was hover-gunning someone on a physboard." ~ Smithy
"I've tried Pussy, It's horrible!" ~ PAUL (Out of context, talking about a drink)
"22:45:38 (Team) HalfBurntToast : your trickery is no match for our might
22:45:43 (Team) HalfBurntToast : for GONDOR
22:46:27 (Team) HalfBurntToast : his numbers are too great"

Image
User avatar
echo1001
Community Leader
United Alliance
9479 Hours
Player since: Jul 11, 2010
 
Posts: 901
Joined: Mon Feb 18, 2008 12:01 am
Location: Hutchinson, KS
SteamID: STEAM_0:1:5601022
Steam User Name: pcthree
Rig: AMD Anthlon II x4 2.6 Ghz (oc'd to 3.38 Ghz)
4 GB RAM
EVGA nVidia GTX 470 2-way SLI
MSI NF980-G65
650 GB HDD

Re: Mandelbrot

Postby CasanovaFrankenstein » Tue Dec 22, 2009 9:51 pm

Awesome! Something from school?
Image
User avatar
CasanovaFrankenstein
Community Co-Leader
Mad Scientist
1588 Hours
Player since: Jul 8, 2010
 
Posts: 970
Joined: Mon Feb 18, 2008 1:39 pm
SteamID: Steam_0:0:3320092
Steam User Name: CasanovaF

Re: Mandelbrot

Postby echo1001 » Tue Dec 22, 2009 11:18 pm

Nah, personal project. I came across it when doing some general reading in wikipedia. It took like 5 minutes to write.

I was easily able to reproduce the code in c# and added threading for a live preview.

Next I need to work on a buddhabrot script. (Google it, they're cool looking)
"He was hover-gunning someone on a physboard." ~ Smithy
"I've tried Pussy, It's horrible!" ~ PAUL (Out of context, talking about a drink)
"22:45:38 (Team) HalfBurntToast : your trickery is no match for our might
22:45:43 (Team) HalfBurntToast : for GONDOR
22:46:27 (Team) HalfBurntToast : his numbers are too great"

Image
User avatar
echo1001
Community Leader
United Alliance
9479 Hours
Player since: Jul 11, 2010
 
Posts: 901
Joined: Mon Feb 18, 2008 12:01 am
Location: Hutchinson, KS
SteamID: STEAM_0:1:5601022
Steam User Name: pcthree
Rig: AMD Anthlon II x4 2.6 Ghz (oc'd to 3.38 Ghz)
4 GB RAM
EVGA nVidia GTX 470 2-way SLI
MSI NF980-G65
650 GB HDD

Re: Mandelbrot

Postby echo1001 » Wed Dec 23, 2009 12:28 pm

Here's a buddhabrot render, this one took about an hour in C# (309 lines) using 100% of my processor. (multithreaded, used both cores)

test5.png


29 minutes 40 seconds:

buddha-flower.png
"He was hover-gunning someone on a physboard." ~ Smithy
"I've tried Pussy, It's horrible!" ~ PAUL (Out of context, talking about a drink)
"22:45:38 (Team) HalfBurntToast : your trickery is no match for our might
22:45:43 (Team) HalfBurntToast : for GONDOR
22:46:27 (Team) HalfBurntToast : his numbers are too great"

Image
User avatar
echo1001
Community Leader
United Alliance
9479 Hours
Player since: Jul 11, 2010
 
Posts: 901
Joined: Mon Feb 18, 2008 12:01 am
Location: Hutchinson, KS
SteamID: STEAM_0:1:5601022
Steam User Name: pcthree
Rig: AMD Anthlon II x4 2.6 Ghz (oc'd to 3.38 Ghz)
4 GB RAM
EVGA nVidia GTX 470 2-way SLI
MSI NF980-G65
650 GB HDD

Re: Mandelbrot

Postby SciTech » Thu Dec 24, 2009 12:59 pm

Nice. I have no idea what it is, but I like pwetty pictures. xD
"If at first you don't succeed.. Make an E2 to do it for you."
User avatar
SciTech
Global Admin
 
Posts: 201
Joined: Sun Mar 22, 2009 2:16 am
SteamID: STEAM_0:1:23264416


Return to Show-off

Who is online

Users browsing this forum: No registered users and 0 guests

cron