Author Topic: Waves and Particles  (Read 2353 times)

0 Members and 2 Guests are viewing this topic.

Charles Pegge

  • Guest
Waves and Particles
« on: March 10, 2013, 07:32:57 PM »
The source code for this demo can be found in  Oxygen-inProgress: /examples/GUI/glWaveParticle.o2bas

Peter knows the algorithm:

Code: [Select]
...
  sub MakePatternB(sys n)
  '======================
  '
  %size 1024
  static long pixels[size*size]
  static long tx=size, ty=size, x, y, p, c
  '
  type   rgba  byte r,g,b,a
  double range,x,y,r,sc,stp
  long   px,py,p
  rgba   tex at (@pixels)
  '
  range=28 : sc=127 : stp=range*2/size
  y=-range
  p=@pixels
  for py=1 to size
    x=-range
    for px=1 to size
      r = Cos(x) + Sin(y)      
      Tex.r = 128+sc*Cos(y*r)
      Tex.g = 128+sc*Cos(x*y*r)
      Tex.b = 128+sc*Sin(r*x)
      Tex.a = 255
      @tex+=sizeof tex 'ADVANCE TEXTURE ARRAY POINTER
      x+=stp
    Next
    y+=stp
  Next
  '
  glBindTexture GL_TEXTURE_2D, texn[n]
  glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
  glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
  glTexImage2D GL_TEXTURE_2D, 0, 4, tx, ty, 0, GL_RGBA, GL_UNSIGNED_BYTE, @Pixels
  '
  end sub
...

Charles

X

Charles Pegge

  • Guest
Re: Waves and Particles
« Reply #1 on: March 11, 2013, 07:36:10 AM »
There are many possibilities. The algorithm is very robust.


  range=24 : sc=127 : stp=range*2/size
  y=-range
  p=@pixels
  for py=1 to size
    x=-range
    for px=1 to size
      cosx=cos(x)
      siny=sin(y)
      'r=+Cosx+Siny '24
      'r = cosx * Siny '32     
      'r = Cosx * Siny+Cosx+Siny '24     
      'r = Cosx*Cosx+Siny*Siny '24     
      'r = hypot(Cosx,Siny) '***     
      'r = hypot(Cosx,Siny)+(cosx+siny)
      r = hypot(Cosx,Siny)+(cosx+siny)*.5
      Tex.r = 128+sc*Cos(r*y)
      Tex.g = 128+sc*Cos(r*x*y)
      Tex.b = 128+sc*Sin(r*x)
      Tex.a = 255
      @tex+=sizeof tex 'ADVANCE TEXTURE ARRAY POINTER
      x+=stp
    Next
    y+=stp
  Next



X