Skip to content

Instantly share code, notes, and snippets.

@epsimatic
Last active April 13, 2019 15:36
Show Gist options
  • Save epsimatic/4394a321fc2591acd9835cd03f57c734 to your computer and use it in GitHub Desktop.
Save epsimatic/4394a321fc2591acd9835cd03f57c734 to your computer and use it in GitHub Desktop.
Mouser
// This is an Arduino code for Digispark attiny board
#include <DigiMouse.h>
void setup() {
DigiMouse.begin();
randomSeed(analogRead(0));
}
void loop() {
double hours = double(millis()) / 1000.0 / 7200.0;
double insanity = min(hours/2, 1.0); // 2 hours until full insanity
insanity = insanity * insanity * insanity * insanity * insanity * insanity;
move (
random(1+insanity*50, 2+insanity*400),
float(random(PI*2*1000))/1000,
random(1+insanity*30, 2+insanity*48)
);
DigiMouse.delay(100000 * (1.0001-insanity));
}
void move(float distance, float angle, float spd) {
float x_total = distance * cos(angle);
float y_total = distance * sin(angle);
int steps = 100;
int x_accumulated = 0;
int y_accumulated = 0;
for (int i = 0; i<=steps; i++) {
float x_desired = x_total / steps * i;
float y_desired = y_total / steps * i;
int x_delta = x_desired - x_accumulated;
int y_delta = y_desired - y_accumulated;
x_accumulated += x_delta;
y_accumulated += y_delta;
DigiMouse.move(x_delta, y_delta, 0);
DigiMouse.delay(steps/spd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment