Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helping hand starting with animation
#1
All,
So here is where I admit that use Python as a functional language, and struggle with Object Oriented languages.

I have been writing animations for my LPD8806 strips for a while now and have switched to using AllPixel.

- BUT -

I am still driving the pixels and animations in my own code, not using the anim() routines.

Where I am stuck is that my capabilities for OO programming are causing me to hit a wall and the fantastic samples out there, while impressive are not the easiest thing for me to learn from.

While I don't need anyone to tutor me in OO programming, I just need a really simple example to build off.

Does ANYONE have a SIMPLE animation sample that I can clone that does something super simple like a single LED chaser or similar?

Once I can get started and figure this out, I have some animations that I quite like that I would like to contribute back to the library...

Cheers.

snrkl.
#2
Without adding a lesson in OO, this would be the simplest example of writing an animation class I can point you to:

https://github.com/ManiacalLabs/BiblioPixel/wiki/Writing-an-Animation

But, if you post the code for one example of something you are trying to convert into an animation (please provide your entire script) I'd be happy to walk you through it.
#3
Heres what I have been using to date:


Code:
#!/usr/bin/env python

"""
A flame routine - perfect to set your LED matrix into a warm and toasty mood...
An algorithm as old as the hills (and demo coders)
snrkl_AT_snrkl_DOT_org
"""

def debugLog(message):
   """
   Function that prints to stdout if debug == 1
   message: Message to Print
   returns:    NULL
   """
   if debug == 1:
       print("Debug: " + str(message))

debug = 1

#!/usr/bin/env python

import sys
import time
import random
import numpy

sys.path.append('/usr/local/lib/python2.7/site-packages/')

from bibliopixel.led import *
from bibliopixel.animation import *
#from bibliopixel.drivers.LPD8806 import *
from bibliopixel.drivers.visualizer import *
import bibliopixel.image as image

#create driver for a 8x8 grid, use the size of your display
#driver = DriverLPD8806(8*8,c_order = ChannelOrder.GRB)
#led = LEDMatrix(driver,serpentine = 0,rotation = MatrixRotation.ROTATE_0, vert_flip = True)

myHeight = 64
myWidth = 64
   
driver = DriverVisualizer(width=myWidth, height=myHeight, pixelSize=10)
led = LEDMatrix(driver)

# uncomment to run calibration test
#anim = MatrixCalibrationTest(led)
#anim.run()


try:
   # reset screen to black
   led.fillScreen((0,0,0))
   
   
   while True:
       y = myHeight -1
       for x in range(myWidth):
           ## Option 1: Generate some flamey colours in a weighted random fashion
           randomRed = random.randint(128,255)
           randomGreen = random.randint(0,128)
           randomBlue = random.randint(0,128)
           #debugLog("RBG: " + str(randomRed) + "," + str(randomGreen) + "," + str(randomBlue))
           led.set(x,y,(randomRed,randomGreen,randomBlue))
           
           
           ## Option 2: lets pre-stack the deck with some flamey colours
           #red = (255,0,0)
           #yellow = (255,255,0)
           #orange = (255,128,0)
           #white = (255,255,255)
           #black = (0,0,0)
           #palette = [red,red,red,yellow,yellow,yellow,orange,orange,orange,white]        
           #led.set(x,y,(palette[random.randint(0,len(palette)-1)]))
           #led.update()
 
       #iterate through the matrix, and crunch pixels
       for y in range(myHeight -1):
           for x in range(myWidth):
               #debugLog("xy is: " + str(x) + "," + str(y))
               inputPixel = [0,0,0]
               inputPixel[0] = led.get(x-1,y+1)
               inputPixel[1] = led.get(x,y+1)
               inputPixel[2] = led.get(x+1,y+1)
               #debugLog(str(inputPixel[0]))
               #debugLog(str(inputPixel[1]))
               #debugLog(str(inputPixel[2]))
               
               r = [inputPixel[0][0],inputPixel[1][0],inputPixel[2][0]]
               g = [inputPixel[0][1],inputPixel[1][1],inputPixel[2][1]]
               b = [inputPixel[0][2],inputPixel[1][2],inputPixel[2][2]]
               
               outputPixel = [0,0,0]
               
               #decay = 1.5
               decay = random.uniform(1.0,1.2)
               outputPixel[0] = int(numpy.mean(r)/decay)
               outputPixel[1] = int(numpy.mean(g)/decay)
               outputPixel[2] = int(numpy.mean(b)/decay)
               
               #debugLog(str(outputPixel))
               led.set(x,y,[outputPixel[0],outputPixel[1],outputPixel[2]])
               #led.update()
               #raw_input("...")
       
       led.update()
       #time.sleep(0.1)
   
except KeyboardInterrupt:
   sys.exit()

(10-03-2016, 08:06 AM)Adam Wrote: Without adding a lesson in OO, this would be the simplest example of writing an animation class I can point you to:

https://github.com/ManiacalLabs/BiblioPixel/wiki/Writing-an-Animation

But, if you post the code for one example of something you are trying to convert into an animation (please provide your entire script) I'd be happy to walk you through it.

Let me try working through the wiki example again - most of my OO hassles, I feel, are namespace related and just not knowing how to reference objects and functions under them correctly...
#4
@adam: do you have the simple animation examples from the wiki as a full python script? I think this would make it MUCH easier to reverse engineer and learn how to do this properly..


Forum Jump:


Users browsing this thread: 1 Guest(s)