Results 1 to 7 of 7

Thread: Pattern generator functions

  1. #1
    Join Date
    Dec 2006
    Location
    Pflugerville, TX, USA
    Posts
    1,977

    Default Pattern generator functions

    Does anyone have any pattern generator functions that they would like to share? Basically I am talking about a function that will create some XY point given some constant parameters, one of which is time. And by patterns I am talking about things like spirograph patterns, random/abstract patterns, etc.

    Maybe we could come up with a library of such things.

  2. #2
    Join Date
    Mar 2006
    Posts
    2,478

    Default

    Not on this machine or I'd paste them right now. They're in Lua, and they draw regular polygons, and they're not polished. They work though, and they're easy enough to translate because I try to stay with standard forms of syntax that work in other languages I've used. If I find them I'll post. Probably just the best single example. Which also has an array designed to accept a frame of arbitrary point count but that idea was really primal, barely formed. The main task was to do rotations of defined shapes, and it could make spirographs.
    Last edited by The_Doctor; 09-15-2007 at 09:26.

  3. #3
    Join Date
    Dec 2006
    Location
    Netherlands
    Posts
    983

    Default

    Aren't abstract generators usually based on a number of oscillators? Thus for each axis a number of sine functions added each with a parameter for amplitude, phase shift and frequency?
    something like:
    Code:
    x = a1 * sin( b1*t + c1 ) + a2 * sin( b2*t + c2 ) .... etc
    where:
    t is time
    an is amplitude
    bn is frequency
    cn phase shift


    For color one has to be more creative but is basically the same idea.

  4. #4
    Join Date
    Dec 2006
    Location
    Pflugerville, TX, USA
    Posts
    1,977

    Default

    Well, you can combine square waves, sine waves, saw tooths, etc and come up with all sorts of things. That is a given. But coming up with right formulas that actually produce something that is pleasing is not that trivial. Takes some fooling around. That's the point of this thread. To find some good ones. I think anyone that is interested in implementing these functions would already know what that they are based on waveforms so no need to discuss that I don't think.

  5. #5
    Join Date
    Mar 2006
    Posts
    2,478

    Default

    Probably not useful, and definitely not tidy, but here it is in full. I don't know if I can explain it anymore so if you want to ask, be careful what you wish for.

    What I do remember is it's optimised for WideMoves and I found a constant dwell time regardless of angular change was easier, as well as better, than trying to vary it according to any angular change. Also, I used linear interpolation, with a step count designed to keep small step size constant when possible. The array holds points to be joined with straight lines, curves would be built from segments of those... And I used Lua 5, as used in wxLua, though apart from the End Process message box, that code should run in the default Lua install on Linux or Windows. And it makes RAW wave files, stereo, 44.1 KHz (or vary to suit scanners), you'd need to import to wave editor and resave, I never made a WAV header code chunk.

    Code:
    --==============================================    Command Line Stereo Waveform Script    ===============================================--
    --  Make the dwell time and the step rate work together to maintain rotation speed. This allows thinning of the 'walls' and strengthening of corners.
    --  Dwell time should be calculated on the difference in step sizes for the axis with the largest rate change.
        --  Note! Only works with very fine time resolution.  D=math.max(math.abs(RXN,RXO),math.abs(RYN,RYO))
    
    --  LINE WEIGHT CALCULATION ERROR! It works, but the line length is not known till the rotator has done, and the draw length depends on step size and
    --  count which are based on line length. You can't specify an accurate rotation rate at the outset, unless you also exactly specify the draw rate.
    
    function Main()  local F,OUT,X,Y,A,N,P,R,S,D={},{},0,0,8192,2.33333333333333333333333,math.rad(0),math.rad(0.02),0.05,10
        for Z=1,N*3 do
            F[Z],F[-Z]=math.sin((Z-1)*2*math.pi/N),math.cos((Z-1)*2*math.pi/N)
        end
    --    F[1],F[-1]=0,0                                                              -- Array for frame, instead of for-loop polygon draw.
    --    F[2],F[-2]=-0.1,0.25
    --    F[3],F[-3]=0.01,1
    --    F[4],F[-4]=0.1,0.25
        local I,FL,SC,X,Y,SX,SY=1,table.getn(F)  local x,y,c,s=0,0  R=R/FL
        while table.getn(OUT)<44100*20  do
            c,s=math.cos(P),math.sin(P)  X,Y=c*F[I]+s*F[-I],c*F[-I]-s*F[I]          -- Rotator.
            SC=((X-x)^2+(Y-y)^2)^0.5/S+1  SX,SY=(X-x)/SC,(Y-y)/SC                   -- Step sizer.
            for Z=1,SC do  table.insert(OUT,Hex_Word(A,x+SX*Z,y+SY*Z))  end         -- Interpolator.
            for Z=1,D/SC+D do  table.insert(OUT,Hex_Word(A,X,Y))  end               -- Dwell points.
            I=I+1  if I>FL then  I=1  end  x,y=X,Y P=P+R
        end
        DataSave("TEST WAVE.raw",table.concat(OUT,"")) --,S+D+1
        wx.wxMessageBox("Finished Processing","",wx.wxOK+wx.wxICON_EXCLAMATION,wx.wxNull)
        os.exit()
    end
    
    --======================================================    Common  Functions   ==========================================================--
    
    function Hex_Word(S,X,Y)  X,Y=S*X,S*Y
        if (X<0) then  X=X+65536  end  if (Y<0) then  Y=Y+65536  end  return string.char(math.mod(X,256),X/256,math.mod(Y,256),Y/256)
    end
    
    function OpenTest(F)
        F=io.open(F)  if F then  return io.close(F)  end
    end
    
    function DataLoad(F)
        F=assert(io.open(F,"rb"))  local D=F:read("*a")  F:close()  return D
    end
    
    function DataSave(F,D)
        F=assert(io.open(F,"wb"))  F:write(D)  F:close()
    end
    
    --=======================================================    End  Of  Script   ===========================================================--
    
    Main()
    Edit:
    Never really said what it does.. Regular polygons, rotating. Or not. Also, polygons other than standard perimetric types, if N is a non-integer (as in the current variable assignments) and has a corresponding multiplier in the for-loop, it draws pentacles and similar forms cleanly. The current settings are for a 7-pointed rotating star.
    The four points in the commented-out array draw a clock hand. It won't tell the time, I found no way to get reliable time basing for that.
    Last edited by The_Doctor; 09-15-2007 at 13:10.

  6. #6
    Join Date
    Dec 2006
    Location
    Pflugerville, TX, USA
    Posts
    1,977

    Default

    Thanks, Doc. Should be interesting to port since I have never seen Lua code before.

  7. #7
    Join Date
    Mar 2006
    Posts
    2,478

    Default

    You're welcome. If there's any good in it, it will be more likely to come out if I'm not the only person doing it, especially as I'm NOT doing it anymore.

    Might though, if I can figure a way that makes it easy. One thought I had tonight: Linux, Unix, BSD, all have nice reserved 'file' names like com1, lpt1, and such that I have been told can be accessed as if they are files. So to write a stream to a sound port you just send it to the sound port by name as if it was a file on a disk, and sound comes out.

    If Windows had support to do that I might be able to do more, easily. That support wouldn't be a driver, those exist. It wouldn't be the OS's connection with the driver either. It would be something that talks to the OS, and appears to us perhaps as a virtual directory in an Explorer window like the Control Panel or Printers icons are used to access. And with standard paths for DOS access. It's such an obvious idea in hindsight, and as most other OS's do something like this, it could be done for Windows too. Someone must have thought of this and tried, but I don't know how far they got, or why I've never heard of anything like it.

    Lua is written in pure ANSI C, and can be compiled. I don't know how fast compiled Lua code runs, but it might be enough to do something for lasers in realtime, if that required support exists. Almost all cross-platform stuff can write to a file, access via a standard path, so it's vital that access to serial and parallel ports and VGA and sound ports and all be done that way on Windows just as it's done on Linux, BSD, Unix, but I've never seen it done! That mystifies me greatly.

    Anyway, if you ever get that code into a useful form and find anything worth using, let me know, it could be the basis for standardising if I ever work on it again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •