The Binary Zoo
Welcome, Guest. Please login or register.
May 26, 2013, 02:35:04 AM

Login with username, password and session length
Search:     Advanced search
Binary Zoo Current Projects:

We are going multi-platform.....very slowly.
29670 Posts in 1431 Topics by 164 Members
Latest Member: Martoon
* Home Help Search Calendar Login Register
+  The Binary Zoo
|-+  General
| |-+  Game Development
| | |-+  cellular textures
« previous next »
Pages: 1 [2] 3 Go Down Print
Author Topic: cellular textures  (Read 14411 times)
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #15 on: August 12, 2007, 09:07:21 AM »

Quote
Quote
could this be done in an other, more "real", free, language?
Yes but not necessarily any easier.....although it shouldn't be that hard anyway.  You just want one routine to generate the "grid" and another to blur the image.

i meant coding the real thing, like in the website
I hadn't seen the website link until now Tongue  That looks pretty simple to me.  The basic code for producing the texture on that site will work in DBPro with only slight modification.  It wont be very fast but it will work.
Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #16 on: August 13, 2007, 05:07:33 PM »

I've knocked up a quick version of that website code to see how fast it is.  Using the current technique it's very slow but that could be speeded up quite a bit with a memblock.

Anyway here's the code.  The texture wraps great and you can get some really nice effects by messing with the colour values. Smiley

Code:
sync on
sync rate 60
sync
randomize timer()
dim Function_Return(10)
null=make vector2(1)

global Texture_Width=100
global Texture_Height=100

global Pnt_Qty=10
type pnts
   X as integer
   Y as integer
endtype
dim Pnt(Pnt_Qty) as pnts

for p=1 to Pnt_Qty
   Pnt(p).X=rnd(Texture_Width)
   Pnt(p).Y=rnd(Texture_Height)
next p

type grids
   Dist as float
   Col as integer
endtype
dim Grid(Texture_Width,Texture_Height) as grids

