#Nature of code - Gaussian Noise #********************************** # The graph shows consecutive random numbers with a normal distribution, meaning that they tend to cluster around the mean with a certain variance. # A large veriance will approach pure random noice, while a small variance will produce a lot less small or large values # Where in BasicNoise, we remap the rand values 0 to 1 to height/2 plus or minus 150, here we create values with a mean of height/2 and variance 50 # Because we use seed(123456), every time you run this program, you will get the same values # Change the seed or completely omit it to get different random values at every run. Change the variance to influence the 'spread' of returned values # #Setup gosub ScreenSetup gosub RandomSetup gosub GraphObjectSetup #Draw while 1 gosub UpdateGraphObject end while ScreenSetup: Fastgraphics width=800 height=400 graphsize width,height color black rect(0,0,width-1,height-1) return RandomSetup: seed(123456) dim randmov(width/2) mean = height/2 sigma = 50 # variance / spread of the bell curve return GraphObjectSetup: oldx=0 oldy= height/2 for i = 0 to width/2-1 u1 = rand u2 = rand z = sqrt(-2*log(u1)) * cos(2*pi*u2) randmov[i] = mean + z * sigma color white line(oldx,oldy,i*2,randmov[i]) oldx = i*2 oldy = randmov[i] next i refresh return UpdateGraphObject: oldi=0 oldy=randmov[0] #shift values left for i = 0 to 398 randmov[i] = randmov[i+1] next i #create new Gaussian value u1 = rand u2 = rand z = sqrt(-2*log(u1)) * cos(2*pi*u2) randmov[399] = mean + z * sigma #draw graph for i = 0 to width/2-1 color white line(oldi,oldy,i*2,randmov[i]) oldi = i*2 oldy = randmov[i] next i refresh pause 0.05 color black rect(0,0,width-1,height-1) return