September 10, 2010, 07:36:30 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: New members: I'm testing a different CAPTCHA system that hopefully is less prone to spambot abuse. Email me at jf@jonof.id.au if you have problems.
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: Share your Evaldraw scripts  (Read 5263 times)
Jinroh
Chatterbox
***
Posts: 171


Lone Wolf.


View Profile WWW
« Reply #15 on: November 02, 2009, 03:53:19 PM »

Sounds cool, but upon using CopyPasta action on the above segment of code, I get a "Error: Bad Static Init Syntax" Error.
Maybe you need updating your Evaldraw copy.

Perhaps, I'll have to check. I thought I had teh latest version, but maybe not. Tongue
Logged

The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~
The Lone Wolf Of JinrohDev
torbj?rn
Lurker

Posts: 17


View Profile
« Reply #16 on: November 13, 2009, 07:49:10 AM »

Jinroh: The metaballs/isosurfaces script requires the newest version of evaldraw. There are some enums that are dependant on enums higher up I think. I've used that feature in my newest script like this
enum{imgW = 180, imgH = 164, tileSiz = 4} // adjust these according to the image size
enum{W=imgW/tileSiz+1, H=imgH/tileSiz+1 };
Saves having to redefine W and H when I change imgW and imgH. Great Cheesy

For quite some time I've wanted to see how this looks in action:
http://freespace.virgin.net/hugo.elias/graphics/x_warp.htm

Sat down and converted Hugo's C-code to evaldraw. I've been tweaking it all day! Smiley

Variables to tweak:
If you want your own image (CTRL+P) scroll down to // Tweak em! and set useImg = 1;

If you want the screen to be scaled correctly according to the size of your image set
imgW and imgH to the size in pixels of your image. For instance imgW=640, imgH=480

If the code runs to slowly, try increasing the tiled image size, tileSiz = 4. Also, just try adjusting it for fun. If you set tileSiz really big. Like 32,64 or 128 and the spring dampning high, and the elasticity very low, like this:
static springDampning = 1; // but not higher.
static elasticity = 0.0000002; //0.00001;
The program behaves like one of those cheesy "manipulate someones face" programs (pinch, pull the picture with mouse).

Try disabling the mixing of colors. Comment/uncomment mix() The mix() function takes the previous frame, the currently warped frame and the source image and blend/mix them togheter. Try tweaking the mixing factors.

One more thing. Left/right click the image to push/pull the grid nodes that define the flow map. They are springs, so they will bounce back.

This is what it looks like:


And If you don't spec and image with CTRL+P



Code:
enum{imgW = 180, imgH = 164, tileSiz = 4} // adjust these according to the image size
enum{W=imgW/tileSiz+1, H=imgH/tileSiz+1 };
static offsX[W][H];
static offsY[W][H];
static offsXV[W][H];
static offsYV[W][H];
static offsXINT[W][H];
static offsYINT[W][H];
static offsXacc[W][H];
static offsYacc[W][H];
static offsC[W][H];

/*
static norms[3][3] =
{
   0, 16, 32,
   32, 16*1.414214, 16*2.236068,
   32, 16*2.236068, 32*1.414214
};
*/

static norms[3][3] =
{
   0, tileSiz, tileSiz*2,
   tileSiz*2, tileSiz*1.414214, tileSiz*2.236068,
   tileSiz*2, tileSiz*2.236068, tileSiz*2*1.414214
};


static pal[255]; // palette for funky texture.

static img1[imgW][imgH]; // original
static img2[imgW][imgH]; // temp
static texture[imgW][imgH];

