Monday 1 May 2017

What if existence of suffering is necessary for consciousness to exist?

Fractals on Arduino Nano with fixed-point arithmetic today...

These small 128x64 monochrome OLED displays were 3.2 euros from ebay.

Serial output from the board as seen by minicom in linux.
Scientific knowledge is that which is useful for making predictions, everything else is just something else.
This 16 MHz board costs 2.2 euros in ebay.
/* avr-gcc -Os mandelbrot.c -mmcu=atmega328p -o program.elf
 * avr-objcopy -O ihex -R .eeprom program.elf program.hex
 * avrdude -c arduino -b 57600 -P /dev/ttyUSB0 -p atmega328p -vv -U flash:w:program.hex
 * (apt-get install avrdude gcc-avr avr-libc)
 */

#define F_CPU 16000000UL
#define BAUD 115200

#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include <util/setbaud.h>

putch(char a) {
  loop_until_bit_is_set(UCSR0A, UDRE0);
  UDR0 = a;
}

int main() {
  int x, y, n, F = 1e3;
  long x0, x1, x2, y0, y1, y2;

  UCSR0A |= _BV(U2X0);
  while(1) {
    for(y=0; y<23; y++) {
      for(x=0; x<80; x++) { 
        x0 = F*6*x/80 - 7*F/2;
  y0 = F*6*y/23 - 3*F;
  x1 = 0;
  y1 = 0;
  n = 0;
  while(sqrt(x1*x1+y1*y1) < F*8 && ++n < 64) {
          x2 = x1*x1/F - y1*y1/F;
          y2 = 2*x1*y1/F;
          x1 = x2 + x0;
          y1 = y2 + y0;
  }
        putch(32+n);
      }
      putch('\r');
      putch('\n');
    }
    putch(27);
    putch('[');
    putch('H');
  }
}


With the OLED display...


int mandelbrot(long xx, long yy) {
  long x0, y0, x1, y1, x2, y2;
  int n, F = 1000;
  
  x0 = F*3*xx/128 - 7*F/2;
  y0 = F*3*yy/64 - 3*F/2;
  x1 = 0;
  y1 = 0;
  n = 0;
  while(sqrt(x1*x1+y1*y1) < F*8 && ++n < 11) {
    x2 = x1*x1/F - y1*y1/F;
    y2 = 2*x1*y1/F;
    x1 = x2 + x0;
    y1 = y2 + y0;
  }
  return n;
}

void loop() {
  unsigned char x, y, z, c;
  int xx, yy;

  for(y=0; y<8; y++) {
    LED_WrCmd(0xb0+y);
    LED_WrCmd(0x00);
    LED_WrCmd(0x10);
    xx = 0;
    for(xx=0; xx<256; xx++) {
      z = 1;
      c = 0;
      for(x=0; x<8; x++) {
        yy = x+y*8;
        if(mandelbrot(xx, yy)>10)
          c = c + z;
        z = 2*z;

      }
      LED_WrDat(c);
      xx++;
    }
  }

}

No comments:

Post a Comment