`find distances
Mmin_dist#=999
Mmax_dist#=0
for y=0 to Texture_Height
   for x=0 to Texture_Width
      min_dist#=999
      for p=1 to Pnt_Qty
         for oy=-1 to 1
            for ox=-1 to 1
               dist#=Get_Distance_2D(x+(ox*Texture_Width),y+(oy*Texture_Height),Pnt(p).X,Pnt(p).Y)
               if dist#<min_dist# then min_dist#=dist#
            next ox
         next oy
      next p
      Grid(x,y).Dist=min_dist#
      if Grid(x,y).Dist<Mmin_dist# then Mmin_dist#=Grid(x,y).Dist
      if Grid(x,y).Dist>Mmax_dist# then Mmax_dist#=Grid(x,y).Dist
   next x
next y

`set colours
for y=1 to Texture_Height
   for x=1 to Texture_Width
      Grid(x,y).Col=255*((Grid(x,y).Dist-Mmin_dist#)/(Mmax_dist#-Mmin_dist#))
   next x
next y

`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

repeat
cls 0

for y=0 to Texture_Height
   for x=0 to Texture_Width
      ink rgb(Grid(x,y).Col,Grid(x,y).Col,Grid(x,y).Col),0
      dot x,y
   next x
next y

ink rgb(255,255,255),0
text 0,200,str$(screen fps())
sync
until escapekey()

`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`Get the distance between 2 points
function Get_Distance_2D(x1#,y1#,x2#,y2#)
x#=x2#-x1#
y#=y2#-y1#
set vector2 1,x#,y#
dist#=length vector2(1)
endfunction dist#

Logged

donny
Bunnymonkey
*****
Offline Offline

Posts: 619


http://www.whynot.tk

vincent_griezelig@hotmail.com
View Profile WWW Email
« Reply #17 on: August 14, 2007, 12:09:37 AM »

wtf, u're amazing:o
i found my mistakes, i just don't know enough of darkbasic yet
its very slow, 4fps:D
Logged
las6
Friend of The Zoo
Playtester
Bunnymonkey
*******
Offline Offline

Posts: 1732


creepy!

lauri_suopera@msn.com
View Profile Email
« Reply #18 on: August 14, 2007, 06:56:19 AM »

well it is slow because every time you generate the texture it has to do four distance calculations per pixel.
So if you have a 256x256 texture, that counts as 65536 pixels... and multiplying that by four gives us 262144. That's how many distance calculations are done to generate a single 256x256 texture. And while fog here uses the vector commands (I assume they are slightly faster than pure math) the distance calculation is going to be slow because at some point it will have to do a SQRT() (Square Root) - which is slow compared to the rest of the math.
Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #19 on: August 14, 2007, 07:19:30 PM »

its very slow, 4fps:D
Well it's slow but not that slow Smiley  The 4 FPS is because my code example is drawing the texture pixel by pixel every frame.  In reality you would just draw it once, turn it into an image, and then display the image.....which is very very fast.

And you could easily speed the initial image creation up by using memblocks. Smiley
Logged

donny
Bunnymonkey
*****
Offline Offline

Posts: 619


http://www.whynot.tk

vincent_griezelig@hotmail.com
View Profile WWW Email
« Reply #20 on: August 14, 2007, 08:18:51 PM »

Quote
Well it's slow but not that slow Smiley  The 4 FPS is because my code example is drawing the texture pixel by pixel every frame.  In reality you would just draw it once, turn it into an image, and then display the image.....which is very very fast.
so, the creation of the image 100*100px takes 1/4sec?
i tryed it 800*600 and it was like 0fps (probably 1/3fps, but its an integer, so...)

Quote
And you could easily speed the initial image creation up by using memblocks. Smiley
i don't know what memblocks are, if you have some sparetime you could make 'em

actually y'all have to know that i'm not imediatly planning to use this code, i just wanted to show you
Logged
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #21 on: August 14, 2007, 09:17:12 PM »

so, the creation of the image 100*100px takes 1/4sec?
i tryed it 800*600 and it was like 0fps (probably 1/3fps, but its an integer, so...)
Currently yes but it could be made faster.

actually y'all have to know that i'm not imediatly planning to use this code, i just wanted to show you
That's ok.  All coders like to discuss problems and possible solutions.  I bet most of the code we write is never used for anything useful.
Logged

donny
Bunnymonkey
*****
Offline Offline

Posts: 619


http://www.whynot.tk

vincent_griezelig@hotmail.com
View Profile WWW Email
« Reply #22 on: August 15, 2007, 01:02:16 PM »

Quote
Currently yes but it could be made faster.
I bet most of the code we write is never used for anything useful.
BUT, i could use it for my upcomming abstract bullet hell shooter.
Logged
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #23 on: August 16, 2007, 09:58:04 AM »

Quote
Currently yes but it could be made faster.
I bet most of the code we write is never used for anything useful.
BUT, i could use it for my upcomming abstract bullet hell shooter.
Cool.  Well have a mess around with that code and you can get some pretty neat effects.  Adding animation and a bit of colour is really easy.
Logged

donny
Bunnymonkey
*****
Offline Offline

Posts: 619


http://www.whynot.tk

vincent_griezelig@hotmail.com
View Profile WWW Email
« Reply #24 on: August 16, 2007, 11:31:04 AM »

animation?
with 4fps?
Logged
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #25 on: August 16, 2007, 12:47:19 PM »

animation?
with 4fps?
lol.  Well you pre-generate the textures when the game loads so there will be no slowdown in game.
Logged

donny
Bunnymonkey
*****
Offline Offline

Posts: 619


http://www.whynot.tk

vincent_griezelig@hotmail.com
View Profile WWW Email
« Reply #26 on: August 16, 2007, 12:48:25 PM »

hmm, could be done aesely, but the loading would take eaons
Logged
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #27 on: August 16, 2007, 01:04:53 PM »

hmm, could be done aesely, but the loading would take eaons
Well that depends on how big the texture is and how many frames of animation you need.

And you can be creating the textures in the background while you display a title or options screen.

And once you have created the necessary images why not just save them to disc so they can just be loaded the next time the game is run and are never generated again?
Logged

donny
Bunnymonkey
*****
Offline Offline

Posts: 619


http://www.whynot.tk

vincent_griezelig@hotmail.com
View Profile WWW Email
« Reply #28 on: August 16, 2007, 02:32:15 PM »

Quote
And once you have created the necessary images why not just save them to disc so they can just be loaded the next time the game is run and are never generated again?
i planned to do that for other projects in photoshop, but using that in the game would not make it random any more
but, whatever

Quote
And you can be creating the textures in the background while you display a title or options screen.
wouldn't that make the optionsscreen slow?
Logged
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12662



View Profile WWW Email
« Reply #29 on: August 16, 2007, 07:28:47 PM »

Quote
And you can be creating the textures in the background while you display a title or options screen.
wouldn't that make the optionsscreen slow?
Well you could run an options screen at 30fps and nobody would ever notice.  Regardless, provided you did it properly, nobody would know the textures were being generated because nothing would slow down.  You just generate the texture one small chunk every frame and not all in one go.

You might well think it's more trouble than it's worth and you could be right but it is possible. Smiley
Logged

Pages: 1 [2] 3 Go Up Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!