// Tweak em!
static useImg = 0; // use pic or generated texture
static randNodeStart = 0;
static springDampning = 0.9999;
static elasticity = 0.000001; //0.00001;
()
{
   cls(); clz(1e32);
   
   if(numframes==0){
      init();
     
      if(useImg==1)
      {
         for(x=0; x<imgW; x++)
         for(y=0; y<imgH; y++)
         {
            texture[x][y] = pic(x,y);//pic("flower.jpg",x,y); 
            img1[x][y] = texture[x][y];
         }
      }
      else
      {
         DrawTexture(tileSiz,tileSiz);
      } 
   }

   
   //for(i=0; i<10; i++)
   Relax();
   
   TextureWarp(); // read img1, store in img2
   mix(); // try turning on/off
   
   static screen[imgh][imgw]; // contains texture to fill screen.
   for(x=0; x<imgw; x++)
   for(y=0; y<imgh; y++)
   {
      //setcol( result[x][y] ); setpix(x,y);
      screen[y][x] = img2[x][y]; //swap x,y
   }
   
   t=glsettex(screen,imgw,imgh);
   
   //
   //drawspr(xres/2, yres/2,imgw,0);
   //texquad(0,0,xres,yres);
   
   setcol(0xffffff); // full brightness
   texquad(0,0,xres,yres);
   glremovetex(t);
   
   
   agitateGrid();   
   //drawGrid();
   
}


texquad(x,y,width,height)
{
   glBegin(GL_COMPLEX);
   glTexCoord(0,0);glVertex(x,y);
   glTexCoord(1,0);glVertex(x+width,y);
   glTexCoord(1,1);glVertex(x+width,y+height);
   glTexCoord(0,1);glVertex(x,y+height);
   glEnd();
}

agitateGrid(){
   direction = 0;
   if(bstatus == 1)
   {
      direction = .5;
   }
   else if(bstatus == 2)
   {
      direction = -.5;
   }
   if(direction != 0)
   for(x=0; x<W; x++)
   for(y=0; y<H; y++)
   {
      if( (x==0) || (x==W-1) || (y==0) || (y==H-1) )
      {
         // dont disturb edge nodes
      }
      else{
      mx = mousx*W/xres;
      my = mousy*H/yres;
      drawsph(mx,my,1);

      xp = x;
      yp = y;
      //if(xp < mx+30 && xp > mx-30)
      //if(yp < my+30 && yp > my-30)
      distToPoint = abs( (mx-xp)^2 + (my-yp)^2 );
     
      if(distToPoint < 4)
      {
         d = atan2(yp-my, xp-mx);
         //dist = ( (xp-mx)^2 + (yp-my)^2);
         
         //offsX[x][y] += direction*cos(d) * min(.5, max(0,dist) );
         //offsY[x][y] += direction*sin(d) * min(.5, max(0,dist) );
         
         offsX[x][y] += direction*cos(d);
         offsY[x][y] += direction*sin(d);
      }
      }
   }
}

drawGrid(){
   xscale = xres/(W*tileSiz);
   yscale = yres/(H*tileSiz);
   for(x=0; x<W; x++)
   for(y=0; y<H; y++)
   {
      //c = int(rnd+.2)*255;
      c=255; setcol(c,c,c);
      drawsph( offsX[x][y]*xscale, offsY[x][y]*yscale, 2);
   }
}

mix()
{
   for(x=0; x<imgW; x++)
   for(y=0; y<imgH; y++){
     
      rn=0; gn=0; bn=0; // new RGB
      ro=0; go=0; bo=0; // old RGB
      rs=0; gs=0; bs=0; // src RGB
      hex2rgb(img2[x][y],rn,gn,bn); // newly warped
      hex2rgb(img1[x][y],ro,go,bo); // previous frame
      //hex2rgb(pic("flower.jpg",x,y),rs,gs,bs); // src
      hex2rgb(texture[x][y],rs,gs,bs); // src
     
      new = 75; // Tweak this. from 1-10 f.ex. Tweak everything :)
      old = 15;
      src = 100-old-new;
      new /= 100;
      old /= 100;
      src /= 100;     

      red = rn*new + ro*old + rs*src;
      green = gn*new + go*old + gs*src;
      blue = bn*new + bo*old + bs*src;
      img1[x][y] = rgb(red,green,blue);
   }
}

TextureWarp()
{
   for(y=0; y<H-1; y++)
   for(x=0; x<W-1; x++)
   {
      TextureBlock(x,y);
   }
}

