Skip to content

SIPL_Mole

Thomas Konstantinovsky edited this page Dec 20, 2019 · 5 revisions

How To Work With SIPL-Mole

First of all an example of a main with a basic usage of MOLE:

#include "Mole.h"

#include <time.h>

  int main(void) {

Color_Palette CSET;  //creating a color palette for color choosing 
Mole test(1500, 1500, CSET.Black);  //creating a Mole object with a 1500X1500 frame with a black background
test.SetMoleColor(CSET.Azure);  //setting the mole color to azure
test.Set_Mole_Position(750, 450);  //setting the mole's position 

test.SetLineWidth(2);  //setting the width of the trail the mole will draw to 2

for (int i = 0; i < 550; i++) { 
	test.GoForward(450);//telling the mole to go forward 450 steps towards current angle (starting default 90)
	test.TurnLeft(175);//after 450 step turn left 175 degrees 
	test.SetMoleColor(CSET.Color_Serial_Number[i % 135 +2]);//change mole color (more about color usage at color wiki)
	
}


test.Write_Canvas("Test"); //Saving the canvas at project directory as Test.jpg 
system("Test.jpg"); //opening out saved image trough cmd
return 1;}

List Of Methods:

`	

   Mole(int const &canvas_width,int const &canvas_height,pixel const &background_color);

void Load_Canvas(int const &width, int const &height, pixel const &background_color);

void Write_Canvas(const char *file_name);

void Set_Mole_Position(int const &pos_x, int const &pos_y);

void GoForward(int const &distance);

void GoBackward(int const &distance);

void TurnRight();

void TurnRight(float const &degree);

void TurnLeft();

void TurnLeft(float const &degree);

void TurnAround();

void SetTarget(int const &pos_x, int const &pos_y);

void SetLineWidth(int const &width);

void Set_Angle_Radians(float const &angle);

void Get_To_Target();

void StampMole(pixel const &color);

void StampMole(pixel const &color,int const &StampID);

void SetMoleColor(pixel const &color);

void Print_Existing_Stamp_ID();

void Remove_Stamp(int const &stamp_id);

`

Usage Guidelines:

First of all create an object of type Mole, keep in mind when creating a Mole object it is recommended to specify all the contractor values in order to start working with your Mole instead of calling set functions.

Example,Creation Of A Mole Object:

Mole(int const &canvas_width,int const &canvas_height,pixel const &background_color);

Color_Palette PALET;
Mole ObjectName(640,1024,PALET.ColorChoice);

After creating the Mole object,a blank canvas with the size specified in the constructor is loaded to memory and the Mole is set to the center of the canvas. you can use:

void Set_Mole_Position(int const &pos_x, int const &pos_y);

to set your Mole position at any time. example:

ObjectName.Set_Mole_Position(500,500)

Keep in mind position has to be in image size boundaries.

Moving And Drawing

After there is a Mole object and everything is set up you can start moving the Mole to draw on your canvas, so how do you move the Mole.

The Mole works like a person with a paint bucket on his back, the paint bucket keeps leaking while the person is moving that way a trail is left any where the person has been. The same idea is implemented by the Mole object.

Example: ObjectName.GoForward(50) Or ObjetName.GoBackward(20)

that way we just moved our mole from our current position 50 step forward ,where is forward you ask ? well mole start at 0 or 2p degrees towards the right of the image, the mole will go 50 steps left and draw a line length of 1 (default) or any weight specified by ObjectName.SetLineWidth()

In order to change the direction the Mole looks at use one of the turning methods. call the method on the Mole object and specify the amount of degrees you wish to turn in the specified direction.

Example: ObjectName.TurnRight(90) Example_B: ObjectName.TurnLeft(31)

Note: not specifying an angle will automatically move the angle +90 degrees . Note: You can also hard-set any angle in radians by calling to angle set method example: Object_Name.Set_Angle_Radians(30*180/PI)

Also available is the TurnAround method which will flip the direction the mole is looking at. Use: ObjectName.TurnAround();

Stamps

You can use stamps to stick circle stamp on your canvas ,when the stamp method is called a circular stamp will be created on the current position of the mole. the created stamp can be created with an int ID as a parameter to the method ,or you can call it without passing the Id parameter in which case an ID will be given to the stamp automatically.

A stamp can be removed at any time by calling the remove method specifying the id of the stamp you want to remove.

example of stamp creation and removal:

ObjectName.StampMole(4,Palette.Red) 'or just' ObjectName.StampMole(Palette.Azure)

removal:

ObjectName.Remove_Stamp(4)

Note: if you lost track of your stamp id's you can call a method that will print to console all stamp id's and locations in order to get all alive stamps id's use : ObjectName.Print_Existing_Stamp_ID();

Writing Canvas To Project Directory

In any given time you can write you current process as a .jpg image to you project directory

usage: ObjectName.Write_Canvas("Thats_My_Drawing")
In project directory a file Thats_My_Drawing.jpg will be created.

Clone this wiki locally