Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Shockwave on January 17, 2008

Title: Simple unoptimised picture zoomer.
Post by: Shockwave on January 17, 2008
Source only;
(it generates it's own pic).

Code: [Select]
'
' BY SHOCKWAVE
' ZOOMS WHATEVER IS IN PICTUREBUFFER AND DISPLAYS ON BUFFER
   
    OPTION STATIC
    OPTION EXPLICIT
   
    #INCLUDE "TINYPTC_EXT.BI"
    #INCLUDE "WINDOWS.BI"

'-------------------------------------------------------------------------------
' SCREEN STUFF ;
'-------------------------------------------------------------------------------

    CONST   XRES    =    640
    CONST   YRES    =    480


    DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )


'-------------------------------------------------------------------------------
' COPY THIS;
'-------------------------------------------------------------------------------

    DIM SHARED AS UINTEGER PICBUFFER ( XRES * YRES )
   
    DECLARE SUB FILL_PICBUFFER()
    DECLARE SUB DRAWPICBUFFER(BYVAL PX1 AS DOUBLE,PY1 AS DOUBLE,BYVAL PX2 AS DOUBLE,PY2 AS DOUBLE,BYVAL PX3 AS DOUBLE,PY3 AS DOUBLE,BYVAL PX4 AS DOUBLE,PY4 AS DOUBLE)
    FILL_PICBUFFER()
 
    PTC_ALLOWCLOSE(0)
    PTC_SETDIALOG(1,"",0,0)               
    IF (PTC_OPEN("C-I-R-C-U-L-A-R",XRES,YRES)=0) THEN
    END-1
    END IF     
   
    DIM ZOOM AS INTEGER
    DIM AS DOUBLE XP1,XP2,XP3,XP4,YP1,YP2,.YP3,YP4
    XP1=320
    XP2=320
    YP1=240
    YP2=240
    DIM SS AS DOUBLE
    SS=TIMER
WHILE((GETASYNCKEYSTATE(VK_ESCAPE)<> -32767))
IF TIMER-SS>3 AND TIMER-SS<15 THEN
IF XP1>0 THEN XP1=XP1-1.34
IF XP2<XRES THEN XP2=XP2+1.34
IF YP1>0 THEN YP1=YP1-1
IF YP2<YRES THEN YP2=YP2+1
END IF


IF TIMER-SS>15 THEN
IF XP1<320 THEN XP1=XP1+1.34
IF XP2>320 THEN XP2=XP2-1.34
IF YP1<240 THEN YP1=YP1+1
IF YP2>240 THEN YP2=YP2-1
END IF

    DRAWPICBUFFER(XP1,YP1,XP2,YP1,XP1,YP2,XP2,YP2)
   
    PTC_UPDATE@BUFFER(0)
    ERASE BUFFER
WEND


'-------------------------------------------------------------------------------
' GENERATE RANDOM PICTURE!
'-------------------------------------------------------------------------------

SUB FILL_PICBUFFER()
    DIM AS INTEGER X,Y,C
   
    FOR Y=0 TO YRES-1
    FOR X=0 TO XRES
        C= X XOR Y
        PICBUFFER(X+(Y*XRES))=RGB(C,C,C)
    NEXT
    NEXT

END SUB


SUB DRAWPICBUFFER(BYVAL PX1 AS DOUBLE,PY1 AS DOUBLE,BYVAL PX2 AS DOUBLE,PY2 AS DOUBLE,BYVAL PX3 AS DOUBLE,PY3 AS DOUBLE,BYVAL PX4 AS DOUBLE,PY4 AS DOUBLE)

        DIM AS DOUBLE INTERX,INTERY, AX,AY
        DIM AS INTEGER XL,YL

        AX=0
        AY=0
       
        INTERX=XRES/(PX2-PX1)
        INTERY=YRES/(PY3-PY1)

FOR YL=PY1 TO PY4
   
    IF  YL>5 AND YL<YRES-5 THEN
    FOR XL=PX1 TO PX2
       
        IF XL>1 AND XL<XRES-1 THEN
        BUFFER(XL+(YL*XRES))=PICBUFFER(INT(AX)+(INT(AY)*XRES))
        END IF
        AX=AX+INTERX
       
    NEXT
    END IF

    AY=AY+INTERY
    AX=0
NEXT

END SUB
Title: Re: Simple unoptimised picture zoomer.
Post by: benny! on January 17, 2008
I would love to see it ... any chance of supplying an exe ?
Title: Re: Simple unoptimised picture zoomer.
Post by: Shockwave on January 17, 2008
Lol, I knew I'd have to post an exe :) Why didn't I do it in the first place?
Ok, leave it for a few seconds after you run it for the effect to happen.
Title: Re: Simple unoptimised picture zoomer.
Post by: benny! on January 17, 2008
Thanks shocky. That runs very smooth here. Looks great.
Title: Re: Simple unoptimised picture zoomer.
Post by: Shockwave on January 17, 2008
It can be sped up easily with pointers :)
Title: Re: Simple unoptimised picture zoomer.
Post by: rain_storm on January 17, 2008
Looks good and the source is very neat and compact. This is a great example to learn from
Title: Re: Simple unoptimised picture zoomer.
Post by: DrewPee on January 17, 2008
Nice code. As already said by rain_storm, great example to learn from - thanks again!

Drew
Title: Re: Simple unoptimised picture zoomer.
Post by: Shockwave on January 17, 2008
Use it if you want to :)