Codesnippets > Math

Schranzors Rand und Gernots Kreis

**Quentin**:

--- Code: (glbasic) ---LIMITFPS 20

fac = 50

WHILE TRUE

FOR i = 0 TO 359

x = fac * SIN(i) + 320

y = fac * COS(i) + 240

SETPIXEL x + RAND(-5, 5), y + RAND(-5, 5), RGB(128, 128, 128)

SETPIXEL x + RAND(-10, 10), y + RAND(-10, 10), RGB(176, 176, 176)

SETPIXEL x + RAND(-20, 20), y + RAND(-20, 20), RGB(208, 208, 208)

SETPIXEL x + RAND(-30, 30), y + RAND(-30, 30), RGB(240, 240, 240)

SETPIXEL x + RAND(-40, 40), y + RAND(-40, 40), RGB(255, 255, 255)

NEXT

INC fac, 10

IF fac > 500 THEN fac = 10

SHOWSCREEN

WEND

FUNCTION RAND: minimum, maximum

RETURN minimum + RND(-minimum + maximum)

ENDFUNCTION

--- End code ---

**Schranz0r**:

cool ^^

**Hemlos**:

Very Cool, i like both, the rand function and the sprites.

Not to be picky, but this is the math section afterall...

Standard Math for SIN and COS are as follows:

COS()x

SIN()y

If you switch them, your angles get transformed incorrectly, and result in a 90 degree transformation.

Typically all 0 angle naturally point to the right, as with all standard math, writing, and technology.

In this case it doesnt matter because it is used in a full circles.

If you use this function with standard angles and non circles,

it is recommended you standard the math for debugging and cross referencing information.

SIN COS TAN Defined:

http://www.gcseguide.co.uk/sin,_cos,_tan.htm

Also i made a tutorial in this math section for using SIN and COS in circular math.

**aonyn**:

Hi Hemlos,

Thanks for posting that link to your math guide.

I just looked through several sections, and it is all very well explained and easy to follow.

regards,

Dave

**monono**:

Nice combination! Easy and good looking.

I am going to shamelessly use this thread to advert my beloved little rand function =D

--- Code: (glbasic) ---FUNCTION QRND: b, e=0 , scale=1

LOCAL n = ABS(e-b)

RETURN b+ n/(scale*n)*RND(scale*n)

ENDFUNCTION

--- End code ---

Examples:

QRND(20) - nothing special, like RND(20)

QRND(20,100) - numbers between 20 and 100

QRND(20,100,10) -numbers between 20 and 100 and 10 steps from one number to the next one 20,20.1...99.9,100

and so on..

Works with negative numbers, too.

How cool is that, uh? =D

Navigation

[0] Message Index

[#] Next page

Go to full version