// img1 -> img2
TextureBlock(xo,yo)
{
   xi = xo * tileSiz-1;
   yi = yo * tileSiz-1;

   Ax=offsXint[xo][yo];
   Ay=offsYint[xo][yo];
   
   Bx=offsXint[xo+1][yo];
   By=offsYint[xo+1][yo];
   
   Cx=offsXint[xo][yo+1];
   Cy=offsYint[xo][yo+1];
   
   Dx=offsXint[xo+1][yo+1];
   Dy=offsYint[xo+1][yo+1];
   
   // Image corners, Left, right
   // A B
   // C D
   TX1=0, TY1=0, TX2=0, TY2=0; tx=0; ty=0;

   VLDx = (Cx-Ax)/tileSiz; // Rate of change X down left
   VRDx = (Dx-Bx)/tileSiz; // X down right
   VLDy = (Cy-Ay)/tileSiz; // Y down left
   VRDy = (Dy-By)/tileSiz; // Y down right
   
   TX1 = Ax;
   TY1 = Ay;
   TX2 = Bx;
   TY2 = By;
   
   for(y=yi; y<yi+tileSiz; y++)
   {
      HDx = (TX2-TX1) / tileSiz; // Rate of change across polygon
      HDy = (TY2-TY1) / tileSiz; // Rate of change across polygon
      tx = TX1;
      ty = TY1;
     
      for(x=xi; x<xi+tileSiz; x++)
      {
         img2[x][y] = img1[ tx ][ ty ];
         tx += HDx;
         ty += HDy;
      }
     
      TX1 += VLDx; 
      TY1 += VLDy;
      TX2 += VRDx;
      TY2 += VRDy;
   } 
}

// Weird texture!
DrawTexture(xs,ys)
{
   VLDc=0; VRDc=0; HDc=0;
   C1=0; C2=0; c=0;
   x=0; y=0; xi=0; yi=0;
   
   for(yi=0; yi<H-1; yi++)
   for(xi=0; xi<W-1; xi++)
   {
      VLDc = (offsC[xi][yi+1] - offsC[xi][yi])/ys;
      VRDc = (offsC[xi+1][yi+1] - offsC[xi+1][yi])/ys;
     
      C1 = offsC[xi][yi];
      C2 = offsC[xi+1][yi];
     
      for(y=yi*ys; y<(yi+1)*ys; y++)
      {
         HDc = (C2-C1) / ys;
         c = C1;
         
         for(x=xi*xs; x<(xi+1)*xs; x++)
         {
            img1[x][y] = 4*pal[c];
            texture[x][y] = img1[x][y];
            c += HDc;
         }
         C1 += VLDc;
         C2 += VRDc;
         
      }
   }
}

Init()
{
   // setup garish palette
   for(i=0; i<64; i++)
   {
      pal[i]     = rgb(i,   0,    63-i);
      pal[i+64]  = rgb(63-i,i,    0);
      pal[i+128] = rgb(0,   63-i, i);
      pal[i+192] = rgb(i,   0,    63-i);
   }   

   for(y=0; y<H; y++)
   for(x=0; x<W; x++)
   {
      if( (x==0) || (x==W-1) || (y==0) || (y==H-1) )
      {
         offsX[x][y] = x*tileSiz;;
         offsY[x][y] = y*tileSiz;;
         offsXv[x][y] = 0;
         offsYv[x][y] = 0;
      }
      else
      {
         offsX[x][y] = x*tileSiz;
         offsY[x][y] = y*tileSiz;
         if(randNodeStart==1)
         {
            offsX[x][y] += nrnd*2;
            offsY[x][y] += nrnd*2;
         }         

         offsXv[x][y] = 0;
         offsYv[x][y] = 0;
      }
      offsXint[x][y] = offsX[x][y];
      offsYint[x][y] = offsY[x][y];
     
      offsXacc[x][y] = 0;
      offsYacc[x][y] = 0;
      offsC[x][y] = int(rnd*255);
   }
}

