GLBasic forum

Codesnippets => Math => Topic started by: I love my Brick on 2012-Feb-15

Title: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-15
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]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-15
The one above creates a simple wobbly vortex.

This next one produces a spiral that slowly unravels itself.

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-15
This next one generates a pattern made out of lines - press space to reveal a new one.

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-15
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]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Kitty Hello on 2012-Feb-15
very nice. You need to set the project/options "explicit declaratinos" on, because your last example had a typo... ;)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: matchy on 2012-Feb-15
Good job. Nothing like a bit of smash coding.  :zzz:
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Slydog on 2012-Feb-15
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:
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Wampus on 2012-Feb-16
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!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-16
Thats amazing!  I love it.

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

Thanks.

Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-16
...and heres one I prepared earlier.

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Wampus on 2012-Feb-16
Good going! I especially like what you've done with the colour gradients.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Feb-17
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]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: mentalthink on 2012-Feb-17
Hi these examples are very nice... thanks for sharing...

I think this are the new Polibius  :D :D
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Wampus on 2012-Feb-28
I've uploaded a video of your spiral thingy code with added polyvectors and trailbacks. Click here to see it (http://www.youtube.com/watch?v=Dwp37rH6nlg). :)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-Feb-28
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... :(
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: fuzzy70 on 2012-Feb-28
Quote from: Wampus on 2012-Feb-28
I've uploaded a video of your spiral thingy code with added polyvectors and trailbacks. Click here to see it (http://www.youtube.com/watch?v=Dwp37rH6nlg). :)

I like that a lot, even though it wants me to throw in the towel programming wise  :sick:

Lee
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Wampus on 2012-Feb-28
Erico and Fuzzy, it might look lovely but I'm not some uber-coder or something. It was an accident. I played with parameters without thinking much about it and that was the result.  :-[

Attached is the code so you can see how simple it actually is.

[EDIT: And yeah, that Slaygon track is awesome!]

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: fuzzy70 on 2012-Feb-28
Thanks for posting the source, I am building up quite a nice collection now   =D

I am basically using them for learning purposes in how GLB works or how to achieve something in GLB. Types (as in functions in types etc) were one of my biggest problems but thanks to source posted on this forum & looking at how others have done it & why they did it that way has helped tremendously.

I started programming games on a ZX80 all the way up to an Amiga but when I switched to PC's many years ago writing tools/utils/apps basically took over & getting my mind back in track for games programming is taking a while (prob due to age  :D) but I will get there.

There are a few projects that I have done which have been halted/abandoned due to losing track or going in the wrong direction but all of them have served a purpose & have learnt a lot from them so they wasn't a waste of time.

Lee

Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-Feb-28
I spare a  :coke: to I love bricks, you around?

I´m still afraid of checking the code hehe, better finish up my game first :-[
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-Feb-28
Quote from: fuzzy70 on 2012-Feb-28
There are a few projects that I have done which have been halted/abandoned due to losing track or going in the wrong direction but all of them have served a purpose & have learnt a lot from them so they wasn't a waste of time.

me too, I wish I had them all, but unfortunantly, only a couple amiga games I did still survive, in code and aminet, the rest is lost :(
My mom kept some of my HQ books (ones me and my brother wrote from scratch), would pay fortunes for the lost ones + my lost games. Hint to nowadays dads...keep all your son´s codes!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Mar-03
Quote from: Wampus on 2012-Feb-28
I've uploaded a video of your spiral thingy code with added polyvectors and trailbacks. Click here to see it (http://www.youtube.com/watch?v=Dwp37rH6nlg). :)

Wow, that is awfully nice. http://www.glbasic.com/forum/Smileys/glbasic/good.gif
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Mar-03
The PacMan game is almost complete.  Its called Scape Ghost, you play a rogue spirit addicted to munching on pills :D The maze ripples along as an animated background mutates. 

Love the DotBall prog - welldone!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Mar-05
Heres two more progs to tinker with.

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Ian Price on 2012-Mar-05
Some pretty nice effects there :)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-15
Hi folks, wow this place looks bare and full of cobwebs.

Theres a few lines of code below that draw gradient Circles with hope that someone replies and sweeps up the webs :)  .... erm....cough...bring a brush.

(Since January of this year Ive been infused with creating a Sprite Designer for GLBasic.  Its come on well and is almost complete.)

Heres an example of how you can to draw colour/gradient circles. Press a Key to animate.



Code (glbasic) Select

GLOBAL x , y , radius , r , g , b , size , col

radius = 50

////
/////
// Da Loop
/////
////

WHILE TRUE // PRESS A KEY TO CONTINUE

FOR loop = 1 TO 20+RND(10)

x= RND(800) // New Xpos

y= RND(800) // not used


FOR a = 1 TO 90

random=RND(255) // ot used

r = a * 2
g = a + 1
b = g + 1

col=RGB(r,g,b)

DRAWLINE x-COS(a)*radius, size+SIN(a)*radius, x,size+SIN(a)*radius, col

DRAWLINE x+COS(a)*radius, size+SIN(a)*radius, x,size+SIN(a)*radius, col

DRAWLINE x+COS(a)*radius, size-SIN(a)*radius, x,size-SIN(a)*radius, col

DRAWLINE x-COS(a)*radius, size-SIN(a)*radius, x,size-SIN(a)*radius, col

NEXT

//size=RND(700)

x=RND(700)

radius = 10 + RND(50)  // New size to shape

INC size ; IF size > 600 THEN size = 0  // Primitive scroll

NEXT

SHOWSCREEN
KEYWAIT
WEND

...

I hope it helps others with thier projects.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-15
To achieve a central, outward gradient all you need to do is shrink the circle around its x & Y pos.  You then increase the size of the circle by 1 and alter the RGB value to suit.

Have fun and I hope I helped someone with their needs.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-15
Just tried! Great!

You know...on another thread, we were discussing about dinamic terrains with textures.
Now I see the results of your code, and it just inspired me that such method, could well be used to try and attempt that.

Really great! :good:
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-15
Hey Erico, I`m a 2D guy pulling all I can out of the hat. Its good news to know that Ive helped you. I look forward to seeing what you can display.

Im a veteran of the Amiga Days....yawn :)

Im currently coding a Sprite Editor/Creator and this previous code of mine was a idea for filled/non filled circles.

Glad it helped you buddy.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-15
Thanks, the terrain generation is actually needed by another forum´s chap I was trying to help, but this sure really inspires.
I´m eager to see what you have going on the sprite editor/creator line of app.
:good:
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-15
Well so far I have completed the following-

Draw
Line
Box (filled/outline)
Circle/Elipse (filled/outline)
Fill - one colour / gradient fill
flood fill(every target colour)
Shapes - vector images from my idea of what can help quickly to outline your idea
Flip - x & Y
Rotate
scroll - wrap around/null repeat
Twist - use the scroll buttons to slowly flip a sprite - like a spinning coin or power up? etc
48 colours to play with - Thats a challenge but better than having 100s of colours to get lost with.
I had started with 32x32/64x64/128x128 & now leave it at 64x64.
If you need to crop this to something. well thats in place for version 2.
Built in animator.
Built in canvass - draw them on screen and see how they look - you can cut a group out and save them as oe sprite.
Colour - alter RGB, darken,brighten
Cut - make a new image that draws on screen
paste - draw it
Copy - keep an image - to drop into a new sprite back
Save/Load
Undo / ....Why redo?

Im learning new tricks whilst coding this and toy with such ideas to implement them into version 1.

I also then see - I can improve this or that - etc.

Such is the life of a coder or creator :)
 


Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-15
That list is quite promising!
I´m particularly found of:

Shapes - vector images from my idea of what can help quickly to outline your idea
Built in animator.
Built in canvass - draw them on screen and see how they look - you can cut a group out and save them as oe sprite.

Things from some other places I find interesting:

light table for animations
stencil for the outlines, easier to color something?

I´m not really sure ´redo´ is needed, like if you have a spare screen or an animation set, you can use other frames to test variations. IMO

Again, it feels quite promising, how long till you believe it will be ready to ship?
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-15
Heres some filled circle eye candy.

Code (glbasic) Select

GLOBAL x , y , radius , r , g , b , size , col, num, radius1, p, count
num=100
radius = 0
radius1 = 10
x=100
y=100

////
/////
// Da Loop
/////
////

WHILE TRUE
FOR loop = 1 TO num ; r = 70  ; g = 60  ; b = 50
FOR a = 1 TO 360 ; r=r+p ; b=b+p ; g=g+p 
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=202 ; num=100 ; radius=0 ; p=0
FOR loop = 1 TO num ; r = 10/num  ; g = 10/num  ; b = 10/num
FOR a = 1 TO 360 ; r=r+p/a*b ; b=b+p/a+g ; g=g+p/a
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=302 ; num=100 ; radius=0 ; p=100
FOR loop = 1 TO num ; r = 30+loop*num/2  ; g = 40+loop*num/3  ; b = 200+loop*num/4
FOR a = 1 TO 360 ; r=r+p*loop ; b=b+p*loop ; g=g+p*loop
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; DEC p ; NEXT

x=402 ; num=100 ; radius=0 ; p=100
FOR loop = 1 TO num ; r = 250  ; g = 100 ; b = 255
FOR a = 1 TO 180 ; r=r-1 ; b=b-0.1 ; g=g+0.1 
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
DRAWRECT x-COS(a)*radius, y-SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=502 ; num=100 ; radius=0 ; p=100
FOR loop = 1 TO num ; r = 20  ; g = 22  ; b = 20
FOR a = 1 TO 360 ; r=r*p ; b=b+p ; g=g+p 
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=100 ; num=100 ; radius=0 ; p=100 ; y=200
FOR loop = 1 TO num ; r = 20  ; g = 22  ; b = 20
FOR a = 1 TO 360 ; r=r*p ; b=b-p ; g=g+p/a 
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=202 ; num=100 ; radius=0 ; p=100
FOR loop = 1 TO num ; r = 20+num  ; g = 22*num ; b = 20*num
FOR a = 1 TO 360 //; r=r+a ; b=b+a ; g=g+b 
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=302 ; num=100 ; radius=0 ; p=100
FOR loop = 1 TO num ; r = 20-num  ; g = 44*num ; b = 34/num
FOR a = 1 TO 360 ; r=r+a ; g=g+b 
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=402 ; num=100 ; radius=0 ; p=10
FOR loop = 1 TO num ; r = loop  ; g = loop/2 ; b = loop/2
FOR a = 1 TO 360   
col=RGB(r,g,b) ;  DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; INC p ; NEXT

x=502 ; num=100 ; radius=0 ; count=0
FOR loop = 1 TO num ; r = 255+loop  ; g = 100+loop ; b = loop/2
FOR a = 1 TO 360 ; INC count ; IF count=2 THEN count=0   
IF count=1 THEN col=RGB(r,g,b) ; IF count=0 THEN col=RGB(0,0,0)
DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; NEXT

x=100 ; num=100 ; radius=0 ; count=0 ; y=300
FOR loop = 1 TO num ; r = 100+loop  ; g = 200+loop ; b = 100+loop/2
FOR a = 0 TO 360 STEP 5; INC count ; IF count=3 THEN count=0   
IF count=1 THEN col=RGB(r,g,b) ; IF count=0 THEN col=RGB(r/2,g/2,b/2) ; IF count=2 THEN col=RGB(r*2,g*2,b*2)
DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; NEXT

x=202 ; num=100 ; radius=0 ; count=0
FOR loop = 1 TO num ; r = 255  ; g = 100 ; b = 0
FOR a = 0 TO 360 ; INC count ; IF count=3 THEN count=0   
IF count=1 THEN col=RGB(r,g,b) ; IF count=0 THEN col=RGB(r/2,g/2,b/2) ; IF count=2 THEN col=RGB(r*2,g*2,b*2)
DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 3, 3, col
NEXT ; INC radius ; DEC num ; NEXT

x=302 ; num=100 ; radius=0 ; count=1 ; p=300
FOR loop = 1 TO num ; r = 255  ; g = 255 ; b = 255
FOR a = 0 TO 180 STEP count ; r=r+a/num ; g=g+g/num ; INC count ; IF count=3 THEN count=1
col=RGB(r,g,b)
DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 2, 2, col
DRAWRECT x-COS(a)*radius, y-SIN(a)*radius, 2, 2, col
NEXT ; INC radius ; DEC num ; DEC p,10 ; NEXT

x=402 ; num=100 ; radius=0 ; count=1 ; p=300
FOR loop = 1 TO num ; r = 100  ; g = 0 ; b = 100
FOR a = 0 TO 180 STEP count ; r=r+a/num ; g=g+g/num ; b=b+p/num ; INC count ; IF count=3 THEN count=1
col=RGB(r,g,b)
DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 2, 2, col
DRAWRECT x-COS(a)*radius, y-SIN(a)*radius, 2, 2, col
NEXT ; INC radius ; DEC num ; DEC p,10 ; NEXT

x=502 ; num=100 ; radius=0 ; count=1 ; p=300
FOR loop = 1 TO num ; r = 100  ; g = 100 ; b = 10
FOR a = 0 TO 90 STEP count ; r=r+a/num ; g=g+g/num ; b=b+p/num ; INC count ; IF count=3 THEN count=1
col=RGB(r,g,b)
DRAWRECT x-COS(a)*radius, y+SIN(a)*radius, 2, 2, col
DRAWRECT x-COS(a)*radius, y-SIN(a)*radius, 2, 2, col

DRAWRECT x+COS(a)*radius, y-SIN(a)*radius, 2, 2, col
DRAWRECT x+COS(a)*radius, y+SIN(a)*radius, 2, 2, col

NEXT ; INC radius ; DEC num ; DEC p,10 ; NEXT


SHOWSCREEN
KEYWAIT
WEND


Edit: Code tags are your friends /Moru :-)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-18
Im posting the "PAC MAN" code here that I lost interest with. There are a million such clones out there and this slowly sank into my mind.  So, I changed a few things, the ghosts see through walls (C`mon, Ghosts cant see through solid matter?) and home in on you - resulting in a very difficult challenge. I had planned a maze that took skill to master without loosing lifes but time/life/another clone of it etc put me off.

