Author Topic: Schranzors Rand und Gernots Kreis  (Read 11694 times)

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Schranzors Rand und Gernots Kreis
« on: 2008-Jan-10 »
Code: (glbasic) [Select]
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

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5116
  • O Rly?
    • View Profile
Schranzors Rand und Gernots Kreis
« Reply #1 on: 2008-Jan-10 »
cool ^^
I <3 DGArray's :D

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

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1622
  • Particle Hawk
    • View Profile
Re: Schranzors Rand und Gernots Kreis
« Reply #2 on: 2008-Aug-15 »
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.
« Last Edit: 2008-Aug-16 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline aonyn

  • Mr. Polyvector
  • ***
  • Posts: 136
    • View Profile
Re: Schranzors Rand und Gernots Kreis
« Reply #3 on: 2011-Feb-15 »
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
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

Offline monono

  • Mr. Polyvector
  • ***
  • Posts: 213
    • View Profile
    • Sockel Lernmedien
Re: Schranzors Rand und Gernots Kreis
« Reply #4 on: 2011-Feb-15 »
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)
ENDFUNCTION

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

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: Schranzors Rand und Gernots Kreis
« Reply #5 on: 2011-Feb-16 »
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)
ENDFUNCTION

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