Qbasicnews.com
April 05, 2020, 01:18:10 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How can I do a fire effect in 9 lines?  (Read 4937 times)
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« on: February 02, 2003, 01:35:45 AM »

Cheesy
Logged

Antoni
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: February 02, 2003, 02:14:20 AM »

Hmmm - I need a buffer for my fire effect...

Let me try it harder Wink
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #2 on: February 02, 2003, 02:16:54 AM »

I saw it first!   :x
Logged

Antoni
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #3 on: February 02, 2003, 06:07:23 AM »

Huh

Closes lips....

I wouldn't post it if I think it to be impossible.  Hey you made a darn 3dstarfield and a Floormapper in 9 lines!!!!!

And here I see you try to ask for a fire? LOL

PS. A fire fx would take less cal that my translucent plasma!!!

*Rel Spanks Antoni....

*but....

* Wow!!! Its the invasion of the Spanish Armada!!!!!

Viva Espa˝a!!!!
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
toonski84
__/--\__
*****
Posts: 2567



« Reply #4 on: February 02, 2003, 11:04:15 AM »

buffer?  nah.  you need to draw a row of random (255 or 0) pixels at the bottom, and consistantly shift up and average the above pixels.  one trick to cut down on space is to when you average, average the pixels surrounding the bottom one so you dont need extra lines to shift the image up.  if you could do it in 9, it'd be a squeeze.  but i'll play with the idea using some of the hacks (string variables, etc) y'all have come up with.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #5 on: February 02, 2003, 11:23:00 AM »

I've tried to do that and I can't. Y'know, I wanted to show you my impressive fire routine, which has some odd twists and deinitely looks better than any fire I've seen. It has averages, but not in the plain way... And it needs to draw a new frame without altering the previous, 'cause it does a 3x3 matrix convolution:

Code:
// MEGAFIRE by NATHAN 2000

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>

#define pon_punto(x,y,c) (pantalla[x+(y<<8)+(y<<6)]=c)
#define FALSO 0
#define CIERTO !FALSO

typedef short LOGICO;

typedef struct
{
   unsigned char r;
   unsigned char g;
   unsigned char b;
}RGB;

typedef RGB PALETA[256];

unsigned char lee_punto(int x ,int y)
{
   return(peekb(0xA000,x+(y<<6)+(y<<8)));
}

void fuego1(void)
{
   PALETA paleta;
   PALETA negra;
   unsigned char *buffer,*pantalla;
   unsigned int i;
   int x,y;
   int punto;
   int paso=0;
   LOGICO terminado=FALSO;
   LOGICO acabando=FALSO;

   buffer=(unsigned char *) malloc (16000);

   pantalla=(unsigned char *) malloc (16000);

   asm mov ax,0x13
   asm int 0x10

   for(i=0;i<45;i++)
   {
      paleta[i].r=63;
      paleta[i].g=63;
      paleta[i].b=63-(64*i)/45;
   }

   for(i=45;i<150;i++)
   {
      paleta[i].r=63;
      paleta[i].g=63-(64*(i-45))/105;
      paleta[i].b=0;
   }

   for(i=150;i<256;i++)
   {
      paleta[i].r=63-(64*(i-150))/106;
      paleta[i].g=0;
      paleta[i].b=0;
   }

   for(i=0;i<256;i++)
   {
      negra[i].r=0;
      negra[i].g=0;
      negra[i].b=0;
      outportb(0x3C8,i);
      outportb(0x3C9,0);
      outportb(0x3C9,0);
      outportb(0x3C9,0);
   }

   // Borro el buffer:
   for(i=0;i<16000;i++)
   {
      buffer[i]=0;
      pantalla[i]=0;
      pokeb(0xA000,16000+i,255);
      pokeb(0xA000,32000+i,255);
   }

   // Pinta bordecitos.
   for(i=50;i<150;i++)
   {
      pokeb(0xA000,320*i,0);
      pokeb(0xA000,320*i+319,0);
      pokeb(0xA000,320*i+1,150);
      pokeb(0xA000,320*i+318,150);
   }

   do
   {
      if(kbhit())
      {
         getch();
         acabando=CIERTO;
         paso=0;
      }


      // Pinto algunos 'focos' en la línea base:
      for(i=0;i<20;i++)
         pon_punto(random(320),48,255);

      if(paso<115) paso++;

      if(paso>=50 && paso<114 && !acabando)
         for(i=0;i<256;i++)
         {
            if(negra[i].r<paleta[i].r) negra[i].r++;
            if(negra[i].g<paleta[i].g) negra[i].g++;
            if(negra[i].b<paleta[i].b) negra[i].b++;

            outportb(0x3C8,i);
            outportb(0x3C9,negra[i].r);
            outportb(0x3C9,negra[i].g);
            outportb(0x3C9,negra[i].b);
         }

      if(acabando)
      {
         for(i=0;i<256;i++)
         {
            if(negra[i].r>0) negra[i].r--;
            if(negra[i].g>0) negra[i].g--;
            if(negra[i].b>0) negra[i].b--;

            outportb(0x3C8,i);
            outportb(0x3C9,negra[i].r);
            outportb(0x3C9,negra[i].g);
            outportb(0x3C9,negra[i].b);
         }
         if(paso==64) terminado=CIERTO;
      }

      // Desenfoca desplazando lo que hay en pantalla a buffer:
      for(y=1;y<49;y++)
      {
         for(x=1;x<319;x++)
         {
            punto=pantalla[x+(y<<8)+(y<<6)];
            punto+=pantalla[x+((y-1)<<8)+((y-1)<<6)];
            punto+=pantalla[x+1+((y-1)<<8)+((y-1)<<6)];
            punto+=pantalla[x+1+(y<<8)+(y<<6)];
            punto+=pantalla[x+1+((y+1)<<8)+((y+1)<<6)];
            punto+=pantalla[x+((y+1)<<8)+((y+1)<<6)];
            punto+=pantalla[x-1+((y+1)<<8)+((y+1)<<6)];
            punto+=pantalla[x-1+(y<<8)+(y<<6)];
            punto+=pantalla[x-1+((y-1)<<8)+((y-1)<<6)];
            punto/=8;
            if(punto<0)
               punto=0;
            else if(punto>255)
               punto=255;
            buffer[x+320*(y-1)]=(unsigned char)punto;
         }
      }

      // Pinto buffer:

      movedata(FP_SEG(buffer),FP_OFF(buffer),0xA000,48000,16000);

      // Pinto buffer al rev‚s:

      for(i=0;i<50;i++)
         movedata(FP_SEG(buffer),FP_OFF(buffer)+320*i,0xA000,320*(49-i),320);

      // Actualizo pantalla:

      movedata(FP_SEG(buffer),FP_OFF(buffer),FP_SEG(pantalla),FP_OFF(pantalla),16000);


   }while (!terminado);

   asm mov ax,0x3
   asm int 0x10

   free(buffer);
   free(pantalla);
}