You will find in this code a prog that allows you to explore the maze with moving ghosts that hunt you.  Erm, thats all I`m afraid.  Ive substitued LOADSPRITE with bland blocks. 

Theres no pro code here folks, just a foundation I typed up over several evenings to get things running.

If any of you admire it, explore it and make/add changes.

Code (glbasic) Select

///////
The code
//////

// --------------------------------- //
// Project: PACMAN
// Start: Friday, February 17, 2012
// IDE Version: 10.244
SETTRANSPARENCY RGB(0,0,0) ; SETSCREEN 640,400,0
LOADFONT "smalfont.bmp",1
SETFONT 1
GLOBAL a,b,col ; c=10 ; col=RGB(255,255,20)
//////////////////////////
//// Title Screen
//////////////////////////
WHILE KEY(57)=FALSE

FOR a=0 TO 200
DRAWLINE 0,a-1,640,a-1,RGB(col+10/2+b,col+10+b,col+a+b)
DRAWLINE 0,400-a,640,400-a,RGB(col+10/2+b,col+10+b,col+a+b)
INC b,1
IF b=20 THEN b=0
NEXT

PRINT "SCAPEGHOST", 235,10
PRINT "After Eons of wandering aimlessly ",25,30
PRINT "around mazes, you decide you want out!",2,50
PRINT "By eating the Pills scattered around",15,70
PRINT "your shadow of a body will find a new",8,90
PRINT "existence within the world of man...",15,110
//// Yawn...not another fecking Pac Man Clone :)
PRINT "<SPACE>",250,300
//INC nextpage ; IF nextpage=500 THEN nextpage=0 ; GOSUB highscore

SHOWSCREEN

WEND

//// Maze stuff
ripple1=5 ; ripple2=20 ; count=1 ; syncgrafix1=10 ; wallsize=10 ; syncgrafix=5 ; effect1=10 ; count=0 ; effect=6
DIM map[31][17] ; GOSUB maze

score=0 ; t$="000"+score ; mdir=1 ; ans=0 ; anf=3

//// Player stuff
ghostspeed=8 ; playerspeed=5 ; px=11 ; py=7

game=1
animovementdelayount=1
ans=0 ; anf=3

GOSUB grafix

GOSUB setupghosts


///////////////////////////////////////////////
////////////////////////////////////////////////
/// MAIN LOOP
////////////////////////////////////////////////
///////////////////////////////////////////////
WHILE NOT FALSE

GOSUB domazebackground

GOSUB drawmaze

GOSUB movemuncher // & ghosts via a delay

GOSUB stats

SHOWSCREEN

WEND

////Routines



SUB drawmaze:

INC count,1
FOR y=0 TO 16
FOR x=0 TO 29

xx=x*wallsize+SIN(count+y*ripple1)*effect1 // For the walls
yy=y*wallsize+SIN(count+x*ripple1)*20 // For the walls

xxx=px*wallsize+SIN(count+py*ripple1)*effect1 // To Clip player and spooks to maze
yyy=py*wallsize+SIN(count+px*ripple1)*20 // Ditto

IF map[x][y]=-1 // -1=no pill, 0=pill

DRAWSPRITE 5,xx*2,yy*2

ENDIF

IF map[x][y]=0 // Draw pill

DRAWSPRITE 0,xx*2,yy*2

ENDIF

IF map[x][y]=1 // Maze Walls

col=RGB(COS(count+y*2+x*2.5)*100+100,SIN(count+y*5)*100+100,SIN(count+x*5)*100+100)
DRAWRECT xx*2+effect,yy*2+effect,wallsize,wallsize,RGB(COS(count+y*2)*100+100,SIN(count+y*5)*127+127,SIN(count+x*5)*127+127)

ENDIF

//DRAWANIM 3,image,xxx*2,yyy*2 // Draw Player
DRAWSPRITE 3,xxx*2,yyy*2
FOR a=0 TO 3

IF ghost[a].x=x AND ghost[a].y=y // Draw Spooks

DRAWSPRITE 4,xx*2,yy*2

ENDIF

NEXT
NEXT
NEXT

ENDSUB

SUB movemuncher:


IF KEY(203)
dirx=-1 ; diry=0
ENDIF


IF KEY(205)
diry=0 ; dirx=1
ENDIF

IF KEY(200)
diry=-1 ; dirx=0
ENDIF

IF KEY(208)
diry=1 ; dirx=0
ENDIF
////Check Lefy
IF dirx=-1 AND map[INTEGER(px-1)][INTEGER(py)]<>1

INC movementdelay ; IF movementdelay > playerspeed THEN DEC px ; GOSUB moveghosts

IF movementdelay = playerspeed + 1
dirx=0 ; movementdelay=0
ENDIF

ENDIF
////Check Right
IF dirx=1 AND map[INTEGER(px+1)][INTEGER(py)]<>1

INC movementdelay ; IF movementdelay > playerspeed THEN INC px ; GOSUB moveghosts

IF movementdelay = playerspeed + 1
dirx=0 ; movementdelay=0
ENDIF

ENDIF
////Check Down
IF diry=1 AND map[INTEGER(px)][INTEGER(py+1)]<>1

INC movementdelay ; IF movementdelay > playerspeed THEN INC py ; GOSUB moveghosts

IF movementdelay = playerspeed + 1
diry=0 ; movementdelay=0
ENDIF

ENDIF
////Check Up
IF diry=-1 AND map[INTEGER(px)][INTEGER(py-1)]<>1

INC movementdelay ; IF movementdelay > playerspeed THEN DEC py ; GOSUB moveghosts

IF movementdelay = playerspeed + 1
diry=0 ; movementdelay=0
ENDIF

ENDIF

ENDSUB


SUB moveghosts:

INC ghostdelay ; IF ghostdelay=ghostspeed+1 THEN ghostdelay=0
IF ghostdelay<ghostspeed
GOTO movethespooks
ENDIF

IF ghostdelay=ghostspeed
FOR a=0 TO 3

IF ghost[a].x<INTEGER(px) AND map[ghost[a].x+1][ghost[a].y]=0

ghost[a].x=ghost[a].x+1

ENDIF


IF ghost[a].x>INTEGER(px) AND map[ghost[a].x-1][ghost[a].y]=0

ghost[a].x=ghost[a].x-1

ENDIF


IF ghost[a].y>INTEGER(py) AND map[ghost[a].x][ghost[a].y-1]=0

ghost[a].y=ghost[a].y-1

ENDIF


IF ghost[a].y<INTEGER(py) AND map[ghost[a].x][ghost[a].y+1]=0

ghost[a].y=ghost[a].y+1

ENDIF
NEXT
ENDIF



movethespooks: // via the drawmaze

ENDSUB// set up ghosts


SUB setupghosts:

TYPE spook
x ; y ; im ; spooked ; dead
ENDTYPE

GLOBAL ghost[] AS spook
DIM ghost[4]



RESTORE ghostdata
// Set up xpos,ypos,anim image range, directionx/y, spooked(you ate the power pill,dead
FOR a=0 TO 3
READ aa,b,c,d,e
ghost[a].x=aa ; ghost[a].y=b ; ghost[a].im=c ; ghost[a].spooked=d ; ghost[a].dead=e
NEXT

STARTDATA ghostdata:

DATA 7,2,0,0,0
DATA 12,4,4,0,0
DATA 10,9,8,1,0
DATA 1,8,12,1,0

ENDDATA

ENDSUB


SUB stats:
// place checks here on maths
ENDSUB

SUB maze:

RESTORE screen

FOR y=0 TO 16
FOR x=0 TO 29

READ a
map[x][y]=a
IF a=5
map[x][y]=1

ENDIF
NEXT ; NEXT

STARTDATA screen:

DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,1,1,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,1,0,0,0,1,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,1,1,1,0,1,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,1,1,1,1,1,0,1,1,1,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,0,0,0,1,0,0,0,-1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,1,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,1,1,1,0,1,2,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,1,0,0,0,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,1,1,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
ENDDATA

ENDSUB


SUB domazebackground:



FOR a=0 TO 499

IF spot[a].y<300

DRAWRECT spot[a].x,spot[a].y,spot[a].zz,spot[a].zz,RGB(0,0,a)

ELSE

DRAWRECT spot[a].x,spot[a].y,spot[a].zz,spot[a].zz,RGB(0,10,a/10)

ENDIF

INC spot[a].zz,1

IF spot[a].zz>20
spot[a].zz=RND(5)
spot[a].x=RND(639)
spot[a].y=RND(399)
ENDIF

NEXT

ENDSUB

SUB grafix:

//LOADSPRITE "dot.bmp", 0
DRAWRECT 0,0,2,2,RGB(255,255,255)
GRABSPRITE 0,0,0,2,2
//LOADANIM "wall.b
//LOADANIM "player.bmp",3,22
DRAWRECT 0,0,22,23,RGB(255,255,0)
GRABSPRITE 3,0,0,22,23 // player
//LOADANIM "ghosts.bmp",4,24,24
DRAWRECT 0,0,22,23,RGB(0,255,255)
GRABSPRITE 4,0,0,22,23
//LOADSPRITE "nodot.bmp", 5
//LOADANIM "score.bmp",6,162,33
//Background
TYPE dot ; x ; y ; sx ; sy ; zz ; ENDTYPE

GLOBAL spot[] AS dot
DIM spot[1000]
FOR a=0 TO 999
spot[a].x=RND(639) ; spot[a].y=RND(399)
IF RND(1)=0
spot[a].sx=2
ELSE
spot[a].sx=-2
ENDIF

IF RND(1)=0
spot[a].sy=-2
ELSE
spot[a].sy=2
ENDIF
spot[a].zz=RND(5)
NEXT

ENDSUB




Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-18
I will sure check this out later.
That data statement there gives me itches as I use similar stuff to draw solaris map(board game) in a way that editing it creates newer maps.I took me ages to understand DATA capabilities back on the COCO days, so I´m quite found of its uses.

Don´t let down because of other/similar games, I´m sure you can beat others attempts or even better, add to the pot.
One successful ´pac man´ always open doors and call attention to other versions too.

You could make into a ROGUE LIKE PACMAN... such a game would make my day :booze:

But I´m just being cheerishable, I certainly understand the life/work/things/other ideas detracting us to pursue one idea. 
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: kanonet on 2012-May-18
I think forum *love*ed up your code a bit, can you put it in code blocks plz, so your formation is saved?
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Schranz0r on 2012-May-18
@I love my Brick:

PLS use the CODETAG!!!

the button with the "#", thx!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-20
Quote from: erico on 2012-May-18
I will sure check this out later.
That data statement there gives me itches as I use similar stuff to draw solaris map(board game) in a way that editing it creates newer maps.I took me ages to understand DATA capabilities back on the COCO days, so I´m quite found of its uses.

Don´t let down because of other/similar games, I´m sure you can beat others attempts or even better, add to the pot.
One successful ´pac man´ always open doors and call attention to other versions too.

You could make into a ROGUE LIKE PACMAN... such a game would make my day :booze:

But I´m just being cheerishable, I certainly understand the life/work/things/other ideas detracting us to pursue one idea.

Thanks buddy.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-20
Quote from: Schranz0r on 2012-May-18
@I love my Brick:

PLS use the CODETAG!!!

the button with the "#", thx!

Ouch. Erm, really sorry to have caused you distress. By the way, what does @ mean before my name?
Please dont shout as that is rude.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-20
Quote from: erico on 2012-May-15
That list is quite promising!
I´m particularly found of:

Shapes - vector images from my idea of what can help quickly to outline your idea
Built in animator.
Built in canvass - draw them on screen and see how they look - you can cut a group out and save them as oe sprite.

Things from some other places I find interesting:

light table for animations
stencil for the outlines, easier to color something?

I´m not really sure ´redo´ is needed, like if you have a spare screen or an animation set, you can use other frames to test variations. IMO

Again, it feels quite promising, how long till you believe it will be ready to ship?

Thanks for the input.

((All the routines I have described work. The fill routine was a right bugger though and held me back many evenings in coding it.  Setpixel can be very slow when measured by Getpixel....I found a work around that reduced my previous idea and allowed a fast fill inside a polygon.  I was left with a bugbear about GLBasic.))

Right now Im adding new ideas that have sprung from the development of this prog.

I try it out on my Son and Daughter and they tell me what needs to be added. (My Daughter told me to add stencils - pacman,invader,coin,diamond etc) My Son just loved it and really liked it when he saved his images and then printed them on screen.

So, I`m working with my kids on this one & sometimes they think out of the box and surprise me by thier idea.

Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-20
Quote from: I love my Brick on 2012-May-20
So, I`m working with my kids on this one & sometimes they think out of the box and surprise me by thier idea.

Best input in the universe! :good:
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-21
Great words!

Children love & embrace the world whilst we adults worry about it & the mistakes we make.

Ah well, back to my brick :) Just glad Im not a real priest - feck, that must be an even harder life. :)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Albert on 2012-May-21
I want this thread with lotsa of screenshots!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-23
Sure, I agree and that will happen. Just a few more tweaks and improvements to go - almost there. The more you complete something the more you find a way to stream line other areas of your code. I hate to say this but, Math is fun! If my younger self could see me now :D

I will remove the colour picker sound effect and all others before I submit the prog here.  The kids love the sound effects but us adults may find them distracting.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Albert on 2012-May-24
Quote from: I love my Brick on 2012-May-18
Im posting the "PAC MAN" code here that I lost interest with.

I've compiled it, nice stuff!

(http://dl.dropbox.com/u/292449/glbasic/img/pacman.jpg)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Albert on 2012-May-24
I've assembled the first few codesnippets into one bundle.

Also I've shot some screenshots:

Tunnel (http://dl.dropbox.com/u/292449/glbasic/img/tunnel.jpg)
Spiral1 (http://dl.dropbox.com/u/292449/glbasic/img/spiral1.jpg)
Spiral2 (http://dl.dropbox.com/u/292449/glbasic/img/spiral2.jpg)
PolySpiral2 (http://dl.dropbox.com/u/292449/glbasic/img/polyspiral.jpg)
Patterns1 (http://dl.dropbox.com/u/292449/glbasic/img/patterns1.jpg)
Patterns2 (http://dl.dropbox.com/u/292449/glbasic/img/patterns3.jpg)
Bat 'n ball (http://dl.dropbox.com/u/292449/glbasic/img/batnball.jpg)
Flag (http://dl.dropbox.com/u/292449/glbasic/img/flag.jpg)
Wormhole (http://dl.dropbox.com/u/292449/glbasic/img/wormhole.jpg)

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-25
Quote from: Albert on 2012-May-24
Quote from: I love my Brick on 2012-May-18
Im posting the "PAC MAN" code here that I lost interest with.

I've compiled it, nice stuff!

(http://dl.dropbox.com/u/292449/glbasic/img/pacman.jpg)

Thanks to albert.  You know, even though theres no game there - you can still find yourelf trying to outwit the stalkers when you try it out. Cheers Albert.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-25
Quote from: Albert on 2012-May-24
I've assembled the first few codesnippets into one bundle.

Also I've shot some screenshots:

Tunnel (http://dl.dropbox.com/u/292449/glbasic/img/tunnel.jpg)
Spiral1 (http://dl.dropbox.com/u/292449/glbasic/img/spiral1.jpg)
Spiral2 (http://dl.dropbox.com/u/292449/glbasic/img/spiral2.jpg)
PolySpiral2 (http://dl.dropbox.com/u/292449/glbasic/img/polyspiral.jpg)
Patterns1 (http://dl.dropbox.com/u/292449/glbasic/img/patterns1.jpg)
Patterns2 (http://dl.dropbox.com/u/292449/glbasic/img/patterns3.jpg)
Bat 'n ball (http://dl.dropbox.com/u/292449/glbasic/img/batnball.jpg)
Flag (http://dl.dropbox.com/u/292449/glbasic/img/flag.jpg)
Wormhole (http://dl.dropbox.com/u/292449/glbasic/img/wormhole.jpg)

Thanx for the slideshow Albert. I started the thread to show that it only takes a few lines of code to display an idea.  I kept the examples short with variables that could be changed/understood by the user. Its all simple stuff which I hope has helped to inspire others to try out the Basic for themselves( and mess with Math). No Functions, no complicated calls etc - just basic see & read, then alter.

When I release the Sprite Creator - called Hyper Sprite for now - I hope you enjoy it friend and find it useful.

Albert, I look forward to your next submissions with great interest. 
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-25
Quote from: erico on 2012-May-15
That list is quite promising!
I´m particularly found of:


light table for animations
stencil for the outlines, easier to color something?

Ive now added a stencil routine that ignores a colour  - stops painting over it.  Can also be used as a freehand fill.

Please explain light table for animations. I`m old :) but interested in you idea.

