# .----------------------------------[ icedragon@quickfox.org ]--. # # | sample-portgen.py | FS2 Portrait Generation Script [EXAMPLE] | # # |--------------------------------------------------------------| # # | This script aims to demonstrate how to work with LIBFS2 and | # # | create 10 95x95 shapes in an FS2 file with random data. It's | # # | not really useful, but may help you understand the library | # # | we use for this. Feel free to share, change and distribute. | # # `--------------------------------------------------------------' # ###--# Imports #--### # Imports the two classes we'll use - FS2_File and FS2_Shape along # with FLAG_ENCODED pseudo-constant. from libfs2 import * from random import randint ###--# Startup #--### # Assign an FS2 file class to a variable so we can deal with it. fs2 = FS2_File() # How big will each shape be (width,height)? dimensions = (95,95) # Generating 10 shapes. for nShape in range(10): # Forming a new shape instance and initializing to a 95x95 image. shape = FS2_Shape( dimensions ) # Since this is an FS2, we need to form an order of our own so all the shapes # here won't be replacing shape 0 in some FSH file. We can do it, but it's not # nice. ;) shape.shpReplace = nShape # Storing random colors all over the space. area = randint(2,30) # To make it nicer, we'll use different color areas. Each area has 8 colors. for x in range(dimensions[0]): for y in range(dimensions[1]): shape.setPixel( (x,y), (8*area) + randint(0,8) ) # Shape generation complete - add it to the list of shapes in the file. fs2.shapes.append( shape ) # Adding a tail to the file for personalization. Not a good thing, but Furc won't mind... ;) fs2.tail = "Created by Artex/IceDragon [http://icerealm.theden.ws/info/]" # When all is done, save the FS2 file to disk and terminate. fs2.saveFile('portgen.fs2') print "Done."