Author Topic: [Prizm C] Mandelbrot Set  (Read 10024 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
[Prizm C] Mandelbrot Set
« on: July 01, 2013, 11:34:31 am »
This is my first working Prizm C program and it is much faster and prettier than my BASIC version. As the title implies, this draws the Mandelbrot set and currently does not do much. You have to wait for it to draw the whole thing and it isn't very fast (it takes about 1 minute 15 seconds to render), but once it is done it looks cool:

Press [MENU] to exit.

I really don't suggest downloading it since all it amounts to is what you see in the still screenshot. My plan is to make an explorer and see if I can possibly make it faster, but I thought I would share with anybody that is curious. Also, the code:
Code: [Select]
#include <fxcg/display.h>
#include <fxcg/keyboard.h>
void plot(int x0, int y0, int color) {
   char* VRAM = (char*)0xA8000000;
   VRAM += 2*(y0*LCD_WIDTH_PX + x0);
   *(VRAM++) = (color&0x0000FF00)>>8;
   *(VRAM++) = (color&0x000000FF);
   return;
}
int main() {
  Bdisp_AllCr_VRAM();
  Bdisp_EnableColor(1);
  double CxMin=-2.0;
  double CyMax=1.5;
  double delta=3.0/192;
  double Zy2,Zx2,Zy,Zx,Cx,Cy;
  int x,y,iter,a,itermax=50;
  Cx=CxMin;
  for(x=0;x<384;x++)
  {
    Cy=CyMax;
    for(y=0;y<192;y++)
    {
      Zx=Cx;
      Zy=Cy;
      Zx2=Cx*Cx;
      Zy2=Cy*Cy;
      for(iter=0;iter<itermax && ((Zx2+Zy2)<=4);iter++)
      {
        Zy=2*Zx*Zy +Cy;
        Zx=Zx2-Zy2 +Cx;
        Zx2=Zx*Zx;
        Zy2=Zy*Zy;
      }
      a=iter-itermax;
      a=2048*(a%32) + 32*(a % 64) + (a % 32);
      plot(x,y+32,a);
      Cy-=delta;
    }
  Cx+=delta;
  Bdisp_PutDisp_DD();
  }

  int key;
  while(1)
  GetKey(&key);
  return 0;
}

I also have no Icon made yet x.x

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Prizm C] Mandelbrot Set
« Reply #1 on: July 03, 2013, 11:23:59 pm »
I like it so far. :D Do you plan to get more into PRIZM dev in the near future such as porting some games you made? :D

*cough*cgGrammer*cough*

Offline mlytle0

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 12
  • Rating: +2/-0
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #2 on: July 04, 2013, 12:32:32 am »
Very Cool!

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #3 on: July 04, 2013, 01:09:58 am »
*cough*84C*cough*
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: [Prizm C] Mandelbrot Set
« Reply #4 on: July 04, 2013, 05:13:35 am »
Ui, this is looking nice!
And I also go with tr1p's opinion :P

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #5 on: July 04, 2013, 06:38:05 am »
I don't have an 84C yet, but I have been thinking about writing a language similar to Grammer for the Prizm :) I make no promises, though :P

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Prizm C] Mandelbrot Set
« Reply #6 on: July 04, 2013, 09:44:40 am »
84C would definitively be much slower, though (although you could do like tr1p1ea and only use half of the screen in stretched mode), since it's 15 MHz, while the PRIZM can go up to 94.3 MHz using Overclui.

Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: [Prizm C] Mandelbrot Set
« Reply #7 on: July 28, 2013, 01:08:52 pm »
I did this in LuaZM once... was very slow. How fast does yours render?



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #8 on: July 28, 2013, 01:16:17 pm »
It took 46 seconds at 94.3MHz, but about 75 seconds at normal speed.

Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: [Prizm C] Mandelbrot Set
« Reply #9 on: July 28, 2013, 01:18:19 pm »
It took 46 seconds at 94.3MHz, but about 75 seconds at normal speed.

Not bad. My (unoptimized, messily coded, first attempt) LuaZM Mandelbrot generator took about a minute to make a very low-res set. The "pixels" were 4x4px :P

Good learning experience though.


EDIT:
http://www.cemetech.net/forum/viewtopic.php?t=8917&start=0
« Last Edit: July 28, 2013, 01:19:25 pm by flyingfisch »



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: [Prizm C] Mandelbrot Set
« Reply #10 on: July 28, 2013, 01:58:29 pm »
Eh, this reminds me of :



