Permalink
Browse files

Rough stab at getting frame output working.

  • Loading branch information...
cibomahto committed Feb 23, 2011
1 parent 5857819 commit 27f9e9c60f6b0d080448711a7aa78ba755b9fdfa
Showing with 87 additions and 40 deletions.
  1. +60 −15 AnimationLoader.pde
  2. +12 −4 PeggyDraw2.pde
  3. +14 −19 data/PeggyFooter.txt
  4. +1 −2 data/PeggyHeader.txt
View
@@ -39,20 +39,19 @@
class AnimationLoader
{
- /*
String[] header;
- String[] RowData;
String[] footer;
+ /*
+ String[] RowData;
+
String[] FileOutput;
String[] OneRow;
*/
AnimationLoader() {
-
- /*
+ // Load any constant strings here
header = loadStrings("PeggyHeader.txt");
footer = loadStrings("PeggyFooter.txt");
- */
}
@@ -89,25 +88,71 @@ class AnimationLoader
}
void SaveAnimation(String filename, AnimationFrames animation) {
+ // File object to write to
+ PrintWriter output;
+
println("Saving animation to: " + filename);
+ // Open the file for writing
+ output = createWriter(filename);
+
+ // First, write the header to the file
+ for (String line : header) {
+ output.println(line);
+ }
+
+ // Maybe write out the number of frames here?
+ output.println("unsigned int frameCount=" + animation.getFrameCount() + ";");
- // For each frame
- for (int i = 0; i < animation.getFrameCount(); i++) {
- println("Frame: " + i);
+ // Write out a definition for a big 2d array of frames
+ output.println("unsigned long frames[" + animation.getFrameCount() + "][25]={");
+
+ // Now, for each frame, write it's data as an array of longs.
+ for (int frameNo = 0; frameNo < animation.getFrameCount(); frameNo++) {
+ output.print("{");
// Load the frame data
- int data[] = animation.getFrame(i).getFrameData();
+ int data[] = animation.getFrame(frameNo).getFrameData();
- // Handle the frame data
- for (int j = 0; j < data.length; j++) {
- print(data[j] > 0 ?"o":" ");
+ // Make sure our frame is of the correct size
+ if (rows*cols != data.length) {
+ print("Error! Data size isn't right!");
+ return;
+ }
+
+ // Handle the frame data, row by row.
+ for (int i = 0; i < rows; i++) {
+ long rowData = 0;
- if ((j + 1) % cols == 0) {
- print("\n");
+ for (int j = 0; j < cols; j++) {
+ if (data[i*cols + j] > 0)
+ {
+ rowData += (1 << j);
+ }
}
+
+ output.print(rowData + ",");
}
- print("\n");
+ output.print("},\n");
+ }
+
+ // close the array
+ output.println("};");
+
+ // Write out the durations to display each frame
+ output.print("unsigned long frameDurations[] = {");
+ for (int frameNo = 0; frameNo < animation.getFrameCount(); frameNo++) {
+ output.print(animation.getFrame(frameNo).getDuration() + ",");
}
+ output.print("};");
+
+ // Now, write the footer to the file
+ for (String line : footer) {
+ output.println(line);
+ }
+
+ // Finally, make sure the file data is written and close the file.
+ output.flush();
+ output.close();
}
}
View
@@ -100,8 +100,7 @@ void setup() {
colorMode(RGB, 15); // Max value of R, G, B = 15.
ellipseMode(CORNER);
-
-
+
strokeWeight(1);
stroke(2); // Set color: Gray outline for LED locations.
@@ -450,8 +449,17 @@ void mousePressed() {
frames = newAnimation;
}
else if( saveButton.isSelected() ) {
- loader.SaveAnimation("demo_save", frames);
- // TODO: Save out the data!
+ // Write to a new file in the PeggyProgram directory, using the current date and time for a name
+
+ // First off, if the PeggyProgram directory doesn't exist, create it!
+ File outputDir = new File(sketchPath, "PeggyProgram");
+ if (!outputDir.exists())
+ outputDir.mkdirs();
+
+ // Make a filename
+ String fileName = "Animation " + year() + "-" + month() + "-" + day() + "_" + hour() + ":" + minute();
+ // Now, call the loader object to actually save the animation.
+ loader.SaveAnimation("PeggyProgram/" + fileName, frames);
}
else if( playButton.isSelected() ) {
if (playing) {
View
@@ -1,30 +1,25 @@
-};
-
-
void setup() // run once, when the sketch starts
{
- frame1.HardwareInit(); // Call this once to init the hardware.
+ frame.HardwareInit(); // Call this once to init the hardware.
// (Only needed once, even if you've got lots of frames.)
+}
- unsigned short y = 0;
+long currentFrame = 0;
+void loop() // run over and over again
+{
+ unsigned short y = 0;
while (y < 25) {
-
-
- frame1.WriteRow( y, data1[y]);
-
+ frame.WriteRow( y, frames[currentFrame][y]);
y++;
-
}
+ // Note: Not sure how long this translates to!
+ frame.RefreshAll(frameDurations[currentFrame]); //Draw frame buffer n times
-} // End void setup()
-
-
-void loop() // run over and over again
-{
-
- frame1.RefreshAll(10); //Draw frame buffer 10 times
-
-}
+ currentFrame += 1;
+ if (currentFrame >= frameCount) {
+ currentFrame = 0;
+ }
+}
View
@@ -23,6 +23,5 @@
#include <math.h>
#include <stdlib.h>
-Peggy2 frame1; // Make a frame buffer object, called frame1
+Peggy2 frame; // Make a frame buffer object, called frame
-unsigned long data1[25] = {

0 comments on commit 27f9e9c

Please sign in to comment.