Solar System Hacked by Children

Give children your code and they will soon hack it for their own ends.  They will experiment and make changes.  Most often they will break it, but occasionally they will learn something new.

In this video, Sam has taken the solar system simulator and removed the part which removes the planets from the screen (so they can be redrawn at a slightly different location).  The effect is a rather nice trail following each planet.  If you leave it running for long enough you will result in a rather fetching work of 'modern art' which I am sure you could sell for thousands.



BB4W Source code:

     REM Solar System Simulator
     REM T Street
     REM 2014-11-25

     REM Hacked by Sam
     REM 2014-12-09
     
MODE 10  : OFF
     
REM screen dimensions
     
SCREEN_WIDTH% = 1440
     SCREEN_HEIGHT% = 1152

     REM -------------------------------------------
     REM STUFF TO MUCK AROUND WITH
     REM -------------------------------------------
     
SUN_RADIUS% = 300 : REM pixels
     
SUN_MASS% = 100   : REM relative units
     
PLANETS% = 30
     REM -------------------------------------------

     
BLACK% = 1 : COLOUR BLACK%, 0, 0, 0
     SUN_COL% = 2 : COLOUR SUN_COL%, 255, 255, 0
     PLANET_COL% =  3 : REM colour pot for planets
     
PLANET_MULT% = 4 : REM size of planet per unit of mass

     REM create the planet structure
     
DIM planet{(PLANETS%-1) x, y, dx, dy, mass, green%, blue% }

     REM randomly create planets
     
PROC_createPlanet( planet{()} )

     REM MAIN LOOP
     
REPEAT
       
*refresh off
       PROC_drawSun
       PROC_drawPlanets( planet{()} )
       *refresh
       WAIT 5
       PROC_move( planet{()} )
       PROC_gravity( planet{()} )
     UNTIL FALSE



     
DEFPROC_createPlanet( this{()} )
     REM creates random planets
     
LOCAL i%
     FOR i% = 0 TO PLANETS%-1
       this{(i%)}.x  = RND(SCREEN_WIDTH%)
       this{(i%)}.y  = RND(SCREEN_HEIGHT%)
       this{(i%)}.dx = RND(10)+5
       this{(i%)}.dy = RND(10)+5
       this{(i%)}.green% = RND(256)-1
       this{(i%)}.blue% = RND(256)-1
       this{(i%)}.mass = RND(10)
     NEXT
     ENDPROC


     
DEFPROC_drawSun
     REM draws the yellow star in center of screen
     
GCOL 0, SUN_COL%
     CIRCLE FILLSCREEN_WIDTH% DIV 2, SCREEN_HEIGHT% DIV 2, SUN_RADIUS%
     ENDPROC


     
DEFPROC_drawPlanets( this{()} )
     REM draw each planet
     
LOCAL i%
     FOR i% = 0 TO PLANETS% -1
       COLOUR PLANET_COL%, 0, this{(i%)}.green%, this{(i%)}.blue%
       GCOL 0, PLANET_COL%
       CIRCLE FILL this{(i%)}.x, this{(i%)}.y, this{(i%)}.mass * PLANET_MULT%
     NEXT
     ENDPROC


     
DEFPROC_move( this{()} )
     REM move planet due to its own velocity
     
LOCAL i%
     FOR i% = 0 TO PLANETS% -1
       this{(i%)}.x += this{(i%)}.dx
       this{(i%)}.y += this{(i%)}.dy
     NEXT
     ENDPROC


     
DEFPROC_gravity( this{()} )
     REM apply gravity to each planet from the sun
     
LOCAL distance
     LOCAL i% : REM iterator
     
FOR i% = 0 TO PLANETS% - 1
       distance = SQR( (SCREEN_WIDTH% DIV 2 - this{(i%)}.x)^2 + (SCREEN_HEIGHT% DIV 2 - this{(i%)}.y)^2 )
       IF distance<>0 THEN
         
this{(i%)}.dx += ( this{(i%)}.mass * SUN_MASS% * (SCREEN_WIDTH% DIV 2 - this{(i%)}.x) / distance^2 )
         this{(i%)}.dy += ( this{(i%)}.mass * SUN_MASS% * (SCREEN_HEIGHT% DIV 2 - this{(i%)}.y) / distance^2 )
       ENDIF
     NEXT
     ENDPROC