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

#### erico

• Prof. Inline
• Posts: 2455
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #30 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?

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #31 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
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
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
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
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
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
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
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
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
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
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)
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)
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)
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)
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)
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)

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

SHOWSCREEN
KEYWAIT
WEND

Edit: Code tags are your friends /Moru :-)
« Last Edit: 2012-May-15 by Moru »
I like things and do stuff.

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #32 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.

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
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 "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
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

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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,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:

DRAWRECT 0,0,2,2,RGB(255,255,255)
GRABSPRITE 0,0,0,2,2
DRAWRECT 0,0,22,23,RGB(255,255,0)
GRABSPRITE 3,0,0,22,23 // player
DRAWRECT 0,0,22,23,RGB(0,255,255)
GRABSPRITE 4,0,0,22,23
//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

« Last Edit: 2012-May-18 by Schranz0r »
I like things and do stuff.

#### erico

• Prof. Inline
• Posts: 2455
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #33 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

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

#### kanonet

• Global Moderator
• Prof. Inline
• Posts: 772
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #34 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?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

#### Schranz0r

• Prof. Inline
• Posts: 4666
• O Rly?
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #35 on: 2012-May-18 »
@I love my Brick:

PLS use the CODETAG!!!

the button with the "#", thx!
I DGArray's

PC:
AMD Phenom II x4 @ 3.6ghz, 16gb 1600 Ram, HIS 7970 GHz Edition @3GB, Windows 7 64Bit

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #36 on: 2012-May-20 »
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

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

Thanks buddy.
I like things and do stuff.

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #37 on: 2012-May-20 »
@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.
I like things and do stuff.

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #38 on: 2012-May-20 »
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.

I like things and do stuff.

#### erico

• Prof. Inline
• Posts: 2455
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #39 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!

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #40 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.
I like things and do stuff.

#### Albert

• Dr. Type
• Posts: 253
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #41 on: 2012-May-21 »
I want this thread with lotsa of screenshots!

#### I love my Brick

• Mr. Drawsprite
• Posts: 61
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #42 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

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.
I like things and do stuff.

#### Albert

• Dr. Type
• Posts: 253
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #43 on: 2012-May-24 »
Im posting the "PAC MAN" code here that I lost interest with.

I've compiled it, nice stuff!

#### Albert

• Dr. Type
• Posts: 253
##### Re: Toying with COS & SIN commands to produce 2D effects.
« Reply #44 on: 2012-May-24 »
I've assembled the first few codesnippets into one bundle.

Also I've shot some screenshots:

Tunnel
Spiral1
Spiral2
PolySpiral2
Patterns1
Patterns2
Bat 'n ball
Flag
Wormhole