<commit_before>#include <math.h>
#include <stdio.h>

#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "displaybuffer.h"
#include "displaydriver.h"
#include "mode-bounce.h"

const static char *LOG_TAG = "mode-bounce";

static displaybuffer_t buffer_bounce;

ModeBounceParameters mode_bounce_params;

int mode_bounce_draw() {
  buffer_wipe(&buffer_draw);
  buffer_draw_pixel(mode_bounce_params.pos.x, mode_bounce_params.pos.y, PIXEL_YELLOW, &buffer_draw);

  mode_bounce_params.pos.x += mode_bounce_params.rate.x;
  mode_bounce_params.pos.y += mode_bounce_params.rate.y;

  if (mode_bounce_params.pos.x <= 0) {
    mode_bounce_params.pos.x = 0;
    mode_bounce_params.rate.x = -mode_bounce_params.rate.x;
  } else if (mode_bounce_params.pos.x >= DISPLAY_WIDTH - 1) {
    mode_bounce_params.pos.x = DISPLAY_WIDTH - 1;
    mode_bounce_params.rate.x = -mode_bounce_params.rate.x;
  }

  if (mode_bounce_params.pos.y <= 0) {
    mode_bounce_params.pos.y = 0;
    mode_bounce_params.rate.y = -mode_bounce_params.rate.y;
  } else if (mode_bounce_params.pos.y >= DISPLAY_HEIGHT - 1) {
    mode_bounce_params.pos.y = DISPLAY_HEIGHT - 1;
    mode_bounce_params.rate.y = -mode_bounce_params.rate.y;
  }

  buffer_commit_drawing();
  
  return BOUNCE_TIME_DELAY_BETWEEN_DRAWS_MS;
}

void mode_bounce_setup() {
  mode_bounce_params.pos.x = esp_random() % DISPLAY_WIDTH;
  mode_bounce_params.pos.y = esp_random() % DISPLAY_HEIGHT;
  mode_bounce_params.rate.x = 0.5 + (((esp_random() % 50)+1) / (double)100);
  mode_bounce_params.rate.y = 0.5 + (((esp_random() % 50)+1) / (double)100);
}
<commit_msg>Change from bouncing pixel to circle.<commit_after>#include <math.h>
#include <stdio.h>

#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "displaybuffer.h"
#include "displaydriver.h"
#include "mode-bounce.h"

#define MODE_BOUNCE_RADIUS 2

const static char *LOG_TAG = "mode-bounce";

static displaybuffer_t buffer_bounce;

ModeBounceParameters mode_bounce_params;

int mode_bounce_draw() {
  buffer_wipe(&buffer_draw);
  buffer_fill_circle(
      mode_bounce_params.pos.x, mode_bounce_params.pos.y, MODE_BOUNCE_RADIUS,
      PIXEL_YELLOW, &buffer_draw);

  mode_bounce_params.pos.x += mode_bounce_params.rate.x;
  mode_bounce_params.pos.y += mode_bounce_params.rate.y;

  if (mode_bounce_params.pos.x <= MODE_BOUNCE_RADIUS) {
    mode_bounce_params.pos.x = MODE_BOUNCE_RADIUS;
    mode_bounce_params.rate.x = -mode_bounce_params.rate.x;
  } else if (mode_bounce_params.pos.x >= DISPLAY_WIDTH - 1 - MODE_BOUNCE_RADIUS) {
    mode_bounce_params.pos.x = DISPLAY_WIDTH - 1 - MODE_BOUNCE_RADIUS;
    mode_bounce_params.rate.x = -mode_bounce_params.rate.x;
  }

  if (mode_bounce_params.pos.y <= MODE_BOUNCE_RADIUS) {
    mode_bounce_params.pos.y = MODE_BOUNCE_RADIUS;
    mode_bounce_params.rate.y = -mode_bounce_params.rate.y;
  } else if (mode_bounce_params.pos.y >= DISPLAY_HEIGHT - 1 - MODE_BOUNCE_RADIUS) {
    mode_bounce_params.pos.y = DISPLAY_HEIGHT - 1 - MODE_BOUNCE_RADIUS;
    mode_bounce_params.rate.y = -mode_bounce_params.rate.y;
  }

  buffer_commit_drawing();
  
  return BOUNCE_TIME_DELAY_BETWEEN_DRAWS_MS;
}

void mode_bounce_setup() {
  mode_bounce_params.pos.x = esp_random() % DISPLAY_WIDTH;
  mode_bounce_params.pos.y = esp_random() % DISPLAY_HEIGHT;
  mode_bounce_params.rate.x = 0.5 + (((esp_random() % 50)+1) / (double)100);
  mode_bounce_params.rate.y = 0.5 + (((esp_random() % 50)+1) / (double)100);
}

{'fraction_non_alphanumeric': 0.1275802752293578, 'fraction_numerical': 0.012901376146788992, 'mean_word_length': 4.673170731707317, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '872942', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1455, 'n_words': 198}