Relax()
{
   for(y=1; y<H-1; y++)
   {
      yh = y+2;
      yl = y-2;
      if(yl<0) yl=0;
      if(yh>H-1) yh = H-1;
     
      for(x=1; x<W-1; x++)
      {
         xh = x+2;
         xl = x-2;
         if(xl<0) xl=0;
         if(xh>W-1) xh=W-1;
     
         for(yi=yl; yi<=yh; yi++)
         {
            for(xi=xl; xi<=xh; xi++)
            {
               if( (xi != x) || (yi != y) )
               {
                  xspring = offsX[xi][yi] - offsX[x][y];
                  yspring = offsY[xi][yi] - offsY[x][y];
                 
                  norm = norms[abs(xi-x)][abs(yi-y)];
                  length = sqrt(xspring^2 + yspring^2);
                  scaler = (norm-length) * elasticity; //tweak
                 
                  xspring *= scaler;
                  yspring *= scaler;
                 
                  offsXv[xi][yi] += xspring;
                  offsYv[xi][yi] += yspring;
                 
                  offsXv[xi][yi] *= springDampning;
                  offsYv[xi][yi] *= springDampning;
               }   
            }
         }
      }
   }
   
   for(y=1; y<H-1; y++)
   for(x=1; x<W-1; x++)
   {
      if( (x==0) || (x==W-1) || (y==0) || (y==H-1) )
      {
      }
      else
      {
         offsX[x][y] += offsXv[x][y];
         offsY[x][y] += offsYv[x][y];
         offsXv[x][y] *= 0.9999;
         offsYv[x][y] *= 0.9999;
      }
     
      // need to trunc this to integer?
      offsXint[x][y] = ( offsX[x][y] );
      offsYint[x][y] = ( offsY[x][y] );
     
      /*
      // allows it to handle non-integer values of points on the grid
      offsXacc[x][y] += offsX[x][y];
      if(offsXacc[x][y] > 1)
      {
         offsXacc[x][y] -= 1;
         offsXint[x][y] += 1;
      }
      if(offsXacc[x][y] < 1)
      {
         offsXacc[x][y] += 1;
         offsXint[x][y] -= 1;
      }     

      offsYacc[x][y] += offsY[x][y];
      if(offsYacc[x][y] > 1)
      {
         offsYacc[x][y] -= 1;
         offsYint[x][y] += 1;
      }
      if(offsYacc[x][y] < 1)
      {
         offsYacc[x][y] += 1;
         offsYint[x][y] -= 1;
      }
      */

   }
   
   // make sure points on the grid never stray outside screen
   for(x=0; x<W-1; x++)
   {
      if( offsYint[x][1] < 0 ) offsYint[x][1] = 0;
      if( offsYint[x][H-2] > imgH ) offsYint[x][H-2] = imgH;
   }
   for(y=0; y<H-1; y++)
   {
      if( offsXint[1][y] < 0 ) offsXint[1][y] = 0;
      if( offsXint[W-2][y] > imgW ) offsXint[W-2][y] = imgW;
   }
}
hex2rgb(mrgb,&r,&g,&b)

   r = (mrgb / 2^16);
   g = (mrgb / 2^8) % 256;
   b = mrgb % 256;   
}



« Last Edit: November 13, 2009, 09:15:07 AM by torbj?rn » Logged
CaimX86
Observer
*
Posts: 34


View Profile
« Reply #17 on: November 28, 2009, 02:51:15 AM »

I really love Perlin Effect.

Congratulation's torbj?rn.

Maybe I'll start use Evaldraw.
Logged
CraigFatman
Lurker

Posts: 6



View Profile
« Reply #18 on: April 05, 2010, 02:05:26 AM »

An ultrasmooth hypotrochoid/epitrochoid visualizer. =) Includes useful procedures for anti-aliased dots.

