Shop OBEX P1 Docs P2 Docs Learn Events
64 Random Pixels - up for grabs — Parallax Forums

64 Random Pixels - up for grabs

Jay KickliterJay Kickliter Posts: 446
edited 2010-05-10 17:16 in Propeller 1
A few months ago I released a design and gave away a couple empty boards for a concept I was working on. School got tough and I got burnt out on electronics, explaining my absence from the forum. Anyways, I'm on summer vacation, and am resurrecting this project.

The board tiny (~ 1.2" x 2"), with a Propeller and an 8x8 array of LED's. My attempt at conceptual art is for the LED's to step through every possible combination of pixels, not ever getting there naturally. Simple enough, just increment a a 64 bit number and watch the patterns emerge. But I was thinking that it would be cooler to randomly jump around, and temporarily display the current image, then move on. The concept is that anything that can be discernible in an 8x8 matrix will eventually appear, including digits, and the symbol for pi. Oh, and my favorite, 'e'.

To my question, in order for it to work, it seems to me like I need a 64 bit random number generator. Or at least a way to fake it. Is that even possible? I can't just randomize every pixel, since that will only give me static. Any ideas? I figure this might be something that could be posted to hackaday and the like to give the Propeller some nerd cred and exposure. Truthfully, the weather is too nice for me to want to spend too much time indoors working on this, but I'm 99% percent done and would like to give something back.

I messed up reflowing the board that I made, and need to replace the USB connector, but unless I made a really stupid error, it should work.

Edit:

