 |
| Author |
Message |
spooky
User
Joined: Fri Aug 30th 2002
Location: United Kingdom
|
Yes, I know it's not a mega 3D shoot-em-up but it does demonstrate basic 2D drawing and it does produce some very pretty pictures!
+ Code Snippet
remstart
A Mandelbrot fractal generator in only 20 lines!
(Only actually needs 15 lines but split data lines to aid readability)
After each image drawn, zoom in with left mouse button
variables to play with:
s = pixel size : bigger numbers = blockier image but much quicker to draw
i = maximum iterations : bigger numbers = more detailed image but slower
Only tested on DBPro patched to #2 on an Athlon XP 2000 PC running WinXP Home
remend
s=1: i=1000 : sync on : draw sprites first : dim c(153)
for f=1 to 153 : read c(f) : next f : x1#=-2 : x2#=2
y1#=-2 : y2#=2 : do : change mouse 1 : for y=0 to screen height()-1 step s
y3#=y1#+(y/(screen height()/(y2#-y1#))) : for x=0 to screen width()-1 step s : x3#=x1#+(x/(screen width()/(x2#-x1#))) : x4#=x3# : y4#=y3#
c=0 : for m=0 to i : x5#=(x4#*x4#)-(y4#*y4#)+x3# : y5#=((2*x4#*y4#)+y3#) : if sqrt((x5#*x5#)+(y5#*y5#))>2
c=(m mod 50)+1 : exit : endif : x4#=x5# : y4#=y5#
next m : ink rgb(c(c*3+1),c(c*3+2),c(c*3+3)),0 : box x,y,x+s,y+s : next x : sync
next y : sync : get image 1,0,0,screen width()-1,screen height()-1 : sprite 1,0,0,1 : set sprite 1,0,0
change mouse 0 : ink rgb(255,255,255),0 : do : if mouseclick()=1 : mx#=mousex()
my#=mousey() : while mouseclick()=1 : m2x#=mousex() : m2y#=mousey() : line mx#,my#,m2x#,my#
line m2x#,my#,m2x#,m2y# : line m2x#,m2y#,mx#,m2y# : line mx#,m2y#,mx#,my# : sync : endwhile
sync : if abs(mx#-m2x#)>10 and abs(my#-m2y#)>10 and m2x#>mx# and m2y#>my# : exit : endif : endif
loop : delete sprite 1 : x1n#=x1#+(mx#/(screen width()/(x2#-x1#))) : x2n#=x1#+(m2x#/(screen width()/(x2#-x1#))) : y1n#=y1#+(my#/(screen height()/(y2#-y1#)))
y2n#=y1#+(m2y#/(screen height()/(y2#-y1#))) : x1#=x1n# : y1#=y1n# : x2#=x2n# : y2#=y2n#
loop
data 0,0,0,175,0,0,193,0,0,209,0,0,223,0,0,235,3,0,244,9,0,250,18,0,253,30,0,253,44,0,250,60,0,244
data 78,0,235,97,0,223,117,0,209,136,0,193,156,0,175,175,0,156,193,0,136,209,0,117,223,0,97,235,0
data 78,244,0,60,250,2,44,253,10,30,253,24,18,250,42,9,244,63,3,246,87,0,223,113,0,209,140,0,193,166
data 0,175,190,0,156,211,0,136,229,0,117,243,0,97,251,0,78,254,0,60,251,0,44,253,0,30,229,3,18,211,9
data 9,190,19,3,166,30,0,140,44,0,113,60,0,60,78,0,63,97,0,42,117,0,24,136,0,10,156,0,2
I love it when a plan comes together
|
Back to top
 |
|
spooky
User
Joined: Fri Aug 30th 2002
Location: United Kingdom
|
Updated it a bit to fix a couple of annoyances.
Worked out that DBPro is crap with small numbers (even double floats) and so I wouldn't bother trying to write a similar program as you will just tear your hair out when you encounter the problems I found (usually with numbers down below 10 decimal places)
+ Code Snippet
remstart
A Mandelbrot fractal generator in only 20 lines!
After each image drawn, zoom in with left mouse button
variables to play with:
s = pixel size : bigger numbers = blockier image but much quicker to draw
i = maximum iterations : bigger numbers = more detailed image but slower
Only tested on DBPro patched to #2 on an Athlon XP 2000 PC running WinXP Home
V2 fixes:
1. No more blurry image when mouse selecting
2. Fixed some accuracy problems
Problems remaining:
1. After you zoom in about 7 times, everything blocky, this is
because DBPro's maths with very small numbers is very bugged
(take this as a warning if you plan on doing any complicated maths!)
remend
s=1 : i=1000 : sync on : draw sprites first : dim c(153)
x1 as double float : x2 as double float : x3 as double float : x4 as double float : x5 as double float
y1 as double float : y2 as double float : y3 as double float : y4 as double float : y5 as double float
sw=screen width()-1 : sh=screen height()-1 : for f=1 to 153 : read c(f) : next f
x1=-2 : x2=2 : y1=-2 : y2=2 : do
change mouse 1 : for y=0 to sh step s : y3=y1+(y*(y2-y1)/sh) : for x=0 to sw step s : x3=x1+(x*(x2-x1)/sw)
x4=x3 : y4=y3 : t=0 : for m=0 to i : x5=(x4*x4)-(y4*y4)+x3
y5=(x4*y4*2)+y3 : if sqrt((x5*x5)+(y5*y5))>2 : t=(m mod 50)+1 : exit : endif
x4=x5 : y4=y5 : next m : ink rgb(c(t*3+1),c(t*3+2),c(t*3+3)),0 : box x,y,x+s,y+s
next x : sync : next y : get image 1,0,0,sw,sh,1 : sprite 1,0,0,1
set sprite 1,0,0 : change mouse 0 : ink rgb(255,255,255),0 : do : if mouseclick()=1
mx=mousex() : my=mousey() : while mouseclick()=1 : nx=mousex() : ny=mousey()
line mx,my,nx,my : line nx,my,nx,ny : line nx,ny,mx,ny : line mx,ny,mx,my : sync
endwhile : sync : if abs(mx-nx)>10 and abs(my-ny)>10 and nx>mx and ny>my : exit : endif
endif : loop : delete sprite 1 : x3=(x2-x1)/sw : y3=(y2-y1)/sh
x2=x1+(nx*x3) : x1=x1+(mx*x3) : y2=y1+(ny*y3) : y1=y1+(my*y3) : loop
data 0,0,0,175,0,0,193,0,0,209,0,0,223,0,0,235,3,0,244,9,0,250,18,0,253,30,0,253,44,0,250,60,0,244,78,0,235,97,0,223
data 117,0,209,136,0,193,156,0,175,175,0,156,193,0,136,209,0,117,223,0,97,235,0,78,244,0,60,250,2,44,253,10,30,253,24,18
data 250,42,9,244,63,3,246,87,0,223,113,0,209,140,0,193,166,0,175,190,0,156,211,0,136,229,0,117,243,0,97,251,0,78,254,0,60
data 251,0,44,253,0,30,229,3,18,211,9,9,190,19,3,166,30,0,140,44,0,113,60,0,60,78,0,63,97,0,42,117,0,24,136,0,10,156,0,2
I love it when a plan comes together
|
Back to top
 |
|
David T
Moderator
 Joined: Tue Aug 27th 2002
Location: England
|
Very good!
I love Star Trek.
Especially the Episodes with Starships in.
|
Back to top
 |
|
G Man X
User
Joined: Wed Dec 11th 2002
Location: Cyberspace
|
How do you post a picture?
Good The Boyz Have Done It Is!
|
Back to top
 |
|
spooky
User
Joined: Fri Aug 30th 2002
Location: United Kingdom
|
This forum does not allow posting of images, e.t.c.
You have to upload to either free web-space you get with your dial-up account or go and buy a proper domain and upload it there. You use FTP to do this.
Once you have a 'url', e.g. http://www.xyz/piccy.jpg you just use the 'img' button in the 'post' box
I love it when a plan comes together
|
Back to top
 |
|
|
Google Ad
AdBot
Joined: Aug 26th 2002
Location: Everywhere
|
|
Back to top
 |
|
Attreid
User
Joined: Wed Nov 27th 2002
Location: Cyberspace
|
Wow, it's beautiful !
I think that it's the best twenty-lines programm that I have see.
congratulations !
I'm following John, but I'm not john.
Lol, it is funnier in french 
|
Back to top
 |
|
KamaKase
User
Joined: Tue Oct 29th 2002
Location: Cyberspace
|
grrrr...Doesn't work for me. Are there patches for DBC or something???
|
Back to top
 |
|
KamaKase
User
Joined: Tue Oct 29th 2002
Location: Cyberspace
|
ermmmm....doesn't work for me in DBPro I mean.
|
Back to top
 |
|
KamaKase
User
Joined: Tue Oct 29th 2002
Location: Cyberspace
|
...never mind. It works (sorry for multiposting)
|
Back to top
 |
|
Juju_Browser
User
Joined: Mon Apr 21st 2003
Location: Cyberspace
|
it is very cool
This is a chaotic mathematical situation
Juju_browser
|
Back to top
 |
|
Sorry, but it has been so long since anyone replied to this Thread that it has been automatically locked.
You may read it but not reply.
Enter a word or phrase to search our Forum for:
|
|
 |