Code:
/*
Controls:

Hold LMB or arrow keys to move around
Hold RMB for constant-brightness mode
Hold '1' and move mouse to set the radii
Hold '2' to change the phase
Hit '3' to toggle relative radius mode
*/
static init, ptim, k, tfx, tfy, afx, afy, vfx, vfy,
xs, ys, ph, subs, rel, keycnt[256], keytrig[256];
()
{
tim=klock();
dt=tim-ptim;
  for(i=0;i<256;i++)
  {
    keytrig[i]=0;
    if(keystatus[i]) {
      if(keycnt[i]==0) keytrig[i]=1;
      keycnt[i]+=dt;
      if(keycnt[i]>0.25) { keytrig[i]=1; keycnt[i]-=0.05; } }
    else { keycnt[i]=0; }
  }
if(init==0) {
  init=1;
  xs=12; ys=12; ph=0; subs=16;
}
if(bstatus==1) {
  tfx+=(mousx*2-xres)*dt*subs/xres;
  tfy+=(mousy*2-yres)*dt*subs/yres;
}
if(keystatus[2]) {
  xs=(mousx*2-xres)*12/xres;
  ys=(mousy*2-yres)*12/yres;
}
if(keystatus[3]) {
  ph=(mousx*2-xres)*pi/xres;
}
ph+=dt;
if(bstatus!=2) {
  if(k==0) k=1024; else k=k/75/dt;
} else {
  k=1024;
}
if(keytrig[0xcd]) { // Right
  tfx++;
}
if(keytrig[0xcb]) { // Left
  tfx--;
}
if(keytrig[0xc8]) { // Down
  tfy--;
}
if(keytrig[0xd0]) { // Up
  tfy++;
}
if(keytrig[4]) { // 3
  rel=1-rel;
}
dta=min(dt,0.1);
for(i=0;i<subs;i++) {
tfx+=(tfx+0.5-floor(tfx+1))*dta;
tfy+=(tfy+0.5-floor(tfy+1))*dta;
vfx+=(tfx-afx)*dta;
vfy+=(tfy-afy)*dta;
vfx-=(vfx*abs(vfx)*2+vfx*0.3)*dta;
vfy-=(vfy*abs(vfy)*2+vfy*0.3)*dta;
g=0.05*dta;
if(abs(vfx)<g) vfx=0; else vfx-=g*sgn(vfx);
if(abs(vfy)<g) vfy=0; else vfy-=g*sgn(vfy);
afx+=vfx*dta;
afy+=vfy*dta;
}
fox=floor(afx);
foy=floor(afy);
pfx=(fox-afx)*64;
pfy=(foy-afy)*64;
cls(0);
//k=1024;
setcol(255,255,255);
for(fy=0;fy<=10;fy++) {
  x=xres/2-304; y=64*fy-32+pfy;
  moveto(x,y);
  printf("%g",fy+foy);
}
setcol(255,224,75);
for(fx=-6;fx<=6;fx++) {
  x=xres/2+64*fx-16+pfx; y=4;
  moveto(x,y);
  printf("%g",fx+fox);
}
km=pi*2/k; dm=dt*64*subs;
for(fy=0;fy<=10;fy++) for(fx=-5;fx<=5;fx++) {
 xi=64*fx+pfx; yi=64*fy-16+pfy;
 if(xi>-288 && xi<288 && yi>16 && yi<544) {
  alp=min(min(min(min(xi+288, 288-xi), yi-16), 544-yi), 32);
  alp*=0.01/32;
  xi+=xres/2;
  xsr=xs; ysr=ys;
  if(rel) {
    if(abs(fx+fox)>abs(fy+foy))
      xsr*=(fy+foy)/(fx+fox);
    else if(fy+foy!=0)
      ysr*=(fx+fox)/(fy+foy);
  }
  for(i=0;i<k;i++)
  {
    d=rnd*dm; x=xi+d*vfx; y=yi+d*vfy;
    t=(i+rnd)*km;
    a=t*(fx+fox); b=t*(fy+foy)+ph;
    x+=sin(a)*xsr+sin(b)*ysr;
    y-=cos(a)*xsr-cos(b)*ysr;
    disppntsppa(x, y, 1024, 256, 64, alp);
  }
 }
}
ptim=tim;
}

disppntspp(x, y, r, g, b)
{
  ix=floor(x); iy=floor(y);
  shx=x-ix;
  shy=y-iy;
  disppnta(ix, iy, r, g, b, (1-shx)*(1-shy));
  disppnta(ix+1, iy, r, g, b, shx*(1-shy));
  disppnta(ix, iy+1, r, g, b, (1-shx)*shy);
  disppnta(ix+1, iy+1, r, g, b, shx*shy);
}

