Author Topic: Toying with COS & SIN commands to produce 2D effects.  (Read 24086 times)

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Try this small modification to the above code.  Compile it, move the mouse like crazy with left button held down. The overall effect is very similar to a skyscape coming towards you.

//// Skyscape effect

GETSCREENSIZE w,h

GRABSPRITE 0,0,0,w,h

WHILE TRUE

ROTOSPRITE 0,0,0,0 // draw current display

MOUSESTATE mx, my, b1, b2 // read da mouse

IF b1=1 // button pressed

FOR a=0 TO 90 STEP 5 // change the "STEP" for different effects

DRAWRECT 300+COS(a)*50+mx,200+SIN(a)*50+my,mx-mx/2,my-my/2,RGB(255/mx+my,mx+my,255)
DRAWRECT 300-COS(a)*50-mx,200+SIN(a)*50-my,mx-mx/2,my-my/2,RGB(255/mx+my,mx+my,255)
DRAWRECT 300+COS(a)*50-mx,200+SIN(a)*50+my,mx-mx/2,my-my/2,RGB(255/mx+my,mx+my,255)
DRAWRECT 300+COS(a)*50+mx,200+SIN(a)*50-my,mx-mx/2,my-my/2,RGB(255/mx+my,mx+my,255)

NEXT

ENDIF

GRABSPRITE 0,0,0,w,h // grab new screen display

SHOWSCREEN

WEND
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
erm...or a strange new world :)
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Replace the above code with the following:

//
DRAWRECT 300+COS(a)*50+mx,200+SIN(a)*50+my,mx-mx/2,my-my/2,RGB(255/mx+my,200,mx+my)
DRAWRECT 300-COS(a)*50-mx,200+SIN(a)*50-my,mx-mx/2,my-my/2,RGB(0,mx+my,255)
//
DRAWRECT 300+COS(a)*50-mx,200+SIN(a)*50+my,mx-mx/2,my-my/2,RGB(mx+my,200,mx+my)
DRAWRECT 300+COS(a)*50+mx,200+SIN(a)*50-my,mx-mx/2,my-my/2,RGB(0,mx+my,255)
//

It creates a simple sky & landscape - fun for the kids.
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Code: GLBasic [Select]
// The tunnel that might be made of jelly tweaked.
// A 50 pence production (c)
// created by "I love my brick"

GETSCREENSIZE w,h

tsize=51 ; xpos=320 ; ypos=200 ; shortradius=14 ; longradius=25 ; rot=1

        TYPE tube ; x ; y ; sizex ; sizey ; speed ; r ; g ; b ; sx ; sy ; ENDTYPE

GLOBAL t[] AS tube ; DIM t[tsize]

        FOR a=0 TO tsize-1

        t[a].speed=0.5 ; t[a].x=xpos ;  t[a].y=ypos ; t[a].sizex=shortradius ; t[a].sizey=longradius
        INC shortradius,10; INC longradius,10 ;
        t[a].r=0; t[a].g=0; t[a].b=0 ;
        INC t[a].sx,2 ; INC t[a].sy,2

        NEXT

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main Loop
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

WHILE NOT FALSE
ROTOSPRITE 0,0,0,0.1
FOR bb=0 TO 50

FOR aa=0 TO 360 STEP 15

        x=t[bb].x+t[bb].sizex*COS(aa)*COS(rot)+t[bb].sizey*SIN(aa)*SIN(rot) // the maths bit
        y=t[bb].y+t[bb].sizex*COS(aa)*SIN(rot)-t[bb].sizey*SIN(aa)*COS(rot)

        DRAWRECT x,y,t[bb].sx,t[bb].sy, RGB(t[bb].r, t[bb].g, t[bb].b)
NEXT

        INC t[bb].sx,0.1 ; INC t[bb].sy,0.1 // increase the size of the block
        INC t[bb].sizex,t[bb].speed ; INC t[bb].sizey,t[bb].speed ; INC t[bb].speed,0.1 // acceleration

        IF t[bb].sizex>500 // return to centre of screen
        t[bb].sizex=4 ; t[bb].sizey=25 ;  t[bb].speed=0.1
        t[bb].sx=1.1 ; t[bb].sy=1.1 ; t[bb].sizex=10+RND(20) ; t[bb].sizey=5+RND(10)
        ENDIF
