|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Payments Humor Music |
Build a graphical normal distribution, GWBASIC / BASICANORMAL.BAS drops a particle from the top center of the screen, and then makes random left/right decisions about which way to go on the way down, and as a result builds a normal distribution at the screen bottom. The comments below appear to indicate that instead of merely landing in piles that create a normal distribution, the particles also stick to each other if they find themselves adjacent. This is behavior from the diffusion limited aggregation simulation program. If desired, it should be easy to remove this DLA-like behavior from the small amount of code below, to restore the program to its original design. Originally written in GWBASIC for the Heathkit H-100 vintage computer, it will probably run in BASICA on any PC-compatible, with the trivial modification indicated in the code. Other versions:
|
10 'NORMAL.BAS 3-28-90 11 'COPYRIGHT (C)1990 STEVEN WHITNEY. 12 'Initially published by http://25yearsofprogramming.com. 13 'Published under GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY. 14 'BUILDS A NORMAL DISTRIBUTION AT THE BOTTOM OF THE SCREEN 15 '(THE DROPPED MARBLES ALSO SHOW THEIR TRAILS AS THEY FALL), BUT HAS THE 16 'STICKY ROUTINES FROM DLA, SO IT MAKES STRANGE TREELIKE FORMATIONS AT THE 17 'SCREEN BOTTOM, INSTEAD, IN A VAGUELY NORMAL DISTRIBUTION. 18 'SCREEN 12 : 'ENABLE FOR IBM BASICA 20 'SET CENTERPOINT 30 RANDOMIZE 40 CLS 90 'KEEP THIS LINE, A BORDER TO PREVENT GOING OUT OF BOUNDS 100 LINE (0, 479)-(639, 479), 1 110 'THIS REALLY SHOULD DRAW A CIRCLE AND START MOVING FROM A POINT ON IT 121 X = 320: Y = 1 130 PSET (X, Y), 4 140 'TEST TO SEE IF POINT IS NEXT TO ANOTHER POINT 150 TST = (POINT(X + 1, Y) OR POINT(X - 1, Y) OR POINT(X + 1, Y + 1) OR POINT(X, Y + 1) OR POINT(X - 1, Y + 1) OR POINT(X + 1, Y - 1) OR POINT(X, Y - 1) OR POINT(X - 1, Y - 1)) AND NOT 4 160 IF TST THEN PSET (X, Y), 7: GOTO 110 170 'PSET(X,Y),0 180 M = INT(RND * 2) 190 IF M = 0 THEN X = X + 1 200 IF M = 1 THEN X = X - 1 210 Y = Y + 1 270 'NO NEED FOR OUT OF BOUNDS TEST - BORDER TAKES CARE OF IT 280 GOTO 130
|
|
|
|
|
Copyright ©2011 Steven Whitney. Last modified Tue 05/24/2011 12:30:23 -0700. |
||