Cheers.

Mr Brick
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-25
Quote from: I love my Brick on 2012-May-25
Please explain light table for animations. I`m old :) but interested in you idea.

Is like having control of transparency overlay of frames around the current, for example, let´s suppose I´m drawing a walking cycle animation of my main caracter, only outline, I draw first frame, when advance to next one, the one before is there but untouchable on a 50% transparent level.
That way it is easy for people do draw a bit over the last frame, helps a lot on timing animations.

Some programs you can choose how many frames before and after the current one and a set o transparency decay.

Name Lightable comes from a traditional animator´s table that has similar effect.

PS:there is a pic of a more homebrew light table (also called light box maybe) on the left and the ´transparent´layer effect on a physical version.
   

[attachment deleted by admin]
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: matchy on 2012-May-25
It's cool looking.

So now just make it cooler by connecting the visuals into a spectrum analyzer :good:, if you can find the update lib for fmod.  :zzz:
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-25
Quote from: erico on 2012-May-25
Quote from: I love my Brick on 2012-May-25
Please explain light table for animations. I`m old :) but interested in you idea.

Is like having control of transparency overlay of frames around the current, for example, let´s suppose I´m drawing a walking cycle animation of my main caracter, only outline, I draw first frame, when advance to next one, the one before is there but untouchable on a 50% transparent level.
That way it is easy for people do draw a bit over the last frame, helps a lot on timing animations.

