Author Topic: Maybe some fun, maybe not  (Read 3360 times)

0 Members and 1 Guest are viewing this topic.

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Maybe some fun, maybe not
« on: April 12, 2021, 06:59:11 am »
I was inspired today to write this silly simulation when I watched Fellippe's pandemic simulation video. It is not about the pandemic. It is about something different. It is not really a true simulation. It is a silly simulation. And hopefully it may also be fun. Some silly fun!
Code: QB64: [Select]
  1. TYPE OBJECT
  2.     sex AS INTEGER
  3.     age AS INTEGER
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.     vx AS SINGLE
  7.     vy AS SINGLE
  8.     dt AS INTEGER
  9.  
  10. DIM SHARED object(1000) AS OBJECT
  11.  
  12.  
  13.  
  14. SCREEN _NEWIMAGE(sw, sh, 256)
  15.  
  16.  
  17. Initialize
  18.  
  19. repeat = 1
  20.  
  21. WHILE repeat
  22.     CLS
  23.  
  24.     FOR i = 0 TO 999
  25.         IF object(i).age > 6000 THEN
  26.             object(i).sex = 0
  27.             _CONTINUE
  28.         END IF
  29.         IF object(i).sex = 1 AND object(i).age > 960 AND object(i).age < 5400 THEN
  30.             FOR j = 0 TO 999
  31.                 IF object(i).age > 6000 THEN
  32.                     object(i).sex = 0
  33.                     _CONTINUE
  34.                 END IF
  35.                 IF object(j).sex = 2 AND object(j).age > 960 AND object(j).age < 2760 THEN
  36.                     d = SQR((ABS(object(i).x - object(j).x) ^ 2) + (ABS(object(i).y - object(j).y) ^ 2))
  37.                     IF d < 13 AND object(j).dt = 0 THEN
  38.                         object(j).dt = 46
  39.                         FOR k = 0 TO 999
  40.                             IF object(k).sex = 0 THEN
  41.                                 object(k).sex = RND * 2 + 1
  42.                                 object(k).age = 0
  43.                                 object(k).x = RND * (sw - 24) + 12
  44.                                 object(k).y = RND * (sh - 24) + 12
  45.                                 EXIT FOR
  46.                             END IF
  47.                         NEXT
  48.                     END IF
  49.                 END IF
  50.             NEXT
  51.         END IF
  52.     NEXT
  53.  
  54.     FOR i = 0 TO 999
  55.         IF object(i).sex = 0 THEN _CONTINUE
  56.         object(i).age = object(i).age + 1
  57.         IF object(i).dt > 0 THEN object(i).dt = object(i).dt - 1
  58.         c = 11
  59.         IF object(i).sex = 2 THEN c = 13
  60.         object(i).vx = object(i).vx + RND * .1 - .05
  61.         object(i).vy = object(i).vy + RND * .1 - .05
  62.         object(i).x = object(i).x + object(i).vx
  63.         object(i).y = object(i).y + object(i).vy
  64.         IF object(i).x < 13 THEN object(i).vx = 1
  65.         IF object(i).x > sw - 13 THEN object(i).vx = -1
  66.         IF object(i).y < 13 THEN object(i).vy = 1
  67.         IF object(i).y > sh - 13 THEN object(i).vy = -1
  68.         CIRCLE (object(i).x, object(i).y), 12, c
  69.         'PAINT (object(i).x, object(i).y), c
  70.     NEXT
  71.  
  72.     IF INKEY$ = CHR$(27) THEN repeat = 0
  73.  
  74.     _LIMIT 60
  75.  
  76.     _DISPLAY
  77.  
  78.  
  79. SUB Initialize
  80.     FOR i = 0 TO 999
  81.         object(i).sex = 0
  82.     NEXT
  83.     FOR i = 0 TO 40
  84.         object(i).sex = 1
  85.         object(i).age = RND * 100
  86.         object(i).x = RND * (sw - 24) + 12
  87.         object(i).y = RND * (sh - 24) + 12
  88.  
  89.     NEXT
  90.     FOR j = i + 1 TO i * 2
  91.         object(j).sex = 2
  92.         object(j).age = RND * 100
  93.         object(j).x = RND * (sw - 24) + 12
  94.         object(j).y = RND * (sh - 24) + 12
  95.     NEXT
  96.  
My name is Michael, but you can call me Mike :)

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: Maybe some fun, maybe not
« Reply #1 on: April 12, 2021, 03:43:53 pm »
Sixty frames = one simulated year.

Changed the mechanics a bit. Added more color information.
Green - too young
Grey - too old
Pink - female
Blue - male
Solid Pink - take a guess

Things that affect the outcome.
Population density - the larger the starting population the more likely the simulation will sustain
Size of the circles - the larger they are the more plentiful will be the collisions
CONST min - The lower the more fruitful the society will be
CONST maxm - The higher "
CONST maxf - The higher "

The goal is to achieve simulation sustainability without too explosive growth and with not too many failures.

DISCLAIMER ABOUT THE CURRENT SETTINGS
It is just a numbers game. The settings are restricted to what is commonly possible. They are not 100% realistic. It is not meant to be politically correct. So just consider these settings being for a primitive society without written laws or moral standards.

