Exemple #1
0
void Pattern_spinner::activate(void *arg)
{
    g_x0 = 0;
    g_y0 = 0;

    g_x1 = flip_x(0);
    g_y1 = flip_y(0);

    display_current();
    m_last_move_ms = millis();
}
Exemple #2
0
bool Pattern_peak_spike::display()
{
#undef LOG_PEAKS
#ifdef LOG_PEAKS
    const int max_dots = 64;
    char dots[max_dots + 2];
    memset(dots, ' ', sizeof(dots));
    dots[max_dots] = '|';
    dots[max_dots + 1] = '\0';
    memset(dots, '.', get_mapped_peak(max_dots));
    Serial.printf("peak %5u %s\n", get_peak(), dots);
#endif

    Colour c = make_hue(g_hue.get());

    int leds = get_mapped_peak(LED_COUNT / 2);

#define FADE_PEAK
#ifdef FADE_PEAK
    static Value held_leds(0, 0, LED_COUNT / 2);
    held_leds.set_velocity(-10, 60);
    if (leds > held_leds.get()) {
	held_leds.set(leds);
    }
    leds = held_leds.get();
#endif

    // Start drawing out from the bottom middle both up and horizontally.
    int start_x = COLUMN_COUNT / 2;
    int start_y = ROW_COUNT - 1;
    int x = start_x;
    int y = start_y;
    for (int led = 0; led < leds; ++led) {
	draw_pixel(x, y, c);
	draw_pixel(flip_x(x), y, c);
	++x;
	++y;
	if (x >= COLUMN_COUNT || y >= ROW_COUNT) {
	    --start_y;
	    if (start_y < 0) {
		start_y = 0;
		++start_x;
	    }
	    x = start_x;
	    y = start_y;
	}
    }

    return true;
}
void resymmetrise(LifeList *cells) {

    if (!FLIP_X && !FLIP_Y)
        return;

    int i, n = cells->ncells;

    resizeIfNeeded(cells, 2 * n);

    for (i = 0; i < n; i++) {
        int pos = cells->cellList[i].position;
        if (FLIP_X) pos = flip_x(pos);
        if (FLIP_Y) pos = flip_y(pos);
        cells->cellList[i+n].position = pos;
        cells->cellList[i+n].value = cells->cellList[i].value;
    }

    cells->ncells = 2 * n;

    makeRowMajor(cells);
}
Exemple #4
0
void
APITests::testBasicOperations(int width, int height) {
  const PixelFormat format = PF_R8G8B8A8;
  const int bpp = 4;

  auto_ptr<Image> image(CreateImage(width, height, format));
  CPPUNIT_ASSERT(image->getWidth()  == width);
  CPPUNIT_ASSERT(image->getHeight() == height);
  CPPUNIT_ASSERT(image->getFormat() == format);

  // verify that the image is black
  byte* pixels = (byte*)image->getPixels();
  for (int i = 0; i < width * height * bpp; ++i) {
    CPPUNIT_ASSERT(pixels[i] == 0);
  }

  // fill the image with random pixels
  for (int i = 0; i < width * height * bpp; ++i) {
    pixels[i] = rand() % 256;
  }

  auto_ptr<Image> create_clone(
      CreateImage(image->getWidth(), image->getHeight(),
                  image->getFormat(), image->getPixels()));
  CPPUNIT_ASSERT(create_clone.get() != 0);
  CPPUNIT_ASSERT(image->getWidth()  == create_clone->getWidth());
  CPPUNIT_ASSERT(image->getHeight() == create_clone->getHeight());
  CPPUNIT_ASSERT(image->getFormat() == create_clone->getFormat());
  CPPUNIT_ASSERT(memcmp(image->getPixels(),
                        create_clone->getPixels(),
                        width * height * bpp) == 0);

  // clone the image (use same pixel format)
  auto_ptr<Image> identical_clone(CloneImage(image.get()));
  CPPUNIT_ASSERT(image->getWidth()  == identical_clone->getWidth());
  CPPUNIT_ASSERT(image->getHeight() == identical_clone->getHeight());
  CPPUNIT_ASSERT(image->getFormat() == identical_clone->getFormat());
  CPPUNIT_ASSERT(memcmp(image->getPixels(),
                        identical_clone->getPixels(),
                        width * height * bpp) == 0);

  // clone the image, removing the alpha channel
  auto_ptr<Image> other_clone(CloneImage(identical_clone.get(), PF_R8G8B8));
  CPPUNIT_ASSERT(image->getWidth()  == other_clone->getWidth());
  CPPUNIT_ASSERT(image->getHeight() == other_clone->getHeight());
  CPPUNIT_ASSERT(other_clone->getFormat() == PF_R8G8B8);
  byte* image_p = (byte*)image->getPixels();
  byte* other_p = (byte*)other_clone->getPixels();
  for (int i = 0; i < width * height; ++i) {
    CPPUNIT_ASSERT(*image_p++ == *other_p++);
    CPPUNIT_ASSERT(*image_p++ == *other_p++);
    CPPUNIT_ASSERT(*image_p++ == *other_p++);
    ++image_p;  // skip alpha
  }

  // flip the image
  // clone source first, since flip frees the original
  auto_ptr<Image> flip_none(FlipImage(CloneImage(image.get()), 0));
  auto_ptr<Image> flip_x   (FlipImage(CloneImage(image.get()), CA_X));
  auto_ptr<Image> flip_y   (FlipImage(CloneImage(image.get()), CA_Y));
  auto_ptr<Image> flip_xy  (FlipImage(CloneImage(image.get()), CA_X | CA_Y));

  AssertImagesEqual("No flipping", flip_none.get(), image.get());

  CPPUNIT_ASSERT(flip_x.get() != 0);
  CPPUNIT_ASSERT(width  == flip_x->getWidth());
  CPPUNIT_ASSERT(height == flip_x->getHeight());
  CPPUNIT_ASSERT(format == flip_x->getFormat());

  CPPUNIT_ASSERT(flip_y.get() != 0);
  CPPUNIT_ASSERT(width  == flip_y->getWidth());
  CPPUNIT_ASSERT(height == flip_y->getHeight());
  CPPUNIT_ASSERT(format == flip_y->getFormat());

  CPPUNIT_ASSERT(flip_xy.get() != 0);
  CPPUNIT_ASSERT(width  == flip_xy->getWidth()); 
  CPPUNIT_ASSERT(height == flip_xy->getHeight());
  CPPUNIT_ASSERT(format == flip_xy->getFormat());

  const byte* flip_x_pixels  = (const byte*)flip_x->getPixels();
  const byte* flip_y_pixels  = (const byte*)flip_y->getPixels();
  const byte* flip_xy_pixels = (const byte*)flip_xy->getPixels();

  for (int h = 0; h < height; h++) {
    for (int w = 0; w < width; w++) {
      const int image_index = (h * width + w) * bpp;
      const int opp_w = width  - 1 - w;
      const int opp_h = height - 1 - h;
      const int flip_x_index  = (opp_h * width + w) * bpp;
      const int flip_y_index  = (h * width + opp_w) * bpp;
      const int flip_xy_index = (opp_h * width + opp_w) * bpp;
      
      for (int p = 0; p < bpp; p++) {
        CPPUNIT_ASSERT(pixels[image_index] == flip_x_pixels [flip_x_index]);
        CPPUNIT_ASSERT(pixels[image_index] == flip_y_pixels [flip_y_index]);
        CPPUNIT_ASSERT(pixels[image_index] == flip_xy_pixels[flip_xy_index]);
      }
    }
  }

}