BASIC

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

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Welcome to all.

Below are a few progs that create dazzling eye candy. No doubt there are far easier methods of achieving what Ive included here - if so show me as I learning all the time :)

[attachment deleted by admin]
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
The one above creates a simple wobbly vortex.

This next one produces a spiral that slowly unravels itself.

[attachment deleted by admin]
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
This next one generates a pattern made out of lines - press space to reveal a new one.

[attachment deleted by admin]
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Using drawrect, this next sample displays a screen size explosion in multicolour simplicity.

It could also pass as a primitve psychedelic show too. :)

[attachment deleted by admin]
« Last Edit: 2012-Feb-15 by I love my Brick »
I like things and do stuff.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10723
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
very nice. You need to set the project/options "explicit declaratinos" on, because your last example had a typo... ;)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Good job. Nothing like a bit of smash coding.  :zzz:

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Well, that wasted 15 minutes of my day!
Couldn't resist tweaking the values in your code, to see what changed!  :S
Very fun stuff, and in so little code.  :good:
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Fun.  :good:

I added a poly to the spiral code. Very psychedelic.

Code: GLBasic [Select]
GLOBAL change,x,y,aa,col,ca,mel,xo,yo

change=20.0 // this excites the dots on screen

WHILE NOT FALSE

        FOR aa=1 TO 12996 STEP change
       
                INC ca, 0.1
               
                mel = MOD(aa+ca,12996)
       
                SELECT mel
               
                        CASE 1 TO 2166
                       
                                col = RGB(255,INTEGER(mel/8.494117647058824),0)
                               
                        CASE 2167 TO 4332
                       
                                col = RGB(255-(mel-2166)/8.494117647058824, 255,0)
                               
                        CASE 4333 TO 6498
                       
                                col = RGB(0, 255, (mel-4332)/8.494117647058824)
                               
                        CASE 6499 TO 8664
                               
                                col = RGB(0, 255-(mel-6495)/8.494117647058824, 255)
                               
                        CASE 8665 TO 10830
                       
                                col = RGB((mel-8664)/8.494117647058824, 0, 255)
                               
                        CASE 10831 TO 12996
                       
                                col = RGB(255, 0, 255-(mel-10830)/8.494117647058824)
                               
                        DEFAULT
                       
                                col = RGB(128,128,128)

                ENDSELECT

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


                        SMOOTHSHADING TRUE
                        STARTPOLY -1, 0
                        ALPHAMODE 0.1
                                POLYVECTOR 322+y*aa,243+x*aa, 0, 0, col
                                POLYVECTOR 322+y*aa,243+xo*aa, 0, 10, col
                                POLYVECTOR 322+yo*aa,243+xo*aa, 10, 10, col
                                POLYVECTOR 323+yo*aa,243+x*aa, 10, 0, col
                        ALPHAMODE 0.1
                        ENDPOLY


                        ALPHAMODE 0.5
                        DRAWLINE 323+y*aa,243+x*aa, 323+yo*aa,243+xo*aa, col
                        DRAWRECT 322+y*aa,242+x*aa,3,3, RGB(196,196,196)
                       
                        xo = x
                        yo = y

        NEXT
       
        INC change, 0.0333 // let the fun begin!
        SHOWSCREEN
//KEYWAIT
WEND // infinity in action!

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Thats amazing!  I love it.

Now youve got me tinkering with your code :D  Its the best way to learn new tricks.

Thanks.

I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
...and heres one I prepared earlier.

[attachment deleted by admin]
I like things and do stuff.

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Good going! I especially like what you've done with the colour gradients.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Heres a very simple looking bat and ball game with bricks that sway - yes i know its boring :). The bricks could easily become aliens and the bat a space ship. My next little bit of code will be a PAC MAN clone using much of the above to produce a wacky but fun experience :D

Use left and right cursors to move the bat.

[attachment deleted by admin]
I like things and do stuff.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Hi these examples are very nice... thanks for sharing...

I think this are the new Polibius  :D :D

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
I've uploaded a video of your spiral thingy code with added polyvectors and trailbacks. Click here to see it. :)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4240
    • View Profile
    • Portfolio
gasp cogh :O

looks wondefull, and that Slaygon tune is just awesome...have been thinking of this tune for a featured zombi apocalypse movie for quite some time.

Great code you guys, I´m afraid to check it and feel naive... :(