The basic concept of scrap_engine evolves around having a map that is basically a coordinate system that represents the column and rows in the console/terminal.
On this maps objects can be added, moved, and removed according to given rules.

Note: The most constructor/method arguments of class directly translate to their attributes and, with some exceptions (state, dynfps, type...), should not be manipulated directly.
There may be some method descriptions missing for some classes, that's because those methods are described in their mother classes description.
The basic map class to add scrap_engine.objects on.
Constructor.
- height:
intHeight of the map - width:
intWidth of the map - background:
StringDefault char, that will be used as the maps background - dynfps:
booleanIf changes of the map will be checked ascrap_engine.Map.show()
Shows a frame.
- init:
booleanForces printing
Resizes the map.
- height:
intNew height of the map - width:
intNew width of the map - background:
StringDefault char, that will be used as the maps background
Blurs another map as the background into the map
- blurmap:
scrap_engine.MapThe map to use as the background - esccode:
StringEscape code used to blur the blurmap
An object that can be added and moved on a scrap_engine.Map.
Constructor.
- char:
StringA string that represents to object on the map - state:
StringState"solid"or"float", that indices the behaviour of the Object."solid"means that not other objects can be put over the object,"float"means that it is possible. - arg_proto:
dictionaryA custom dictionary that can be passed to custom objects in, for examplescrap_engine.Text
Adds the object to a given map at a given coordinate.
- map:
scrap_engine.MapThe map the object should be added to - x:
intThe x coordinate the object will be set to - y:
intThe y coordinate the object will be set to
Sets the object to a given coordinate on the map. If this fails, the method will return 1.
- x:
intThe new x coordinate the object will be set to - y:
intThe new y coordinate the object will be set to
Removes the object from the map.
Redraws the object on the map.
Changes the char of the Object, that represents the object on the map.
- char:
StringThe new string that represents to object on the map
Method that is executed, when another object is laid over it self. This just works, if self.state = "float". This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
- ob:
scrap_engine.ObjectThe object, that is laid over self.
Method that's executed, when it's tried to lay this object over another object with self.state = "solid". This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
- ob:
scrap_engine.ObjectThe object, that self tried to be laid over - x:
intX coordinate of the object, that self tried to be laid over - y:
intY coordinate of the object, that self tried to be laid over
This method is executed when trying to set self over the left boarders of the map. This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
This method is executed when trying to set self over the right boarders of the map. This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
This method is executed when trying to set self over the top boarders of the map. This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
This method is executed when trying to set self over the bottom boarders of the map. This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
This method is executed when trying to move self from a place out of the boarders of the map to a place inside the boarders. This function returns nothing and does nothing, it can be used in custom daughter classes of scrap_engine.Object.
Sets the state of the Object.
- state:
StringThe new state ("float" or "solid")
More a meta class to organize scrap_engine.Objects and daughter objects to do certain actions with a group of those at once.
Constructor.
- obs:
list<scrap_engine.Object>The initial list ofscrap_engine.Objects.
Adds an scrap_engine.Object to the group.
- ob:
scrap_engine.ObjectA singlescrap_engine.Object, that's added to the list ofscrap_engine.Objects.
Adds a list of scrap_engine.Objects to the group.
- obs:
list<scrap_engine.Object>A list ofscrap_engine.Objects, that's added to the group.
Removes an scrap_engine.Object from the group.
- ob:
scrap_engine.ObjectThescrap_engine.Objectthat's going to be removed.
Moves all objects of the group with a given vector.
- x:
intX component of the vector - y:
intY component of the vector
Removes all scrap_engine.Objects in the group from the map.
Moves the group to a given coordinate. THIS JUST WORKS WITH DAUGHTER CLASSES, BECAUSE scrap_engine.ObjectGroup HAS NO COORDINATE BY IT SELF.
- x:
intThe new x coordinate the group will be set to - y:
intThe new y coordinate the group will be set to
Sets the state of the Object.
- state:
StringThe new state ("float" or "solid")
An easy way to generate text labels. This is a daughter class of scrap_engine.ObjectGroup and shares all its methods. Texts can be added together.
Method scrap_engine.Text.__init__(self, text, state="solid", esccode="", ob_class=Object, ob_args={}, ignore="")
Constructor.
- text:
StringThe text of the label. - state:
StringState"solid"or"float", that indices the behaviour of the Obeject."solid"means that not other objects can be put over the object,"float"means that it is possible. - esccode:
StringThe ansii escape code that can be used to colour the text or make it bold/italic... - ob_class:
classThe class of the objects in the label, that should be used. - ob_args:
dictionaryThis dictionary is passed asarg_prototo the objects. - ignore:
StringCharacter of objects that should be ignored not be added to the map.
Adds the text to a map.
- map:
scrap_engine.MapThe map the text should be added to - x:
intThe x coordinate the text will be set to - y:
intThe y coordinate the text will be set to
Removes the text from the map.
Changes the text of the text.
- text:
StringThe text of the label. - esccode:
StringThe ansii escape code that can be used to colour the text or make it bold/italic...
An easy way to generate rectangles. This is a daughter class of scrap_engine.ObjectGroup and shares all its methods.
Method scrap_engine.Square.__init__(self, char, width, height, state="solid", ob_class=Object, ob_args={}, threads=False)
Constructor.
- char:
StringThe character that's used in the rectangle - width:
intWidth of the rectangle - height:
intHeight of the rectangle - state:
StringState"solid"or"float", that indices the behaviour of the Object."solid"means that not other objects can be put over the object,"float"means that it is possible. - esccode:
StringThe ansii escape code that can be used to color the text or make it bold/italic... - ob_class:
classThe class of the objects in the label, that should be used - ob_args:
dictionaryThis dictionary is passed asarg_prototo the objects - threads:
booleanIf or if not threading should be used for generating the rectangle (useful for big rectangles)
Adds the rectangle to a map.
- map:
scrap_engine.MapThe map the rectangle should be added to - x:
intThe x coordinate the rectangle will be set to - y:
intThe y coordinate the rectangle will be set to
Changes char for the character of the rectangle.
- char:
StringThe new character of the rectangle
Changes the size of the rectangle.
- width:
intWidth of the rectangle - height:
intHeight of the rectangle
An easy way to generate frames. This is a daughter class of scrap_engine.ObjectGroup and shares all its methods.
Method scrap_engine.Frame.__init__(self, height, width, corner_chars=["+", "+", "+", "+"], horizontal_chars=["-", "-"], vertical_chars=["|", "|"], state="solid", ob_class=Object, ob_args={})
Constructor.
- height:
intHeight of the frame - width:
intWidth of the frame - corner_chars:
list<String>Chars used for frame corners, [lefttop, righttop, leftbottom, rightbottom] - horizontal_chars:
list<String>Chars used for horizontals, [top, bottom] - vertical_chars:
list<String>Chars used for verticals, [left, right] - state:
StringState"solid"or"float", that indices the behaviour of the Object."solid"means that not other objects can be put over the object,"float"means that it is possible. - ob_class:
classThe class of the objects in the label, that should be used - ob_args:
dictionaryThis dictionary is passed asarg_prototo the objects
Adds the frame to a map.
- map:
scrap_engine.MapThe map the frame should be added to - x:
intThe x coordinate the frame will be set to - y:
intThe y coordinate the frame will be set to
Moves the frame to a given coordinate.
- x:
intThe new x coordinate the frame will be set to - y:
intThe new y coordinate the frame will be set to
Method scrap_engine.Frame.rechar(self, corner_chars=["+", "+", "+", "+"], horizontal_char="-", vertical_char="|")
Changes char for the character of the rectangle.
- corner_chars:
list<String>Chars used for frame corners, [lefttop, righttop, leftbottom, rightbottom] - horizontal_chars:
list<String>Chars used for horizontals, [top, bottom] - vertical_chars:
list<String>Chars used for verticals, [left, right]
Removes the frame from the map.
Resizes the frame.
- height:
intHeight of the frame - width:
intWidth of the frame
A box to pack objects/groups/frames etc. into relative to a coordinate. This is a daughter class of scrap_engine.ObjectGroup and shares all its methods.
Constructor.
- height:
intHeight of the box - width:
intWidth of the box
Adds the box to a map.
- map:
scrap_engine.MapThe map the box should be added to - x:
intThe x coordinate the box will be set to - y:
intThe y coordinate the box will be set to
Adds an object/group etc. to the box.
- ob:
scrap_engine.Object/scrap_engine.ObjectGroupetc. The object/group that's added to the box - rx:
intThe x coordinate the object will be set to in the box - ry:
intThe y coordinate the object will be set to in the box
Sets an object to another coordinate in the box.
- ob:
scrap_engine.Object/scrap_engine.ObjectGroupetc. The object/group that's is - rx:
intThe new x coordinate the object will be set to in the box - ry:
intThe new y coordinate the object will be set to in the box
Removes the box from the map.
Resizes the box.
- height:
intHeight of the box - width:
intWidth of the box
An easy way to create a circle with a given radius, that's more like an ellipse. This is a daughter class of scrap_engine.Box and shares all its methods.
Constructor.
- char:
StringCharacter used for the circle - radius:
floatRadius of the circle - state:
StringState"solid"or"float", that indices the behaviour of the Object."solid"means that not other objects can be put over the object,"float"means that it is possible. - ob_class:
classThe class of the objects in the label, that should be used - ob_args:
dictionaryThis dictionary is passed asarg_prototo the objects
Changes char for the character of the circle.
- char:
StringThe new character of the circle
Changes the radius of the circle
- radius:
floatRadius of the circle
A line that can be drawn on the map, that's described by a vector. This is a daughter class of scrap_engine.Box and shares all its methods. The unrounded coordinates of the single points Objects of the line are passed in arg_proto to the Objects.
Method scrap_engine.Line.__init__(self, char, cx, cy, l_type="straight", state="solid", ob_class=Object, ob_args={})
Constructor.
- char:
StringCharacter used for the circle - cx:
floatX component of the vector - cy:
floatY component of the vector - state:
StringState"solid"or"float", that indices the behaviour of the Object."solid"means that not other objects can be put over the object,"float"means that it is possible. - l_type:
StringThe type the line should havestraightorcrippled - ob_class:
classThe class of the objects in the label, that should be used - ob_args:
dictionaryThis dictionary is passed asarg_prototo the objects
Changes char for the character of the line.
- char:
StringThe new character of the circle
Changes the vector of the line.
- cx:
floatX component of the vector - cy:
floatY component of the vector
A map that's background is a cut-out of another map. This is a daughter class of scrap_engine.Map and shares all its methods.
Constructor.
- bmap:
scrap_engine.MapThe map that's the background - x:
intThe x coordinate the map will be set to - y:
intThe y coordinate the map will be set to - height:
intHeight of the map - width:
intWidth of the map - dynfps:
booleanIf changes of the map will be checked ascrap_engine.Map.show()
Updates the background.
Moves the map to a given coordinate.
- x:
intThe new x coordinate the map will be set to - y:
intThe new y coordinate the map will be set to
A wrapper for scrap_engine.Submap.show() and scrap_engine.Submap.remap(self)
- init:
booleanForces printing
The CoordinateError is raised, when an Object is tried to add to an impossible coordinate. Its' attributes are:
- obj:
scrap_engine.ObjectThe Object that's tried to add - map_:
scrap_engine.MapThe Map the Object is tried to add to - x:
intThe x coordinate the Object is tried to add to - y:
intThe y coordinate the Object is tried to add to
This is just a simple example program that adds a an "a" to the coordinate (10|5) in the terminal.
import scrap_engine as se # imports scrap_engine
mymap = se.Map(background=" ") # defines mymap as a map as big as the terminal window with the background " "
myob = se.Object("a") # defines myob as an object with "a" as character
myob.add(mymap, 10, 5) # adds myob to mymap at (10|5)
mymap.show() # shows mymapAnother small example that moves the a in a line over the screen.
import scrap_engine as se # imports scrap_engine
import time
mymap = se.Map(background=" ") # defines mymap as a map as big as the terminal window with the background " "
myob = se.Object("a") # defines myob as an object with "a" as character
myob.add(mymap, 10, 5) # adds myob to mymap at (10|5)
mymap.show() # shows mymap
for i in range(5):
time.sleep(0.3) # waiting 0.3 seconds
myob.set(myob.x+1, 5) # sets myob to its own x coordinate +1 and y coordinate 5
mymap.show() # shows mymapAn example of the Text, Square and Frame class.
import scrap_engine as se # imports scrap_engine
mymap = se.Map(background=" ") # defines mymap as a map as big as the terminal window with the background " "
mytext = se.Text("Hello world") # defines a text as "Hello world"
myrectangle = se.Square(height=5, width=6, char="#") # defines a rectangle width height 5, width 6 and the character "#"
myframe = se.Frame(height=7, width=8, corner_chars=["┌", "┐", "└", "┘"], horizontal_chars=["─", "─"], vertical_chars=["│", "│"]) # defines a frame see scrap_engine.Frame
mytext.add(mymap, 0, 0) # adds mytext to (0|0)
myrectangle.add(mymap, 2, 2) # adds myrectangle to (2|2)
myframe.add(mymap, 1, 1) # adds myframe to (1|1)
mymap.show() # now a frame with a rectangle and a text above it should be shownAn example of a line across the screen with a moving "#" in it.
import scrap_engine as se
import time
map = se.Map(background=" ")
line = se.Line("a", 10, 5, type="straight") # makes a straight line described by the vector (10 5) with "a" as its char
line.add(map, 0, 0) # addes line to (0|0)
map.show()
for i in range(len(line.obs)): # list.obs is the list of all Objects that are part of the line
line.obs[i].rechar("#") # rechars the Object to "#"
if i != 0:
line.obs[i-1].rechar(line.char) # line.char is the default char of the line
time.sleep(0.4)
map.show()Example for a clock like line rotation.
import scrap_engine as se
import time, math
map = se.Map(background=" ")
line = se.Line("#", 0, 10) # downwards facing line of the vector (0 10)
line.add(map, 10, 10)
map.show()
# loops i until 360 and resizes the line with the vector (sin(i)*10 cos(i)*10)
for i in range(360):
line.resize(math.sin(math.radians(i))*10, math.cos(math.radians(i))*10)
time.sleep(0.05)
map.show()An example that shows how Texts are added.
import scrap_engine as se
map = se.Map(background=" ")
text1 = se.Text("Hey")
text2 = se.Text(" You!")
text1 += text2
text1.add(map, 0, 0) # Those two steps can even be switched
#>>> Hey You!