Mira-Gumowski Fractal nice colour example
/* Mira Gumowski Fractal v1.0 */
inline void digitalWriteDirect(int pin, boolean val){
if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
else g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}
volatile short line;
byte fb[240][320];
#define do20(x) x x x x x x x x x x x x x x x x x x x x
#define do80(x) do20(x) do20(x) do20(x) do20(x)
#define do320(x) do80(x) do80(x) do80(x) do80(x)
#define MNOP(x) asm volatile (" .rept " #x "\n\t nop \n\t .endr \n\t")
void TC0_Handler()
{
long dummy=REG_TC0_SR0;
if(line < 480){
byte * p=fb[line>>1];
MNOP(160);
do320(REG_PIOD_ODSR = *p++;MNOP(2);)
REG_PIOD_ODSR = 0;
}
if(line==490) digitalWriteDirect(3,1); //or digitalWriteDirect(3,0); to invert vsync
if(line==492) digitalWriteDirect(3,0); //or digitalWriteDirect(3,1); to invert vsync
line++; if(line == 525) line=0;
}
void setup(){
pinMode(3,OUTPUT); pinMode(2,OUTPUT); // vsync=3 hsync=2
pinMode(25,OUTPUT); pinMode(26,OUTPUT); // blue (26=msb,25=lsb)
pinMode(27,OUTPUT); pinMode(28,OUTPUT); pinMode(14,OUTPUT); // green (14=msb,28,27=lsb)
pinMode(15,OUTPUT); pinMode(29,OUTPUT); pinMode(11,OUTPUT); // red (11=msb,29,15=lsb)
REG_PIOD_OWER= 0xff;
REG_PMC_PCER0= 1<<27;
REG_PIOB_PDR = 1<<25;
REG_PIOB_ABSR= 1<<25;
REG_TC0_WPMR = 0x54494D00;
REG_TC0_CMR0 = 0b00000000000010011100010000000000;
// REG_TC0_CMR0 = 0b00000000000001101100010000000000; // this inverts hsync
REG_TC0_RC0 = 1334;
REG_TC0_RA0 = 1174;
REG_TC0_CCR0 = 0b101;
REG_TC0_IER0 = 0b00010000;
REG_TC0_IDR0 = 0b11101111;
NVIC_EnableIRQ(TC0_IRQn);
}
float a = -0.6624;
float c = 2*(1-a);
float x = 14.7176;
float y = -14.6602;
float f = 0;
int xx,yy;
int cnt = 0;
int col = 255;
void loop(){
double oldx = x;
x = f+1*y;
f = a*x+c*x*x/(1+x*x);
y = f-oldx;
xx = 160+3*x;
yy = 120+4*y;
if (cnt == 2000) {
col = rand();
cnt = 0; }
cnt++;
if ((xx>=0)&(xx<=319)&(yy>=0)&(yy<=239)) {
fb[yy][xx]=col; }
}