:P
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #11 on: July 28, 2013, 10:36:27 pm »
Oh my gosh, I totally want to learn enough ARM assembly to do that on my NSpire o.o

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Prizm C] Mandelbrot Set
« Reply #12 on: July 28, 2013, 10:52:59 pm »
I am curious about how fast this would be in computer Lua on a 150 MHz computer with 64 MB of RAM compared to the Lua TI gave us.

Offline ProgrammerNerd

  • LV3 Member (Next: 100)
  • ***
  • Posts: 50
  • Rating: +9/-2
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #13 on: September 22, 2013, 10:03:22 am »
This topic reminded me of a program that I wrote awhile ago for the casio prizm. It takes less than a second in my program to do a mandelbrot. I actully wrote it about 6 months ago maybe more don't remeber. I did not spend too much time on it so there is much work needed to be done. I am working on improving it right now.
Here is a video

And the source code.
Code: [Select]
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <keyboard.hpp>
#include <color.h>
#include <display.h>//display is 384x216
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef int fixed_t;
static fixed_t divX;
static fixed_t addX;
static fixed_t divY;
static fixed_t addY;
static fixed_t stepX;
static fixed_t stepY;
#define preMan 13
static fixed_t scaleM[4] = {-2<<preMan,1<<preMan,-1<<preMan,1<<preMan};
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
unsigned short lastkey[8];
unsigned short holdkey[8];
void keyupdate(void) {
memcpy(holdkey, lastkey, sizeof(unsigned short)*8);
memcpy(lastkey, keyboard_register, sizeof(unsigned short)*8);
}
int keydownlast(int basic_keycode){
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (lastkey[word] & 1<<bit));
}
int keydownhold(int basic_keycode){
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (holdkey[word] & 1<<bit));
}
inline fixed_t abs(fixed_t val){
if (val < 0)
val*=-1;
return val;
}
inline void plotMan(fixed_t x,fixed_t y,uint16_t col){
uint16_t * vramAd=(uint16_t *)0xA8000000;
x+=addX;
x=x*384/divX;
y+=addY;
y=y*216/divY;
vramAd+=(y*384)+x;
*vramAd=col;
}
inline fixed_t square(fixed_t x){
return x*x;
}
void setScale(fixed_t * scale){//format minx maxx miny maxy
divX=abs(scale[0]-scale[1]);
divY=abs(scale[2]-scale[3]);
addX=scale[0]*-1;
addY=scale[2]*-1;
stepX=divX/384;
stepY=divY/216;
}
uint16_t ManIt(fixed_t c_r,fixed_t c_i,uint16_t maxit){//manIt stands for mandelbrot iteration what did you think it stood for?
//c_r = scaled x coordinate of pixel (must be scaled to lie somewhere in the mandelbrot X scale (-2.5, 1)
//c_i = scaled y coordinate of pixel (must be scaled to lie somewhere in the mandelbrot Y scale (-1, 1)
// squre optimaztion code below orgionally from http://randomascii.wordpress.com/2011/08/13/faster-fractals-through-algebra/
//early bailout code from http://locklessinc.com/articles/mandelbrot/
//changed by me to use fixed point math
fixed_t ckr,cki;
unsigned p=0,ptot=8;
fixed_t z_r = c_r;
fixed_t z_i = c_i;
fixed_t zrsqr = (z_r * z_r)>>preMan;
fixed_t zisqr = (z_i * z_i)>>preMan;
//int zrsqr,zisqr;
do{
ckr = z_r;
cki = z_i;
ptot += ptot;
if (ptot > maxit) ptot = maxit;
for (; p < ptot;++p){
z_i =(square(z_r+z_i)>>preMan)-zrsqr-zisqr;
z_i += c_i;
z_r = zrsqr-zisqr+c_r;
zrsqr = (z_r*z_r)>>preMan;
zisqr = (z_i*z_i)>>preMan;
if ((zrsqr + zisqr) > (4<<preMan))
return p*0xFFFF/maxit;
if ((z_r == ckr) && (z_i == cki))
return 0xFFFF;
}
} while (ptot != maxit);
//plotMan(x0,y0,(uint32_t)iteration*(uint32_t)0xFFFF/(uint32_t)maxit);
//return (uint32_t)p*(uint32_t)0xFFFF/(uint32_t)maxit;
return 0xFFFF;
}
void mandel(uint16_t maxit){
fixed_t x,y;
uint16_t xx;
uint16_t * vramAd=(uint16_t *)0xA8000000;
for (y=scaleM[2];y<scaleM[3];y+=stepY){
xx=0;
for (x=scaleM[0];x<scaleM[1];x+=stepX){
if (xx > 400)
return;
*vramAd++=ManIt(x,y,maxit);
xx++;
}
vramAd+=384-xx;
}
Bdisp_PutDisp_DD();
}
void mandel4(uint16_t maxit){
static uint16_t temp[100];
fixed_t x,y;
uint16_t xx;
uint8_t yy,z;
uint16_t * vramAd=(uint16_t *)0xA8000000;
for (y=scaleM[2];y<scaleM[3];y+=stepY*4){
xx=0;
for (x=scaleM[0];x<scaleM[1];x+=stepX*4){
if (xx > 96)
return;
temp[xx]=ManIt(x,y,maxit);
xx++;
}
for (yy=0;yy<4;++yy){
for (x=0;x<96;++x){
*vramAd++=temp[x];
*vramAd++=temp[x];
*vramAd++=temp[x];
*vramAd++=temp[x];
}
}
// vramAd+=384-xx;
// vramAd+=384*15;
}
Bdisp_PutDisp_DD();
}
/*int PRGM_GetKey(void)
{
  unsigned char buffer[12];
  PRGM_GetKey_OS( buffer );
  return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}*/