I forgot to add the specs if anyone is curious.
100% surface mount (I used a cheap plastic stencil, which is why I got too much paste on the USB connector)
64 0603 yellow LED's
USB programming
Lithium Polymer battery on the back, either coincell or with JST connector.
Battery charging when plugged in to USB via Maxim 1555 IC
1.2" x 2.1" (ish, don't have my calipers handy)
Low drop out voltage regulator, plenty of decoupling caps, etc. Most passives 0603.

Post Edited (Jay Kickliter) : 5/4/2010 5:24:15 PM GMT
428 x 564 - 67K

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-02 22:56
    Congratulations Jay. IIRC the prop does have a pseudo random number generator in spin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Kal_ZakkathKal_Zakkath Posts: 72
    edited 2010-05-03 00:17
    The easiest way I can think of to avoid the 'static' look would be to just flip a small number of bits on each cycle - as in, randomly generate a number of bits to change (say 1-5, or even just 1 bit each cycle), then randomly generate the bit position(s) to change (1-64).

    I suspect you'll be waiting a pretty long time if you want to see a character appear though tongue.gif (at least without some 'cheating' to limit the randomness)
  • Roger LeeRoger Lee Posts: 339
    edited 2010-05-03 01:03
    Jay, You want to hit ALL possibilities, in a RANDOM LOOKING pattern.

    First off, I don't know how.

    Could a method from meshed gears work for you.
    100 teeth with 50 teeth will repeat meshing the same teeth over and over.
    101 : 50 gives very long period.

    I don't have the number to add, to get through your 64 bit number with a long period.
    Possibly two or more counters working alternately.

    my 2 cents.

    OK, this (at best) will give you a pattern of 1) many bits 2) vary few bits 3) repeat
    That's fails on the part about Looking Random.

    Post Edited (Roger Lee) : 5/3/2010 4:00:49 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-03 04:58
    Jay Kickliter said...
    The concept is that anything that can be discernible in an 8x8 matrix will eventually appear, including digits, and the symbol for pi. Oh, and my favorite, 'e'.
    You should read Jorge Luis Borges', "The Library of Babylon", which is included in many anthologies of his short stories. I think you'd enjoy it!

    -Phil
  • pullmollpullmoll Posts: 817
    edited 2010-05-03 10:41
    Jay Kickliter said...
    To my question, in order for it to work, it seems to me like I need a 64 bit random number generator. Or at least a way to fake it. Is that even possible?

    The easiest way to achieve what you want is to build a 64 bit LFSR (linear feedback shift register). If the feedback points are in the right positions, the LFSR can be maximum length, meaning it passes through all possible numbers before it repeats. With 64 bits this will take some time

    An example for a 64 bit LFSR is the so called "dense" polynome used in the DLT1 spec ECMA-182. It is:
    x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 + x^40 +
    x^39 + x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 + x^24 + x^23 +
    x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 + x^7 + x^4 + x + 1

    You create a 64 bit number pattern with a 1 in places of each term's exponent, so this would be bits #63, #61, #56, #54 ... #0. The value is 0xad93d23594c93659. A byte is fed into the LFSR by 8 times shifting the value left one position and, if the bit #0, #1, #2 of the byte xor the bit #63 of the polynome value is set, xoring the LFSR with this xor value.

    But you don't want to feed bytes into a CRC like algorithm, you want pseudo random numbers. You could just do:
    VAR
        long    cog
        long    lfsr_cnt
        long    lfsr_lsb
        long    lfsr_msb
    
    PUB start
        cog := COGNEW(@entry, @lfsr_cnt) + 1
    
    PUB lfsr(cntr, my_uint64_ptr)
        lfsr_cnt := cntr
        repeat while lfsr_cnt
        long[noparse][[/noparse]my_uint64_ptr][noparse][[/noparse]0] := lfsr_lsb
        long[noparse][[/noparse]my_uint64_ptr](1) := lfsr_msb ' this forum software eats up a 1 in square brackets ;-/
    
    DAT
            org    0
    entry
            mov    hubram_ptr, PAR
    wait
            rdlong    count, hubram_ptr    WZ
        if_z    jmp    #wait
    
    lfsr64
            shl    oldval, #1        WC
            rcl    oldval+1, #1        WC
        if_c    xor    oldval, xor_lsb
        if_c    xor    oldval+1, xor_msb
    
            djnz    count, #lfsr64
            add    hubram_ptr, #4
            wrlong    oldval, hubram_ptr
            add    hubram_ptr, #4
            wrlong    oldval+1, hubram_ptr
            sub    hubram_ptr, #2*4
            wrlong    count, hubram_ptr
            jmp    #wait
    
    count        long    0
    oldval        long    0, 1
    xor_lsb        long    $94c93659
    xor_msb        long    $ad93d235
    hubram_ptr    long    0-0
    
    



    Then you call e.g. lfsr(1) and can inspect the two longs lfsr_lsb and lfsr_msb afterwards. If you start with these values, you can see the 1 in oldval shifting up to $80000000 and then the (pseudo) chaos begins.

    A much more nerdy project would be to display 64 bits of the digits of Pi, i.e. 0..63, then 64..127 etc. pp. There is a formula that allows you to calculate these from any position in binary or hex. I don't have the formula handy, though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects

    Post Edited (pullmoll) : 5/3/2010 12:08:30 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-03 17:07
    FYI: If displaying the random patterns at the rate of one every microsecond, it would take nearly 585 millennia to see all of them.

    -Phil
  • Christof Eb.Christof Eb. Posts: 1,246
    edited 2010-05-03 18:25
    Hi Jay,

    random numbers will be just noise, like a disconnected antenna at the television. The chance to be in front of the screen and see "e" and recognise it·is very very low. So you will have to cheat a little bit and show something that looks like random....... Or random, that looks like something with system: Mandelbrots Fractals perhaps?

    Christof
  • Jay KickliterJay Kickliter Posts: 446
    edited 2010-05-03 20:04
    Christof, isn't the difference that a truly random 64 bit number would look a lot different than just fuzz? My understanding is that a fuzzy tv picture is a whole bunch of random numbers applied to individual pixels, with pretty much no chance of a pattern emerging.

    Phil, actually, that's kind of the point. A pin to wear to hacker parties (at least NYC is good for one thing) that you know eventually will show a smiley face but you'll never actually see it. Hey, I'm a wannabe engineer, this is my attempt at 'art'. I just like the idea of knowing patterns are there, even if I'll never see them. If I was to make a bunch of them, people can reprogram to do whatever they want, like display crude animations.

    pullmol, thanks for the code. I'm going to give it a try.

    That said, I need to get the thing to work first.

    Speaking of Mandelbrot, do yourself a favor guys and check out Jonathan Coulton's Mandelbrot Set. Using the lyrics without access to the internet, and some spare time, I came up with the attachment. Code Monkey is good also.
    1024 x 768 - 171K
  • VIRANDVIRAND Posts: 656
    edited 2010-05-04 08:19
    Maybe try this, if you have a calculator that can do the math, or can do it by hand:

    Try dividing 2 to the power of 64 by small prime numbers near 100,
    and writing down the primes that divide 2 to 64th with no remainders.
    Then, see what happens when you add THOSE, PLUS (OR MINUS) ONE,
    to your two longs of 64 bits for the LEDs (with just a couple of lines of Spin).
    You only need one of "THOSE" but some sequence results may look nicer than others.

    I'd expect the sequences to vary in apparent randomness from static to noticeable patterns,
    and probably not skip any combinations like LFSRs do; LFSRs usually skip only zero.

    I have discovered some pseudorandom algorithms that make "alien fonts" but they
    have limited "alphabets" that I did not design. (Just as nobody "designed" the shape
    of Mandelbrot's Set)

    Perhaps if you design the font of glyphs you would like to see, and then feed it into
    the Berlekamp-Massey algorithm, it will create a repeating LFSR that generates those,
    and after that, who knows? But it will eventually repeat. I don't have Mathematica, so
    don't ask me how to do that... But...
    (nevermind)

    A simpler, more obvious method would be to create a glyph font, and write a program
    that randomly changes pixels to the next glyph, until glyph matches the display, and then stops
    trying to make the glyph it just made, and starts trying to make the next one. If you use the
    Spin random number generator, be sure to use it to select the one of 64 LEDs, because it
    will definitely skip pixels forever if you try to get X and Y from it separately. But it probably
    works this way with ?LED and then LED:=LED//64 (and then X:=LED/8 and then Y:=LED//8 if
    you Need to do it that way). I would describe this effect as similar to how I saw a digital
    picture frame morph between two pictures in such a way that the morph midpoint resembled
    TV static more than either of the two pictures.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I should be typing in Spin now.
    Coming soon. My open Propeller Project Pages and favorite links index.
  • pullmollpullmoll Posts: 817
    edited 2010-05-04 08:51
    VIRAND said...
    Try dividing 2 to the power of 64 by small prime numbers near 100,
    and writing down the primes that divide 2 to 64th with no remainders.

    You mean like 2*2*2*2 for 2^4 or 2*2*2*2*2 for 2^5? wink.gif
    The prime factor(s) of powers of 2 are 2 - all of them.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects
  • heaterheater Posts: 3,370
    edited 2010-05-04 09:32
    Watching the random static on old black and white TV's could get quite interesting if you stared at a patch of screen for a long while. Swirling patterns start to emerge, in colour!

    How about a mini Conways Game of Life?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2010-05-04 09:40
    Go for the random noise, but stick in few subliminal paterns. Just enough to intrigue any passer by.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Style and grace : Nil point
  • pullmollpullmoll Posts: 817
    edited 2010-05-04 10:51
    heater said...
    How about a mini Conways Game of Life?

    That should be interesting. You'd have to detect a static "picture", i.e. nothing but blinkers left, and inject some random dots to revive the action.
    Start with an R-pentomino for a lot of cycles. I don't remember how much it were... many.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects
  • heaterheater Posts: 3,370
    edited 2010-05-04 14:50
    @Jay: You know, I think that little board would be very useful for all kinds of applications where little status indicators and such are required. You should produce a bunch of them or get someone else to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Jay KickliterJay Kickliter Posts: 446
    edited 2010-05-04 17:05
    heater, I'll give the design to anyone who wants it. I don't have the time to mess around with it now. Actually, I did post the board files on here a few months ago, I think. What I really want to do is add an IR receiver and TX so people could make them interact, not sure how, but it seems like a good idea.

    EDIT:

    You know what, there are a lot more capable people here than me. I'm looking outside, and the weather is nice, and itching for a road trip in my recently acquired diesel car. If anyone here is really good at surface mount rework, I'll give you the one photo. It's fully populated, and as far as I know I only messed up the USB connector. I don't know if the QFN chip flowed correctly, but I'm not reading any shorts on my meter. So, if you're good at this stuff, let me know and it's yours. And feel free to shame for abandoning it, I'll be laughing all the way to the Rockies.

    Post Edited (Jay Kickliter) : 5/4/2010 5:21:50 PM GMT
  • VIRANDVIRAND Posts: 656
    edited 2010-05-04 19:23
    pullmoll said...
    VIRAND said...
    Try dividing 2 to the power of 64 by small prime numbers near 100,
    and writing down the primes that divide 2 to 64th with no remainders.

    You mean like 2*2*2*2 for 2^4 or 2*2*2*2*2 for 2^5? wink.gif
    The prime factor(s) of powers of 2 are 2 - all of them.

    Sorry, I meant (2 to the 64th)-1, assuming that's not a mersenne, and if it is, hmmm.

    I was thinking of something like at each step, adding ((2 to the 64th)/91)+1 assuming
    that 91 is a prime that divided 2'64 with no remainder. That may be wrong, but if not,
    the intent is to get a result similar to adding 1 (going thru all combos in order) but by
    also adding a large and ugly non-power-of-2 number to make it look more random
    and still guarantee a "Normal" sequence that never skips a combo, just like adding 1,
    which may not even be necessary if the "ugly number" divides 2'64 with a remainder
    of 1.

    I'm sure that what I am trying to say to do works, but its been a while since I did it, so
    I am very likely to have forgotten a few minor details. But try to think of something like
    a number of degrees of a circle that after appearing to cut it like a pizza, ends at 359
    or 1 degrees instead of 360 degrees, thus goes through all combinations after around
    360 / N revolutions.

    If we didn't figure that one out, at least there is the
    easy 64-pseudorandom-numbers morph technique.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-04 21:43
    Jay Kickliter said...
    And feel free to shame for abandoning it, I'll be laughing all the way to the Rockies.
    Good for you!!!

    I did that once: packed the car in Indiana to visit Glacier N.P. 'Ended up in the Canadian Rockies, then Alaska, Vancouver, Washington State, all the way down the Pacific coast to Tijuana and back home through Colorado. 15,000 miles total. (The next time I took a trip like that, I didn't return to the Midwest -- just stayed here in Washington State and haven't looked back.)

    Have a great trip! (And take an extra fuel pre-filter for the Benz. A clogged filter is about the only thing that could strand you with that car.)

    -Phil
  • Jay KickliterJay Kickliter Posts: 446
    edited 2010-05-09 18:09
    Still have some time in town, and didn't get any takers, so I replaced the USB connector and it didn't help. Guess I either messed up the design or damaged the FTDI chip.

    Phil, thanks for the fuel filter tip. Are you talking about the little inline filters? I'm actually thinking about making it as far as your neck of the woods. My previous shipping work has taken me to Port Townsend several times. I'm seriously considering moving there when I finish school; it's my favorite little town in the US.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-10 03:12
    Jay,

    Yes, the little clear plastic inline filter. It's there for a good reason, but it can be a show-stopper if you get bad fuel. 'Happened to me once shortly after I got my latest 240D. But the filters are cheap and a cinch to swap out.

    I hope you get to P.T. on your trip! Be sure to look me up if you do. It's a great place to visit and an even better place to live. Send me an email (address in my profile), and I'll provide additional contact info.

    -Phil
  • LawsonLawson Posts: 870
    edited 2010-05-10 17:16
    If you still need a pseudo random number generator I'd suggest looking at an XORshift RNG. I implemented one in a bit of assembly a while ago, super simple and wicked fast. (~9 lines of code, 2 variables, and no loops to get 32 pseudo-random bits) The PAPER describing how to make an XORshift RNG also shows how to make 64-bit or higher RNGs on a 32-bit system.

    Lawson

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lunch cures all problems! have you had lunch?
Sign In or Register to comment.