disppntsppa(x, y, r, g, b, a)
{
  ix=floor(x); iy=floor(y);
  shx=x-ix;
  shy=y-iy;
  disppnta(ix, iy, r, g, b, a*((1-shx)*(1-shy)));
  disppnta(ix+1, iy, r, g, b, a*(shx*(1-shy)));
  disppnta(ix, iy+1, r, g, b, a*((1-shx)*shy));
  disppnta(ix+1, iy+1, r, g, b, a*(shx*shy));
}


disppnta(x, y, r, g, b, a)
{
  rr=0; rg=0; rb=0;
  getpix(x,y,rr,rg,rb);
  r=sqrt(rr*rr+(r*r-rr*rr)*a);
  g=sqrt(rg*rg+(g*g-rg*rg)*a);
  b=sqrt(rb*rb+(b*b-rb*rb)*a);
  //r+=(rr-r)*a;
  //g+=(rg-g)*a;
  //b+=(rb-b)*a;
  setcol(r,g,b);
  setpix(x,y);
}
Logged
Jinroh
Chatterbox
***
Posts: 171


Lone Wolf.


View Profile WWW
« Reply #19 on: April 11, 2010, 05:52:13 PM »

Nobody's done a Floormapper/Mode7 Effect. So I thought I'd do one for you. ^^ And to show I've no longer any trouble with such things. hehe.

Code:
()
{
   //Mode 7 Effect By Jinroh
   static distLUT[600];
         
   camX = 0;
   camY = 0;
   ang = 0.0;
   radians = pi / 180;
   camHeight = 105;
   horizon = 105;
   dist = xres/2 * tan((90 * radians) / 2);
   invRes = 1 / xres;
   
   //Precalculate our distances
   for(y = 0; y < yres; y++)
      distLUT[y] = dist * camHeight / (camHeight - y);

   while(1) //Infinite loop
   {     
      cls(0);
      for(y = horizon; y < yres; y++) //Loop through all the vertical scanlines
      {
        //Calculate the Coordinates at the periphery of the frustum.
        u1 = cos(ang - (160 * (radians))) * distLUT[y];
        v1 = sin(ang - (160 * (radians))) * distLUT[y];
        u2 = cos(ang + (159 * (radians))) * distLUT[y];
        v2 = sin(ang + (159 * (radians))) * distLUT[y];
       
        u1 += camX;
        v1 += camY;
       
        u2 += camX;
        v2 += camY;
       
        //The Change In the Coordinates Across the scanline
        dU = (u2 - u1) * invRes;
        dV = (v2 - v1) * invRes;
       
        tU = u1;
        tV = v1;
       
        for(x = 0; x < xres; x++)
        {             
           setcol(pic("E:\Index.png", tU, tV));
           setpix(x, y);
           tU += dU;
           tV += dV;
        }
      }
     
      ang += .01;
     
      refresh();
   }
}
Logged

The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~
The Lone Wolf Of JinrohDev
Awesoken
Global Moderator
Fixture
*
Posts: 895



View Profile WWW
« Reply #20 on: April 12, 2010, 03:32:23 AM »

Jinroh: your script runs twice as fast if you replace the setcol()&setpix() per pixel to a sethlin() per hline. Here are the modifications:
Code:
   static hbuf[2048];
   ..         
        for(x = 0; x < xres; x++)
        {             
           //setcol(pic("E:\Index.png", tU, tV));
           //setpix(x,y);
           hbuf[x] = pic("E:\Index.png", tU, tV);
           tU += dU;
           tV += dV;
        }
        sethlin(0,y,hbuf,xres);
Logged

-Ken S.
Jinroh
Chatterbox
***
Posts: 171


Lone Wolf.


View Profile WWW
« Reply #21 on: April 12, 2010, 03:41:02 AM »

Wow, thank you Ken. ^^