void main(void) {
Bdisp_EnableColor(1);
Bdisp_AllClr_VRAM();
setScale(scaleM);
uint16_t z=31;
mandel(z);
uint8_t redraw=1;
//uint16_t z=28;//good values for z 28 31 36 41 42 31 is my favoirte so far
do{
keyupdate();
if (keydownlast(KEY_PRGM_F1) && keydownhold(KEY_PRGM_F1)){
z=0xFFFF;
redraw=2;
}
if (keydownlast(KEY_PRGM_F2) && keydownhold(KEY_PRGM_F2)){
z=31;
redraw=2;
}
if (keydownlast(KEY_PRGM_1) && keydownhold(KEY_PRGM_1)){
z--;
redraw=2;
}
if (keydownlast(KEY_PRGM_2) && keydownhold(KEY_PRGM_2)){
z++;
redraw=2;
}
if (keydownlast(KEY_PRGM_SHIFT) && keydownhold(KEY_PRGM_SHIFT)){
scaleM[0]+=256;
scaleM[1]-=256;
scaleM[2]+=144;
scaleM[3]-=144;
setScale(scaleM);
redraw=2;
}
if (keydownlast(KEY_PRGM_ALPHA) && keydownhold(KEY_PRGM_ALPHA)){
scaleM[0]-=256;
scaleM[1]+=256;
scaleM[2]-=144;
scaleM[3]+=144;
setScale(scaleM);
redraw=2;
}
if (keydownlast(KEY_PRGM_UP) && keydownhold(KEY_PRGM_UP)){
scaleM[2]-=144;
scaleM[3]-=144;
setScale(scaleM);
redraw=2;
}
if (keydownlast(KEY_PRGM_DOWN) && keydownhold(KEY_PRGM_DOWN))
{
scaleM[2]+=144;
scaleM[3]+=144;
setScale(scaleM);
redraw=2;
}
if (keydownlast(KEY_PRGM_LEFT) && keydownhold(KEY_PRGM_LEFT)){
scaleM[0]-=256;
scaleM[1]-=256;
setScale(scaleM);
redraw=2;
}
if (keydownlast(KEY_PRGM_RIGHT) && keydownhold(KEY_PRGM_RIGHT)){
scaleM[0]+=256;
scaleM[1]+=256;
setScale(scaleM);
redraw=2;
}
if (redraw == 1){
mandel(z);
redraw=0;
}
else if (redraw == 2){
mandel4(z);
redraw=1;
}
} while (!(keydownlast(KEY_PRGM_EXIT) && keydownhold(KEY_PRGM_EXIT)));
//MsgBoxPop();
return;
}
« Last Edit: September 22, 2013, 10:08:27 am by ProgrammerNerd »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [Prizm C] Mandelbrot Set
« Reply #14 on: September 23, 2013, 02:55:18 pm »
Wow, that looks wonderful! That is pretty similar to the explorer I made in Axe for the TI-84+ calcs (except that scrolling didn't make the image fuzzy). When zooming in, it would zoom in x2 by scaling up the image first and then redraw the image with better accuracy while the user wasn't doing anything.

:thumbsup: