Dark Bit Factory & Gravity

GENERAL => Challenges & Competitions => Topic started by: Deleter on April 30, 2008

Title: [PROCEDURAL] Wood
Post by: Deleter on April 30, 2008
Well this is a start to my entry. Right now its obviously not very flexible but I'm planning on expanding these calculations to accept parameters such as grain density, knot freqency, knot size, texture size, wood scale, and color. I'm not using any specific algorithm, just messing around and seeing what I can come up with.

Code: [Select]
screenres 512,512,32

dim as uinteger seed=&h02D8FAAE

dim as integer offset

randomize seed

dim as integer grain(63)
dim as integer ny(63)
dim as integer lastx(63)
dim as integer xstep
for streak as integer = 0 to 10
    for streakpart as integer = 0 to 5'-int(rnd*3)
        xstep=streak*5+streakpart
        offset = int(rnd*5)-2
        grain(xstep)=streak*50+streakpart*7'xstep*10+offset
        lastx(xstep)=grain(xstep)
        ny(xstep)=0
        '&hC58340
    next
next

const maxdisps=3

dim as integer dispx(maxdisps)
dim as integer dispy(maxdisps)
dim as integer dispm(maxdisps)

dispx(0)=256
dispy(0)=256
dispm(0)=35

dispx(1)=75
dispy(1)=400
dispm(1)=15

dispx(2)=125
dispy(2)=40
dispm(2)=15


dispx(2)=435
dispy(2)=80
dispm(2)=20


const maxd = 512^2 + 512^2

dim as integer tx,ty,td

paint(0,0),&hff00ff
for ystep as integer = 0 to 512
    for xstep as integer = 0 to 51
        if ny(xstep)=ystep then
            offset=int(rnd*3)-1
            lastx(xstep)=offset+grain(xstep)
            ny(xstep)=int(rnd*4)+ystep+2
        end if
        tx=lastx(xstep)
        ty=ystep
       
        for tmp as integer = 0 to ubound(dispx)
            td= (tx-dispx(tmp))^2 + (ty-dispy(tmp))^2
            tx += (1-(td/maxd))^19  *dispm(tmp) * sgn(tx-dispx(tmp))
        next
       
        pset (tx,ty),&h905219'&hC58430
    next
next

dim as any ptr img = imagecreate(512,512,&hff00ff)
dim as any ptr back = imagecreate(512,512,0)
dim as any ptr buffer = imagecreate(512,1,&hff00ff)

get (0,0)-(511,511),img
cls
'paint (0,0),&h956420
for x as integer = 0 to 511
    for y as integer = 0 to 511
        dim as integer c=rgb(&hAC+int(rnd*20),&h65+int(rnd*15),&h17+int(rnd*5))
        for tmpy as integer = -int(rnd*3)-1 to int(rnd*3)+1
        pset back, (x,y+tmpy),c
        next
    next
next
'sleep
for pass as integer = 1 to 10
    for tmpy as integer = 0 to 512
        get back,(0,tmpy)-(511,tmpy),buffer
        put (0,tmpy),buffer,pset'alpha,int(rnd*32)+64
        put (0,tmpy+1),buffer,alpha,int(rnd*32)+64
        put (0,tmpy+2),buffer,alpha,int(rnd*32)+64
        put (0,tmpy+3),buffer,alpha,int(rnd*32)+64
    next
next


line buffer,(0,0)-(511,0),0
for pass as integer = 1 to 10
    for tmpy as integer = 0 to 512
        dim as integer xoff=int(rnd*3)-1
        dim as integer yoff=int(rnd*5)-1
        'get back,(0,tmpy)-(511,tmpy),buffer
        'put (0,tmpy),buffer,pset
        'line buffer,(0,0)-(511,0),0
        get img, (xoff,tmpy+yoff)-(511,tmpy+yoff),buffer
        put (0,tmpy),buffer,alpha,int(rnd*32)+64
    next
next
sleep
for tmp as integer = 1 to 1
    get (0,0)-(511,511),img
    put (int(rnd*10),int(rnd*15)),img,alpha,int(rnd(80))+60
next

imagedestroy back
imagedestroy img
imagedestroy buffer
sleep

result so far:
(http://deleter.phatcode.net/woodtex.jpg)
Title: Re: [PROCEDURAL] Wood
Post by: Shockwave on April 30, 2008
Really nice looking wood texture :)

Title: Re: [PROCEDURAL] Wood
Post by: benny! on April 30, 2008
What Shocky says!
Title: Re: [PROCEDURAL] Wood
Post by: Dr_D on April 30, 2008
That's a good start man. I bet you could make some really detailed stuff with a bit of tweaking. :)
Title: Re: [PROCEDURAL] Wood
Post by: rain_storm on April 30, 2008
 definaley wood grain lotsa variety coming in for this compo :D
Title: Re: [PROCEDURAL] Wood
Post by: Clyde on May 01, 2008
Welldone Deleter :)
Title: Re: [PROCEDURAL] Wood
Post by: Optimus on May 02, 2008
Nice texture, I like it.
Title: Re: [PROCEDURAL] Wood
Post by: Deleter on May 02, 2008
Little number tweaks:

(http://deleter.phatcode.net/woodtex2.jpg)

(still have to make the knot position "random")
Title: Re: [PROCEDURAL] Wood
Post by: Shockwave on May 02, 2008
Thats cool, it looks almost Sketched!
Title: Re: [PROCEDURAL] Wood
Post by: hellfire on May 02, 2008
I really like that, hope you keep working on it!
It's not so far away from what the pros do (http://www.filterforge.com/filters/284.html)...
Title: Re: [PROCEDURAL] Wood
Post by: Pixel_Outlaw on May 12, 2008
I really like the notion of using math to create forms that mimic organic structures. Very nice.