Schranzors Rand und Gernots Kreis

Previous topic - Next topic


Code (glbasic) Select
fac = 50
  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)
  INC fac, 10
  IF fac > 500 THEN fac = 10

FUNCTION RAND: minimum, maximum
  RETURN minimum + RND(-minimum + maximum)


I <3 DGArray's :D

AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard


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:


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:,_cos,_tan.htm

Also i made a tutorial in this math section for using SIN and COS in circular math.
Bing ChatGpt is pretty smart :O


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.

For by grace are ye saved through faith, and that not of yourselves: it is the gift of God: Not of works, lest any man should boast. -Ephesians 2:8-9


Nice combination! Easy and good looking.

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

Code (glbasic) Select

FUNCTION QRND: b, e=0 , scale=1
LOCAL n = ABS(e-b)
RETURN b+ n/(scale*n)*RND(scale*n)

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


Useful, but with one problem:
QRND(100) returns values from 100-200 instead of 0-100...
QRND(n) returns values from n to 2*n instead of 0 to n...

Try this instead:
Code (glbasic) Select
FUNCTION QRND: b, e=0 , scale=1
LOCAL n = ABS(e-b)
RETURN e + n/(scale*n)*RND(scale*n)

I just replaced the b with the e  :P
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary