예제 #1
0
        public void Animate(IEnumerable<Frame> frames)
        {
            var palette = new Palette(frames);
            var encodedFrames = frames.Select(f => new { Data = f.Encode(palette), Duration = f.Duration });

            int size = palette.Data.Length + encodedFrames.Sum(f => f.Data.Length);
            Console.WriteLine("Uploading animation of {0} frame(s) ({1} bytes)", frames.Count(), size);

            WriteNewAnimation();
            WritePalette(palette);
            foreach (var frame in encodedFrames)
            {
                WriteNewFrame(frame.Duration);
                WriteFrameData(frame.Data);
            }
            WriteStartAnimation();
        }
예제 #2
0
파일: Frame.cs 프로젝트: foobert/Colorduino
 public byte[] Encode(Palette palette)
 {
     return RLE(palette.EncodeFrame(this));
 }
예제 #3
0
 private void WritePalette(Palette palette)
 {
     int offset = 0;
     while (offset < palette.Data.Length)
     {
         byte todo = (byte)Math.Min(30, palette.Data.Length - offset);
         byte[] buffer = new byte[todo + 1];
         buffer[0] = CMD_APPEND_PALETTE;
         Array.Copy(palette.Data, offset, buffer, 1, todo);
         offset += todo;
         Write (buffer);
     }
 }