NEXT

        INC rot, 10 // let the wobble begin!
                // set new values for next set of colour
        ran1=RND(255)
        ran2=RND(255)
        ran3=RND(255)

        FOR a=0 TO 50 STEP RND(50) // alter all colours
        t[a].r=ran1
        t[a].b=ran2
        t[a].g=ran3
        NEXT
       
        IF KEY(203)=1 THEN INC x
        GRABSPRITE 0,0,0,w,h
        SHOWSCREEN
WEND // infinity in action!
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Code: GLBasic [Select]
// Spiral code tweak
// I LOVE MY BRICK

GETSCREENSIZE w,h

GRABSPRITE 0,0,0,w,h

change=3.75

//////////
// DA LOOP
//////////

WHILE TRUE

INC count

        IF count=5

                ROTOSPRITE 0,0,0,0.1 // draw current display

                count=0

        ELSE

                ROTOSPRITE 0,0,0,0

        ENDIF

FOR aa=1 TO 26000 STEP change

        x=COS(aa)/32
        y=SIN(aa)/32

        col=RGB(COS(r)*100+100,SIN(count+aa*5)*127+127,SIN(b+aa*5)*127+127)

        DRAWRECT 320+y*aa/2,200+x*aa/2,2,2,col

NEXT

INC change, 0.4 // let the fun begin!

        GRABSPRITE 0,0,0,w,h // grab new screen display

SHOWSCREEN

WEND
I like things and do stuff.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Awesome is one of many words i can think of.
Ill be giving my shrink your name when im in a straight jacket after i attepmt to use these ideas with my 3d particle engine.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Well look at me, I think Im a priest and drag a brick around on a piece of string. :) The code Ive been posting has had a heavy effect upon my sanity :D

But if you do try to implement anything into your particle engine, just remember..."no pain, no gain" :D
I like things and do stuff.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
You gave me your bug..
Dont stare at this too long.

Code: GLBasic [Select]
// Spiral code tweak
// Hemlos

SETSCREEN 800,600,TRUE
FUN1=1


LIMITFPS 40

LOCAL  w,h
GETSCREENSIZE w,h
GRABSPRITE 0,0,0,w,h

WHILE TRUE
        ROTOSPRITE 0,0,0, 4.0
        ALPHAMODE 1.0
        FOR aa=0 TO 359 STEP FUN1

                INC spread, 1.0

                x=COS(aa)*spread
                y=SIN(aa)*spread
               
                IF spread>w/2 THEN spread=1.0
       
                Tweakcolor1=RND(255)/2.0+64
                col=RGB(COS(change)*Tweakcolor1,SIN(change)*Tweakcolor1,SIN(change)*Tweakcolor1)
                DRAWRECT w/2+x,h/2+y,1,1,col

        NEXT

INC change, 1.0
IF change=360.0; change=1.0; ENDIF;

GRABSPRITE 0,0,0,w,h // grab new screen display

SHOWSCREEN

WEND
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Very nice Hemlos, reminds me of some kind of fossilised shell.
I like things and do stuff.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Reminds me of vertigo

This thread belongs in the math section i think, how about you?
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Yes I agree, now how do we move it?
I like things and do stuff.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Well, we merely need to mention it i suppose!
Obviously, theres a little bird with an impecable sense of direction flying around the forums .
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Does this bird look like the pheonix you display near you name? :)

Thankx.

Now Im in Math land lets hope users can see that circluar Math can with clever imagination be implemented into dazzling effects - often cheap on the processor leaving space for other requirements.
 
I like things and do stuff.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
No, it was another mod
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
I was just jesting Hemlos.  I read "bird" and saw a "bird" representing you.

I`m an admirer of your manipulation of the 2d screen.  keep it up!

Me, well too long in the tooth - so I use old fashioned ways with present day power to create a reaction on screen.

(which often only takes a few lines of code. - I always knew one day they would work)

All code Ive placed is a reflection of ideas that never worked on the humble Amiga.(slow frame rate)

Then I see guys like you with a platform that makes anything possible - unlike the ST & Amiga.

I`m learning Hemlos to embrace this new platform via young guys like you.





I like things and do stuff.