I was not aware of that function. Thank you for making me aware. ^^ For those too lazy to make the change here's an update one.

Code:
()
{
   static hbuf[2048];
   //Mode 7 Effect By Jinroh with update by Awesoken.
   static distLUT[600];
         
   camX = 0;
   camY = 0;
   ang = 0.0;
   radians = pi / 180;
   camHeight = 105;
   horizon = 105;
   dist = xres/2 * tan((90 * radians) / 2);
   invRes = 1 / xres;
   
   //Precalculate our distances
   for(y = 0; y < yres; y++)
      distLUT[y] = dist * camHeight / (camHeight - y);

   while(1) //Infinite loop
   {     
      cls(0);
      for(y = horizon; y < yres; y++) //Loop through all the vertical scanlines
      {
        //Calculate the Coordinates at the periphery of the frustum.
        u1 = cos(ang - (160 * (radians))) * distLUT[y];
        v1 = sin(ang - (160 * (radians))) * distLUT[y];
        u2 = cos(ang + (159 * (radians))) * distLUT[y];
        v2 = sin(ang + (159 * (radians))) * distLUT[y];
       
        u1 += camX;
        v1 += camY;
       
        u2 += camX;
        v2 += camY;
       
        //The Change In the Coordinates Across the scanline
        dU = (u2 - u1) * invRes;
        dV = (v2 - v1) * invRes;
       
        tU = u1;
        tV = v1;
       
        for(x = 0; x < xres; x++)
        {             
           hbuf[x] = pic("E:\Index.png", tU, tV);
           tU += dU;
           tV += dV;
        }
        sethlin(0,y,hbuf,xres);
      }
     
      ang += .01;
     
      refresh();
   }
}
« Last Edit: April 12, 2010, 03:45:26 PM by Jinroh » Logged

The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~
The Lone Wolf Of JinrohDev
torbj?rn
Lurker

Posts: 17


View Profile
« Reply #22 on: June 23, 2010, 07:16:45 AM »

Today I modifed the Magfield example that comes with evaldraw in /demos to have multiple poles. Use leftmouse click to drag poles around. Press Space to restart particle flow.
Code:
()
//cls(0x503070);
cls(0);
enum{MAXPOLES = 15}
static poleX[MAXPOLES];
static poleY[MAXPOLES];
static polarity[MAXPOLES];
static positivePole[MAXPOLES];
static positiveCount = 0;

if(numframes==0)
{
   for(i=0; i<MAXPOLES; i++){
      poleX[i] = rnd*xres;
      poleY[i] = rnd*yres;
      polarity[i] = sgn(nrnd);
   }
   for(i=0; i<MAXPOLES; i++)
   {
      if(polarity[i] == 1)
      {
         positivePole[positiveCount] = i;
         positiveCount++;
      }
   }
   
}