The morally correct may want to increase the circle size and increase the minimum age! Etc.
Code: QB64: [Select]
  1. TYPE OBJECT
  2.     sex AS INTEGER
  3.     age AS INTEGER
  4.     x AS SINGLE
  5.     y AS SINGLE
  6.     vx AS SINGLE
  7.     vy AS SINGLE
  8.     dt AS INTEGER
  9.  
  10. DIM SHARED object(1000) AS OBJECT
  11.  
  12. CONST min = 750
  13. CONST maxm = 4800
  14. CONST maxf = 2760
  15.  
  16.  
  17.  
  18. SCREEN _NEWIMAGE(sw, sh, 256)
  19.  
  20.  
  21. Initialize
  22.  
  23. repeat = 1
  24.  
  25. WHILE repeat
  26.     CLS
  27.  
  28.     FOR i = 0 TO 999
  29.         IF object(i).age > 6000 THEN
  30.             object(i).sex = 0
  31.             _CONTINUE
  32.         END IF
  33.         IF object(i).sex = 1 AND object(i).age > min AND object(i).age < maxm THEN
  34.             FOR j = 0 TO 999
  35.                 IF object(j).age > 6000 THEN
  36.                     object(j).sex = 0
  37.                     _CONTINUE
  38.                 END IF
  39.                 IF object(j).sex = 2 AND object(j).age > min AND object(j).age < maxf AND object(j).dt = 0 THEN
  40.                     d = SQR((ABS(object(i).x - object(j).x) ^ 2) + (ABS(object(i).y - object(j).y) ^ 2))
  41.                     IF d < 13 THEN object(j).dt = 46
  42.                 END IF
  43.                 IF object(j).dt = 1 THEN
  44.                     object(j).dt = 0
  45.                     twins = RND * 250
  46.                     count = 0
  47.                     IF twins = 1 THEN count = 1
  48.                     FOR l = 0 TO count
  49.                         FOR k = 0 TO 999
  50.                             IF object(k).sex = 0 THEN
  51.                                 object(k).sex = RND * 2 + 1
  52.                                 object(k).age = 0
  53.                                 object(k).x = RND * (sw - 24) + 12
  54.                                 object(k).y = RND * (sh - 24) + 12
  55.                                 object(k).dt = 0
  56.                                 EXIT FOR
  57.                             END IF
  58.                         NEXT
  59.                     NEXT
  60.                 END IF
  61.             NEXT
  62.         END IF
  63.     NEXT
  64.  
  65.     FOR i = 0 TO 999
  66.         IF object(i).sex = 0 THEN _CONTINUE
  67.         object(i).age = object(i).age + 1
  68.         IF object(i).sex = 2 AND object(i).dt > 1 THEN object(i).dt = object(i).dt - 1
  69.         c = 2
  70.         IF object(i).sex = 1 THEN
  71.             IF object(i).age > min THEN c = 11
  72.             IF object(i).age > maxf THEN c = 7
  73.         END IF
  74.         IF object(i).sex = 2 THEN
  75.             IF object(i).age > min THEN c = 13
  76.             IF object(i).age > maxf THEN c = 7
  77.         END IF
  78.         object(i).vx = object(i).vx + RND * .1 - .05
  79.         object(i).vy = object(i).vy + RND * .1 - .05
  80.         object(i).x = object(i).x + object(i).vx
  81.         object(i).y = object(i).y + object(i).vy
  82.         IF object(i).x < 13 THEN object(i).vx = 1
  83.         IF object(i).x > sw - 13 THEN object(i).vx = -1
  84.         IF object(i).y < 13 THEN object(i).vy = 1
  85.         IF object(i).y > sh - 13 THEN object(i).vy = -1
  86.         CIRCLE (object(i).x, object(i).y), 12, c
  87.         IF object(i).sex = 2 AND object(i).dt > 0 THEN PAINT (object(i).x, object(i).y), c
  88.     NEXT
  89.  
  90.     IF INKEY$ = CHR$(27) THEN repeat = 0
  91.  
  92.     _LIMIT 60
  93.  
  94.     _DISPLAY
  95.  
  96.  
  97. SUB Initialize
  98.     FOR i = 0 TO 999
  99.         object(i).sex = 0
  100.     NEXT
  101.     FOR i = 0 TO 100
  102.         object(i).sex = 1
  103.         object(i).age = RND * 6000
  104.         object(i).x = RND * (sw - 24) + 12
  105.         object(i).y = RND * (sh - 24) + 12
  106.  
  107.     NEXT
  108.     FOR j = i + 1 TO i * 2
  109.         object(j).sex = 2
  110.         object(j).age = RND * 6000
  111.         object(j).x = RND * (sw - 24) + 12
  112.         object(j).y = RND * (sh - 24) + 12
  113.     NEXT
  114.  
My name is Michael, but you can call me Mike :)

Marked as best answer by romichess on April 12, 2021, 04:08:16 pm

Offline AndyA

  • Newbie
  • Posts: 73
    • View Profile
Re: Maybe some fun, maybe not
« Reply #2 on: April 12, 2021, 05:54:29 pm »
That's an interesting take on population growth and decline.

Maybe the solid pink circle should change to solid pink filled ellipses for a short time then be accompanied by smaller green circles. Then like all the others turn gray.