void main(void) { fuego1();}


See what I mean?
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
toonski84
__/--\__
*****
Posts: 2567



« Reply #6 on: February 02, 2003, 11:32:14 AM »

oh well, beat ya to it Smiley

Code:

1 SCREEN 13
2 FOR a = 0 TO 255
3  PALETTE a, a \ 4
4 NEXT a
5 PSET (x, 199), CINT(RND) * 255
6 PSET (x, 198 - i), (POINT(x, 198 - i + 1) + POINT(x + 1, 198 - i + 1) + POINT(x + 1, 198 - i - 1) + POINT(x, 198 - i) + POINT(x, 198 - i + 2)) / 5
7 x = (x + 1) MOD 320
8 IF x = 0 THEN i = (i + 1) MOD 98
9 IF INKEY$ = "" THEN GOTO 5


slow as molasses and ugly as hell, but it's fire.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
NashKat
New Member

Posts: 13


« Reply #7 on: February 05, 2003, 03:05:16 PM »

Doing it the way you typed it you forgot to lable your line. It doesn't know where to go, but I could be very wrong. So do the 9 lines work here or is there another way? :Huh:
Logged
toonski84
__/--\__
*****
Posts: 2567



« Reply #8 on: February 05, 2003, 06:30:36 PM »

*slaps forehead*
blame that on word wrap, not me.  and here's a much faster edition:
Code:

1 SCREEN 13
2 FOR x% = 0 TO 127
3 PALETTE x%, x% \ 2
4 NEXT x%
5 DEF SEG = &HA7D0
6 FOR x% = 31999 TO 0 STEP -1
7 IF x% >= 31680 THEN POKE x%, CINT(RND * 127) ELSE POKE x%, (PEEK(x% + 320) + PEEK(x% + 319) + PEEK(x% + 321) + PEEK(x%) + PEEK(x% + 640)) \ 5
8 NEXT x%
9 IF INKEY$ = "" THEN GOTO 5
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #9 on: February 05, 2003, 06:43:15 PM »

the 'c' source above has been converted/shrinked to 11 lines in QB by Phobeous and me: take a glance at the challenge section Wink
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
toonski84
__/--\__
*****
Posts: 2567



« Reply #10 on: February 05, 2003, 06:44:42 PM »

yeah, i saw it, it's really fantastic.  i dont think i understand teh effect though (mine is a run-of-the-mill "blur upwards" routine Cheesy)
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #11 on: February 05, 2003, 06:50:06 PM »

MIne is also an 1 pixel shifted blur, but with these issues:

* 1st of all, I read 9 dots (the center dot and the 8 that surround it), which are added and divided by 8, not by 9, so it isn't an average.

* The secret is not overwriting the source image instantly. A new image is built from the original, and then that image overwrites the original 1 pixel up.

This is called "convolution". In a convolution, you calculate each pixel of a new image (transformed image) applying a matrix to a group of pixels centered in the current one and measuring the same than the matrix in the original image. Applying means doing a multiplication of each matrix member to each pixel, adding all the values, saturating the result (so it doesn't exceed 255) and writing with that value the new pixel. The twist is that we are shifting the pixels 1 position up.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!