Ok, this code should convert normal code into 20-line format (with 25 commands per line as per the stated rules).
input "Please enter name of dba file to compress (without extension): ",filename$
open to read 1,filename$+".dba"
dim storeline$(20)
linenumber=1
for linenumber=1 to 20
for commandnumber=1 to 25
read string 1,stuff$
if stuff$>"" then storeline$(linenumber)=storeline$(linenumber)+stuff$+":"
if stuff$="" and file end(1)=0 then dec commandnumber
next commandnumber
next linenumber
close file 1
if file exist (filename$+"_compressed.dba") then delete file filename$+"_compressed.dba"
open to write 2,filename$+"_compressed.dba"
for linenumber=1 to 20
write string 2,storeline$(linenumber)
next linenumber
close file 2
print "Compression complete"
wait key
Short but sweet!
Here's some example code to try it out on:
sync on
sync rate 40
autocam off
position camera 0,0,-150
hide mouse
color backdrop rgb(0,0,255)
ink rgb(255,0,0),0
box 0,0,1,1
get image 1,0,0,1,1
ink rgb(255,255,255),0
box 0,0,1,1
get image 2,0,0,1,1
make object box 1,100,15,1
texture object 1,1
make object box 2,15,100,1
texture object 2,1
make object box 3,100,25,1
position object 3,0,0,.1
texture object 3,2
make object box 4,25,100,1
position object 4,0,0,.1
texture object 4,2
make object box 5,150,15,1
zrotate object 5,-45
position object 5,0,0,1
texture object 5,2
make object box 6,150,15,1
zrotate object 6,45
position object 6,0,0,1
texture object 6,2
make object box 7,150,5,1
zrotate object 7,45
position object 7,0,0,.5
texture object 7,1
make object box 8,150,5,1
zrotate object 8,-45
position object 8,0,0,.5
texture object 8,1
for ob=1 to 8
set object light ob,0
next ob
sync
get image 3,screen width()/2-130,screen height()/2-130,screen width()/2+130,screen height()/2+130
for ob=1 to 8
delete object ob
next ob
omega#=8
amp#=2.0
rows=50
columns=50
elasticity#=0.2
a=5
b=5
damping#=0.7
position camera 70,55,0
point camera rows/2,0,columns/2
hide light 0
set ambient light 0
make light 1
position light 1,10,10,10
color backdrop 0
num=rows*columns
dim obnum(rows+1,columns+1)
dim v#(rows,columns)
make matrix 1,rows,columns,rows,columns
for x=1 to rows
for z=1 to columns
obnum(x,z)=ob
ob=ob+1
next z
next x
prepare matrix texture 1,3,rows,columns
tile=1
for x=rows-1 to 0 step -1
for z=0 to columns-1
set matrix tile 1,z,x,tile
inc tile
next z
next x
do
y#=amp#*sin(theta#)
theta#=theta#+omega#
set matrix height 1,rows-a,b,y#
for x=0 to rows
for z=5 to columns
if x<rows
distxp1#=get matrix height(1,x+1,z)-get matrix height (1,x,z)
endif
if x>1
distxm1#=get matrix height(1,x-1,z)-get matrix height (1,x,z)
endif
if z<columns
distzp1#=get matrix height(1,x,z+1)-get matrix height (1,x,z)
endif
if z>1
distzm1#=get matrix height(1,x,z-1)-get matrix height (1,x,z)
endif
vectorsum#=distxp1#+distxm1#+distzp1#+distzm1#
a#=vectorsum#*elasticity#
v#(obnum(x,z))=v#(obnum(x,z))+a#
v#(obnum(x,z))=v#(obnum(x,z))*damping#
set matrix height 1,x,z,get matrix height(1,x,z)+v#(obnum(x,z))
if get matrix height(1,x,z)>amp#*2
set matrix height 1,x,z,amp#*2
endif
if get matrix height(1,x,z)<-amp#*2
set matrix height 1,x,z,-amp#*2
endif
next z
next x
update matrix 1
if get matrix height (1,rows/4,columns/4)>amp#/2 or get matrix height (1,rows/4,columns/4)<-amp#/2
if damping#>0.6
dec damping#,0.0008
endif
else
if damping#<0.72
inc damping#,0.0005
endif
endif
text 0,40,"damping: "+str$(damping#)
sync
loop
For those who can't figure out what to do with the two bits of code - it's very straight forward:
You just need to save the compression code as a project, in its own folder. You then save the example code as a source file (dba) in the same folder.
Once run, code save the compressed version as another dba file with "_compressed" after the file name.
Limitations:
-it won't work for code which has functions
-it wont work for code which uses if-thens .... you must use if-endifs instead.
-it wont' work if the code has rems or ` symbols to remark text
Btw, those are not bugs in my code, they are just things you can't do when stacking multiple commands on one line.
It does, however, know to skip over empty lines!
Anyone who wants to use my code as their starting point for this challenge is welcome to - for example, dealing with if-thens by turning them into if-endifs should be reasonably straight forward I would think.