Some programs you can choose how many frames before and after the current one and a set o transparency decay.

Name Lightable comes from a traditional animator´s table that has similar effect.

PS:there is a pic of a more homebrew light table (also called light box maybe) on the left and the ´transparent´layer effect on a physical version.


Ahh, back in my day it was called the Onion skin effect.(That term sounds like summit Abe Simpson would say) I suppose spriting to mem and some feint darkening/tinting could be a start with that. I`ll give it a bash this weekend. 

A nice bit of homebrew DIY there Erico and I bet that saved you a few bucks.  DIY and me dont mix to well.  My last offering was a piece of wood that I had aimlessly banged nails into...cough... :D
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-May-25
Quote from: I love my Brick on 2012-May-25
Ahh, back in my day it was called the Onion skin effect...
...A nice bit of homebrew DIY there Erico and I bet that saved you a few bucks...

Yeah, onion skin is the name, I must have forgotten such since I am the "no onions no pickles" kind of human =D

That homebrew is not mine, I did assemble one long time ago but a lot more ugly then that, some chaps sells a similar great one every Animamundi festival though.
Since I have a wacom tablet and a scanner, I have no need to indulge in time consuming hand animation anymore.

It is great you are going to give a try!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-May-26
Heres my method of doing this.

1.First we need an image to trace over. (Sprite/BMP)

2.Make a copy & reduce its RGB.(Sprite2Mem - Mem2Sprite)

3.Expand the copy to a size easy to trace over. (ZoomSprite)

4.Get the mouse moving, with a cursor and measurement.

5.Each button press fills a new sprite(new sheet) with pixels.

6.This new (sheet) sprite is then expanded over the copy(s).

7.Creating a visual effect of drawing over the enlarged (original) copy.

8.Go back to 3

9.Create a "NEW SHEET" button to allow a new blank sprite. (Sheet)

9.Set the new sprite as the new sheet over the previous.

10. Display it below next to the other frames. (Like a movie strip)

11. Reduce the RGB of the copy, previous sprite (sheet) etc.

11. Draw them enlarged & return 3.

Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Albert on 2012-Jun-07
Quote from: I love my Brick on 2012-May-25

I started the thread to show that it only takes a few lines of code to display an idea.  I kept the examples short with variables that could be changed/understood by the user. Its all simple stuff which I hope has helped to inspire others to try out the Basic for themselves( and mess with Math). No Functions, no complicated calls etc - just basic see & read, then alter.

I'm totally understand it, and I tried to keep the original code as is, only breaked each of them into two pieces: initialize and process.
I see what you mean, and I'm also a fan of the one-file one-shot programs, could I suggest you http://cymonsgames.com/ (http://cymonsgames.com/)? This site contains lot of type-in programs, also you can submit your own (only c++ was in the past, but things changes). The site's favicon created by me! :D
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-09
Super nice Albert.  I will check out that site and enjoy every minute friend.

Ahh, back in the day when computer mags displayed black n white pics of games...and then you found the type-in section.  You brought back many memories my friend of times long past.  Lets not forget the POKE routines for cheating in games too...great times, long gone :) 

Cheers me dears!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Hemlos on 2012-Jun-11
Hi Brick, great visualizations for music!

I have an idea which can be implemented into your image editor..
Beziers lines, you know the bendy snake like lines in windows paint?
http://www.glbasic.com/forum/index.php?topic=3839.0
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-12
Thanks & yes I can see that - the beginning of a media player type thing.

I havnt implemented your suggestion into the code but it has crossed my mind in the past.  Another thing to put on my pen and paper list - page 2.  Completion of one routine always springs new ideas :)  I`m currently coding a symmetry type thingy like that found in Deluxe Paint. (Instead of one cursor on the grid you can now have more that move in relation to a central point.  Think SPIROGRAPH and you`ll understand what i mean)

 
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-12
Below: A simple example of what I`m adding to the Sprite/image editor.

///////////////////////////////////////////////////////////////////////////////////////////
// 16 lines of code
// mirror drawn image - use mouse with left button held down to paint.
// dont use RND inside the RGB as it slows things down.
///////////////////////////////////////////////////////////////////////////////////////////

GETSCREENSIZE w,h

GRABSPRITE 0,0,0,w,h

WHILE TRUE

DRAWSPRITE 0,0,0 // draw current display

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

IF b1=1 // button pressed

FOR a=0 TO 360 STEP 5 // change the "STEP" for different effects
SETPIXEL 300+COS(a+mx)*50+mx,200+SIN(a+my)*50+my,RGB(255,a,0)
SETPIXEL 300+COS(a+mx)*50-mx,200+SIN(a+my)*50+my,RGB(100,a,a)
SETPIXEL 300+COS(a+mx)*50-mx,200+SIN(a+my)*50-my,RGB(255,a,a/2)
SETPIXEL 300+COS(a+mx)*50+mx,200+SIN(a+my)*50-my,RGB(100,a,a/3)
NEXT

ENDIF

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

SHOWSCREEN

WEND
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-Jun-12
pretty good looking effect and mirrors.
kaleidoscopio especial!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-12
Hey Erico, I hope you manage to get Father Ted - you will love it and laugh! :D
////////////////////////////////////////////////////////////////////////////////////////////////////
Try using DRAWRECT in different sizes instead of SETPIXEL (like the tunnel thing I did)
E.G.: if xpos is at mx=100 enlarge DRAWRECT by two - a zoomed image.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
OR mutiply the SETPIXEL to 8 instead of 4 - toy with minus and plus within COS & SIN
/////////////////////////////////////////////////////
Hope it helps with your creative ideas - cos you will have ideas I cannot see.
/////////////////////////////////////////////////////////////////////////////////////////////////

Cheers

Mark
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-13
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
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-13
erm...or a strange new world :)
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-13
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.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-14
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!
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-14
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
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Hemlos on 2012-Jun-14
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.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-15
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
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Hemlos on 2012-Jun-15
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
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-15
Very nice Hemlos, reminds me of some kind of fossilised shell.
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Hemlos on 2012-Jun-15
Reminds me of vertigo

This thread belongs in the math section i think, how about you?
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-15
Yes I agree, now how do we move it?
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Hemlos on 2012-Jun-15
Well, we merely need to mention it i suppose!
Obviously, theres a little bird with an impecable sense of direction flying around the forums .
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-16
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.
 
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: Hemlos on 2012-Jun-16
No, it was another mod
Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: I love my Brick on 2012-Jun-16
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.





Title: Re: Toying with COS & SIN commands to produce 2D effects.
Post by: erico on 2012-Jun-16
Quote from: I love my Brick on 2012-Jun-16
I`m learning Hemlos to embrace this new platform via young guys like you.

I share this spirit. <3

Yesterday I re-learned math, about the dishes... :P
They do crop up on an exponential way don´t they?