if (bstatus%2)
{
   minDist = 1e32;
   closest = -1;
   
   for(i = 0; i<MAXPOLES; i++){
      dist = ((mousx-polex[i])^2 + (mousy-poley[i])^2 ); // < 16^2;
      if( dist < minDist ){
         minDist = dist;
         closest = i; 
      }
   }
   if(closest != -1){
      polex[closest] = mousx;
      poley[closest] = mousy;
   }
}
{   
   enum {NUMP=8192}
   static px[NUMP], py[NUMP], otim;
   
   if (numframes==0 || keystatus[57])
   {
      j=0;
      for(i=0;i<NUMP;i++)
      {
         p = positivePole[j];
         px[i] = polex[p];
         py[i] = poley[p];
         j++;//evaldraw handles out of bounds.
      }
      otim = klock(0);
   }
   
   hx = xres*.5; hy = yres*.5;
   tim = klock(0); dt = tim-otim; otim = tim;
   setcol(0xffffff);
   

   for(i=0;i<NUMP;i++)
   {
      x = px[i];
      y = py[i];
      dead = 0;
      if( x < -10 || x > xres+10 ) dead = 1;
      if( y < -10 || y > yres+10 ) dead = 1;
     
     
      /*if ((abs(x-hx) >= hx) || (abs(y-hy) >= hy))
      {
         //Select random point on border
         j = (xres+yres)*2*rnd;
              if (j < xres) { x = j; y = 0; }
         else if (j < xres*2)
            { x = j-xres; y = yres; }
         else if (j < xres*2+yres)
            { x = 0; y = j-xres*2; }
         else { x = xres; y = j-xres*2-yres; }
      }*/
       

      dist = 1e32;
      vx=0;
      vy=0;
      if(dead==0)
      for(p1=0; p1<MAXPOLES; p1++)
      {
         if(dead)break;
         x1 = poleX[p1]; y1 = poleY[p1];

         //dx = x1-x2; dy = y1-y2;
         //cx = (x1+x2)/2; cy = (y1+y2)/2;

         dist1 = (x-x1)^2 + (y-y1)^2;

         
         if( polarity[p1] == -1 && dist1 < 16^2){dead=1; break;}
     
         nd = 1/dist1;
         vx += (x-x1)*nd*polarity[p1];
         vy += (y-y1)*nd*polarity[p1];
      }     

      //vx /= MAXPOLES;
      //vy /= MAXPOLES;

      if(dead)
      {
         randPole = positivePole[int(rnd*positiveCount)];
         a = (PI*2.0)*rnd;
         px[i] = cos(a)*15+polex[randPole];
         py[i] = sin(a)*15+poley[randPole];
      }
      else
      {
         d= sqrt(vx^2+vy^2);
         f = 5/d;
         //setcol(64+rnd*128, 64+rnd*128, 128+rnd*128);
         setcol(5*f,2*f, 0);
         //setcol(2*f,1*f,0);
         //setcol((i%72)*64+64,(i%80)+128,64);
         //drawsph(x,y,50*d);
         moveto(x-vx*f,y-vy*f);
         lineto(x+vx*f,y+vy*f);
         
         f = 128*dt/d;     
         x += vx*f;
         y += vy*f;
         
         px[i] = x;
         py[i] = y;
      }
   }
}
setcol(0xc0c0ff);
setfont(12,16);
for(i=0; i<MAXPOLES; i++){
moveto(poleX[i]-3,poleY[i]-5); printf("%g",polarity[i]);
}
Logged
Scott_AW
Participant
**
Posts: 79


View Profile WWW
« Reply #23 on: July 11, 2010, 04:12:26 PM »

A simple script I needed to make to print Integers.

Code:
static fntw = 5, fnth = 8, fnts = 3; //Font's width, height and spacing.
enum {MAXDIG = 10};
//Testing
()
{
  cls(0);
  setfont(fntw,fnth);
  printint(123456789,80,0);
}

printint(num,prx,pry)
{
  num = floor(num);  il = intlen(num);
  if(il > 1)
  {
    static stonum[MAXDIG];
    hoff = fntw+fnts;
    for(ic = il; ic > 0; ic -= 1)
    {
      if(ic == il) {stonum[ic] = floor(num/pow(10,ic-1));}
      else {stonum[ic] = floor(num/pow(10,ic-1))-floor(num/pow(10,ic))*10;}
      moveto(prx+(hoff*(il-ic)),pry);printchar(stonum[ic]+48);
    }
  }
  else
  {
    moveto(prx,pry);printchar(num+48);
  }
}

intlen(num)
{
  for(lc = MAXDIG; lc > 0; lc -= 1)
  {
    if(num > pow(10,lc)) return min(lc+1,10);
  }
}

« Last Edit: July 11, 2010, 04:37:41 PM by Scott_AW » Logged
Awesoken
Global Moderator
Fixture
*
Posts: 895



View Profile WWW
« Reply #24 on: July 12, 2010, 04:52:52 AM »

1. There is no 5x8 bitmap font, so setfont() is ignoring your parameters and using the default size: 8x12.
2. A much easier way to print an integer in EVALDRAW is: printf("%.f",num);
Logged

-Ken S.
Scott_AW
Participant
**
Posts: 79


View Profile WWW
« Reply #25 on: July 12, 2010, 05:12:53 AM »

That would be easier, oh well.
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC