|
Post by xxgeek on Jul 12, 2021 19:32:23 GMT
I understand fractals are used to created vivid scenes in movies like waves, clouds, mountain scenes, and a whole slew of other great graphics.
I was wondering if JB is capable and or fast enough, and if anyone here has used fractals to create any scenes, or anything else.
Anyone?
|
|
|
Post by B+ on Jul 12, 2021 23:55:29 GMT
'Autumn scene.txt for Just Basic 2015-10-03 MGA/B+ translated from: ' tree3.bas SmallBASIC 2015-05-13 translated from ' tree2.txt Naalaa 2015-05-14 MGA/B+ and help from chrisws! ' code inspired by tree found on Naalaa by Peter W
xmax=1200 ymax=700 nomainwin if 1200-xmax>0 then UpperLeftX = (1200-xmax)/2 else UpperLeftX=1 if 700-ymax>0 then UpperLeftY = (700-ymax)/2 else UpperLeftY=1 WindowWidth = xmax +8 'adjust +10 for screen frame plus slight white frame WindowHeight = ymax +31 'add +32 for screen frame plus slight white frame
'_nf =no full screen, _nsb =no scroll bars open "Autumn scene" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down"
'the sky for i=0 to 200 call ink 0,0,205+.25*i call aline 0,i,xmax,i next 'the earth for i=200 to ymax call ink 0,40+.18*i,0 call aline 0,i,xmax,i next 'yard is too neat for i=203 to ymax step 5 j=1 do x=rnd(1)*xmax call leaf2 x,i j=j+1 loop until (500-i)*.25-j<0 next 'the skyline for i=1 to 27 x=rnd(1)*xmax:s=rnd(1)*201:y=200-s:cc=rnd(1)*75 call ink cc,cc,cc call fbox x,y,x+s,y+s next 'the trees 7 back to front call DrawTree 1100,350,55,-90,7 call DrawTree 800,270,65,-90, 7 call DrawTree 550,325,70,-90,7 call DrawTree 325,380,65,-90,7 call DrawTree 125,400,75,-90,7 call DrawTree 900,430,80,-90,7 call DrawTree 600,500,85,-90,7 call DrawTree 300,525,75,-90,7 'more giants call DrawTree 50,500,105,-90,7 call DrawTree 1150,800,125,-90,7 call DrawTree 400,875,115,-90,7 #gr "flush" wait
[quit] close #gr end
'JB notes to BASIC like commands ----- but faster to NOT use CALLs ? sub ink r,g,b #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub bink r,g,b #gr "backcolor ";r;" ";g;" ";b end sub
sub fink r,g,b #gr "color ";r;" ";g;" ";b end sub
sub sink cstr$ #gr "color ";cstr$ #gr "backcolor ";cstr$ end sub
sub pset x,y #gr "set ";x;" ";y end sub
sub aline x0,y0,x1,y1 #gr "line ";x0;" ";y0;" ";x1;" ";y1 end sub
sub box x0,y0,x1,y1 #gr "place ";x0;" ";y0 #gr "box ";x1;" ";y1 end sub
sub fbox x0,y0,x1,y1 #gr "place ";x0;" ";y0 #gr "boxfilled ";x1;" ";y1 end sub
Sub circ x, y, radius #gr "Place ";x;" ";y;"; Circle ";radius End Sub
Sub fcirc x, y, radius #gr "Place ";x;" ";y;"; CircleFilled ";radius End Sub
Sub text x,y,message$ 'note: have to reset fore or back color after ink #gr "Place ";x;" ";y;";|";message$ End Sub
function rad(angle) rad = angle/180*3.1415926 end function
sub pause mil t=time$("milliseconds") while time$("milliseconds")<t+mil wend end sub '====================================================== for tree only sub DrawTree x1, y1, Size, theta, depth SA1=7+23*rnd(1) SA2=7+23*rnd(1) SF1=.60+.30*rnd(1) SF2=.60+.30*rnd(1) x2 = x1 + cos(rad(theta)) * Size y2 = y1 + sin(rad(theta)) * Size call ink 20+rnd(1)*40,35+rnd(1)*40,0 call aline x1,y1,x2,y2 if depth<5 then call leaf x2,y2 if depth<=0 then call leaf x2,y2 : exit sub call DrawTree x2,y2,Size*SF1+8-depth,theta-SA1,depth-1 call DrawTree x2,y2,Size*SF2+8-depth,theta+SA2,depth-1 end sub
sub leaf x,y sp=15 for n=1 to 5 call ink 50+rnd(1)*205,100+rnd(1)*155,0 xoff=x+rnd(1)*sp-rnd(1)*sp yoff=y+rnd(1)*sp-rnd(1)*sp woff=3+rnd(1)*3 hoff=3+rnd(1)*3 call fbox xoff,yoff,xoff+woff,yoff+hoff next end sub
sub leaf2 x,y sp=32 for n=1 to 5 call ink rnd(1)*128,50+rnd(1)*75,rnd(1)*20 xoff=x+rnd(1)*41-20 yoff=y+rnd(1)*5-2 woff=3+rnd(1)*.000012*y*y hoff=3+rnd(1)*.000005*y*y call fbox xoff,yoff,xoff+woff,yoff+hoff next end sub
|
|
|
Post by B+ on Jul 13, 2021 0:09:27 GMT
'checkered checkers v2.txt for Just Basic 2015-10-18 MGA/B+ ' I didn't like pause either!
nomainwin WindowWidth = 640+50 WindowHeight = 640+50 UpperLeftX=300 UpperLeftY=50 open "Close and click Run for next..." for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down" '============================== main code note: to text need min 10 in y value, text width(6-16) height 16 d=8:sq=640/d:sq8=sq/d:dm1=d-1 dim arr(d,d) #gr "color ";255;" ";0;" ";0 #gr "backcolor ";0;" ";0;" ";0 #gr "place ";20;" ";5 #gr "boxfilled ";660;" ";645 for j=0 to dm1 for i=0 to dm1 r=int(rnd(1)*2) if r then arr(i,j)=1 next next for y=0 to dm1 for x=0 to dm1 if arr(x,y) then for yy=0 to dm1 for xx=0 to dm1 #gr "color ";255;" ";0;" ";0 #gr "place ";20+x*sq+xx*sq8;" ";5+y*sq+yy*sq8 #gr "box ";20+x*sq+xx*sq8+sq8;" ";5+y*sq+yy*sq8+sq8 if arr(xx,yy) then #gr "color ";255;" ";0;" ";0 #gr "backcolor ";255;" ";255;" ";255 #gr "place ";20+x*sq+xx*sq8;" ";5+y*sq+yy*sq8 #gr "boxfilled ";20+x*sq+xx*sq8+sq8;" ";5+y*sq+yy*sq8+sq8 end if scan next next end if #gr "color ";0;" ";0;" ";255 #gr "place ";20+x*sq;" ";5+y*sq #gr "box ";20+x*sq+sq;" ";5+y*sq+sq next next #gr "flush" wait [quit] close #gr end
|
|
|
Post by B+ on Jul 13, 2021 0:11:55 GMT
'Infinite Heart.txt for Just Basic 2015-10-10 MGA/B+ <================= file data ' a fractal heart, almost, can't quite figure the recursive function, can't go that far anyway
global xmax,ymax,pi pi=3.1415926 xmax=720 '<===================== current draw space x width pixels ymax=720 '<===================== current draw space y height pixels nomainwin if 1200-xmax>0 then UpperLeftX = (1200-xmax)/2 else UpperLeftX=1 if 700-ymax>0 then UpperLeftY = (700-ymax)/2 else UpperLeftY=1 WindowWidth = xmax +8 'adjust +8 for screen frame plus WindowHeight = ymax +31 'add +31 for screen frame plus
'_nf =no full screen, _nsb =no scroll bars open "Infinite Heart" for graphics_nsb_nf as #gr '<======================== title caption #gr "trapclose [quit]" #gr "down" '============================== main code note: to text need min 10 in y value, text width(6-16) height 16 call ink 0,0,255 #gr "cls" x=(xmax-600)/2-1:y=(ymax-1.15*600)/2:wide=600 call drawdblheart x,y,wide call drawdblheart x+wide/2-wide/32,y+1.15*wide/4+wide/8,wide/16 call ink 255,0,0 'now in dots call pset x+wide/2,y+1.15*wide/4+wide/8+wide/32-3 call pset x+wide/2-1,y+1.15*wide/4+wide/8+wide/32-3 call pset x+wide/2-2,y+1.15*wide/4+wide/8+wide/32-3 call pset x+wide/2-1,y+1.15*wide/4+wide/8+wide/32-2 [finish] '============================== finish up #gr "flush" wait
[quit] close #gr end
'============== procedures for this code
sub drawblade x,y,wide scale=wide/200 sz=wide/4 yax=x+wide/2 'blade lasty=y steps=230*scale-sz call ink 255,255,255 for da=0 to 180 step 180/steps call aline yax-(1-cos(rad(da)))*sz, lasty, yax+(1-cos(rad(da)))*sz, lasty lasty=lasty+1 next call fcirc yax-sz,y+230*scale-sz,sz call fcirc yax+sz,y+230*scale-sz,sz end sub
sub drawdblheart x,y,wide 'for this heart height=wide*1.15 scale=wide/200 sz=wide/4 yax=x+wide/2 lasty=y+230*scale steps=230*scale-sz call ink 255,0,0 for da=0 to 180 step 180/steps call aline yax-(1-cos(rad(da)))*sz, lasty, yax+(1-cos(rad(da)))*sz, lasty lasty=lasty-1 next call fcirc yax-sz,y+sz,sz call fcirc yax+sz,y+sz,sz call drawblade x+sz+sz/2,y+sz,wide/4 end sub
'JB Library of procedures ======================================================
sub ink r,g,b #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub pset x,y #gr "set ";x;" ";y end sub
sub aline x0,y0,x1,y1 #gr "line ";x0;" ";y0;" ";x1;" ";y1 end sub
sub fcirc x, y, radius #gr "place ";x;" ";y;"; circlefilled ";radius end sub
function rad(angle) rad = angle/180*pi end function
|
|
|
Post by B+ on Jul 13, 2021 0:13:01 GMT
'Halloween Recuurence.txt for Just Basic 2015-10-25 MGA/B+ <================= file data
global xmax,ymax,deg2rad,sx deg2rad = Acs(-1)/180 'just mult this times degree angle instead of call sx=0 xmax=800 '<===================== current draw space x width pixels ymax=700 '<===================== current draw space y height pixels nomainwin 'open a temporary graphics window to determine the ' size a frame surrounding a Window. WindowWidth=300:WindowHeight=300 Open "." For Graphics_nsb_nf As #x
'find the coordinates of the center of temporary window #x "Home; PosXY x y"
'calculate and assign actual dimensions needed to obtain 'the desired graphics window size winx = xmax+(300-2*x) : winy = ymax+(300-2*y)
Close #x WindowWidth = winx WindowHeight = winy
if 1200-xmax>0 then UpperLeftX = (1200-xmax)/2 else UpperLeftX=1 if 700-ymax>0 then UpperLeftY = (700-ymax)/2 else UpperLeftY=1
'_nf =no full screen, _nsb =no scroll bars open "Halloween Recurrence" for graphics_nsb_nf as #gr '<======================== title caption #gr "trapclose [quit]" #gr "down" '============================== main code note: to text need min 10 in y value, text width(6-16) height 16 call ink 0,0,0 call fbox 0,0,xmax,ymax
cx=xmax/2:cy=ymax/2:pr=ymax/3
'inside a yellow/white color loop, shifting swirling eyes and movinging teeth d=1:offs=0 for nnn=1 to 1000 call pumpkin cx,cy,pr,1 sx=sx+4*d if sx>1.1*pr/12 then d=-1*d if sx<-1*pr/12 then d=-1*d call pause 1000 scan next
'============================== finish up #gr "flush" wait
[quit] close #gr end
'procedures for this code===================================== sub pumpkin cx,cy,pr,limit call ink 200,80,0 call fellipse cx,cy,3*pr,2*pr a=.95 call fink 0,0,0 for a=1 to 3 call ellips cx,cy,3*pr*(a/4),2*pr next call ellips cx,cy,3*pr*15/16,2*pr 'flickering candle light call ink irLH(200,255),irLH(200,255),120
'eye sockets call ftriangle cx-9*pr/12,cy-3*pr/12,cx-7*pr/12,cy-7*pr/12,cx-3*pr/12,cy-pr/12 call ftriangle cx-7*pr/12,cy-7*pr/12,cx-3*pr/12,cy-pr/12,cx-2*pr/12,cy-4*pr/12 call ftriangle cx+9*pr/12,cy-3*pr/12,cx+7*pr/12,cy-7*pr/12,cx+3*pr/12,cy-pr/12 call ftriangle cx+7*pr/12,cy-7*pr/12,cx+3*pr/12,cy-pr/12,cx+2*pr/12,cy-4*pr/12
'evil grin call ftriangle cx-9*pr/12,cy+1*pr/12,cx-7*pr/12,cy+7*pr/12,cx-6*pr/12,cy+5*pr/12 call ftriangle cx+9*pr/12,cy+1*pr/12,cx+7*pr/12,cy+7*pr/12,cx+6*pr/12,cy+5*pr/12
'moving teeth/talk/grrrr.. u=int(rnd(0)*4)+4 dx=pr/u for i=1 to u tx1=cx-6*pr/12+(i-1)*dx tx2=tx1+.5*dx tx3=tx1+dx ty1=cy+5*pr/12 ty3=cy+5*pr/12 ty2=cy+(4-rnd(0))*pr/12 ty22=cy+(6+rnd(0))*pr/12 call ftriangle tx1,ty1,tx2,ty2,tx3,ty3 call ftriangle tx1+.5*dx,ty1,tx2+.5*dx,ty22,tx3+.5*dx,ty3 next
'shifty eyes if limit then call pumpkin sx+cx-5*pr/12,cy-3.5*pr/12,.1*pr,0 call pumpkin sx+cx+5*pr/12,cy-3.5*pr/12,.1*pr,0 else exit sub end if end sub
'JB Library of procedures ====================================================== 'notes: arrays are global limited in dimensions, no constants, no imports, no declares... 'must "call" subs no ()! not even in definitions and must use () for parameterless functions
sub ink r,g,b #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub bink r,g,b 'backcolor is used for fills, so can make box with border one color, interior another #gr "backcolor ";r;" ";g;" ";b end sub
sub fink r,g,b 'text fore or box, circle edges #gr "color ";r;" ";g;" ";b end sub
sub sink cstr$ 'quick colors for drawing: fcirc, fbox #gr "color ";cstr$ #gr "backcolor ";cstr$ end sub
sub cs str$ 'mostly for text printing so forecolor only select case str$ case "white":call fink 255,255,255 case "gray":call fink 128,128,128 case "red" :call fink 255,0,0 case "blue":call fink 0,0,255 case "green":call fink 0,170,0 case "yellow":call fink 255,255,0 case "magenta":call fink 220,0,180 case "cyan":call fink 0,200,180 case "orange":call fink 250,80,0 case "brown":call fink 50,50,25 end select end sub
sub pset x,y #gr "set ";x;" ";y end sub
sub aline x0,y0,x1,y1 #gr "line ";x0;" ";y0;" ";x1;" ";y1 end sub
sub box x0,y0,x1,y1 #gr "place ";x0;" ";y0 #gr "box ";x1;" ";y1 end sub
sub fbox x0,y0,x1,y1 #gr "place ";x0;" ";y0 #gr "boxfilled ";x1;" ";y1 end sub
sub circ x, y, radius #gr "place ";x;" ";y;"; circle ";radius end sub
sub fcirc x, y, radius #gr "place ";x;" ";y;"; circlefilled ";radius end sub
sub ellips x,y,w,h #gr "place ";x;" ";y;"; ellipse ";w;" ";h end sub
sub fellipse x,y,w,h #gr "place ";x;" ";y;"; ellipsefilled ";w;" ";h end sub
'Fast Filled Triangle Sub by AndyAmaya Sub ftriangle x1, y1, x2, y2, x3, y3 'triangle coordinates must be ordered: where x1 < x2 < x3 If x2 < x1 Then x = x2 : y = y2 : x2 = x1 : y2 = y1 : x1 = x : y1 = y 'swap x1, y1, with x3, y3 If x3 < x1 Then x = x3 : y = y3 : x3 = x1 : y3 = y1 : x1 = x : y1 = y 'swap x2, y2 with x3, y3 If x3 < x2 Then x = x3 : y = y3 : x3 = x2 : y3 = y2 : x2 = x : y2 = y If x1 <> x3 Then slope1 = (y3-y1)/(x3-x1) 'draw the first half of the triangle length = x2 - x1 If length <> 0 Then slope2 = (y2-y1)/(x2-x1) For x = 0 To length #gr "Line ";int(x+x1);" ";int(x*slope1+y1);" ";int(x+x1);" ";int(x*slope2+y1) Next End If 'draw the second half of the triangle y = length*slope1+y1 : length = x3-x2 If length <> 0 Then slope3 = (y3-y2)/(x3-x2) For x = 0 To length #gr "Line ";int(x+x2);" ";int(x*slope1+y);" ";int(x+x2);" ";int(x*slope3+y2) Next End If call aline x1,y1,x2,y2 call aline x2,y2,x1,y1 call aline x2,y2,x3,y3 call aline x3,y3,x2,y2 call aline x1,y1,x3,y3 call aline x3,y3,x1,y1 End Sub
sub text x,y,message$ 'note: have to reset fore or back color after ink #gr "place ";x;" ";y;";|";message$ end sub
sub ctext y,message$ 'uses const xmax call text (xmax-len(message$)*7)/2,y,message$ end sub
sub pause mil t=time$("milliseconds") while time$("milliseconds")<t+mil wend end sub
function irTF() 'make sure call with () irTF=int(rnd(1)*2) end function
function ir255() ir255= int(rnd(1)*256) end function
function irLH(L,H) irLH= int(rnd(1)*(H-L+1))+L end function
function rCD(center, dist) rCD=center+rnd(1)*2*dist-dist end function
|
|
|
Post by B+ on Jul 13, 2021 0:14:59 GMT
'Mr Giggles.txt for Just Basic 2015-10-07 MGA/B+ <================= file data 'extremely modified code from Peter W spiral Bp.org today 'Mr Giggles is the name I gave to first shape draw here. Mr Giggles is famous for his one-liners.
global xmax,ymax,pi xmax=800 '<===================== current draw space x width pixels ymax=700 '<===================== current draw space y height pixels pi=3.1415926 nomainwin if 1200-xmax>0 then UpperLeftX = (1200-xmax)/2 else UpperLeftX=1 if 700-ymax>0 then UpperLeftY = (700-ymax)/2 else UpperLeftY=1 WindowWidth = xmax +8 'adjust +8 for screen frame plus WindowHeight = ymax +31 'add +31 for screen frame plus '_nf =no full screen, _nsb =no scroll bars open "Mr Giggles" for graphics_nsb_nf as #gr '<======================== title caption #gr "trapclose [quit]" #gr "down"
'============================== main code note: to text need min 10 in y value, text width(6-16) height 16 while 1:#gr "fill black":call ink 255,0,0:inc=inc+.7:an2=pi/2:an3=.334:an1=.1+inc:an3=.1+inc:xc=xmax/2:yc=ymax/2:xa=300:ya=300:x1=cos(an1)*xa*cos(an3)+xc:y1=sin(an2)*ya*sin(an3)+yc:for i=1 to 5000:x2=cos(an1)*xa*cos(an3)+xc:y2=sin(an2)*ya*sin(an3)+yc:call circ x2,y2,3:an1=an1+.0666: an2=an2+.0999:an3=an3+.0334:xa=xa*.9999:ya=ya*.9999:scan:next:call pause 1500:wend '============================== finish up
#gr "flush" wait
[quit] close #gr end
'JB Library of procedures ======================================================
sub ink r,g,b #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub circ x, y, radius #gr "place ";x;" ";y;"; circle ";radius end sub
sub pause mil t=time$("milliseconds") while time$("milliseconds")<t+mil wend end sub
|
|
|
Post by B+ on Jul 13, 2021 0:16:12 GMT
That's just 2015
|
|
|
Post by xxgeek on Jul 13, 2021 1:23:45 GMT
Hey B+, I was hoping you would post on this. Good to see you. Not exactly what I was thinking, let me restate....
The kind of fractal graphics you get in games with moving scenes and things like fire, and water splashing that looks so good for what it is. Maybe it's my i5 and onboard graphics though. Would up to date state of the art hardware be better. to view these with?
The last one in your list is getting close, and closer to what I meant so is the first one, if a player could walk or run into the autumn scene as it moves. Can you do that? I was doing a bit of graphics stuff way way back, but nothing like what is possible today.
Thanks for posting I'll play around with the code and see what variations I can come up with. No big deal though B+, I was just curious. I'm not working on a graphics app.
|
|
|
Post by B+ on Jul 13, 2021 1:37:38 GMT
Yeah, JB is probably too slow for real time action play.
PS I mean with drawings not sprites.
|
|
|
Post by xxgeek on Jul 13, 2021 1:48:45 GMT
Yeah, JB is probably too slow for real time action play. PS I mean with drawings not sprites. I thought so. Was hoping I was wrong, oh well. Thanks for taking the time B+
|
|
|
Post by Rod on Jul 13, 2021 7:03:39 GMT
|
|
|
Post by xxgeek on Jul 13, 2021 16:28:37 GMT
That was cool. The whole moving scene is one bmp file. Now I'll have to learn about all the graphics commands and do some playing around. Thanks Rod
|
|