Friday, July 27, 2012

DSDN 142: A Good Number Of Variables...?

Today I re-wrote my entire code, because I realised that for ideal transformations to happen, the code needed to be written from the centre of the canvas, as opposed to from point (50, 50), which is in the top left corner and doesn't really benefit me much.

Since in my last iteration of my code I wrote the whole thing with a grand total of 2 variables, I also wanted to re-write the code in such a way that it would allow me to do exactly what I wanted to it.

So I re-wrote it with these variables instead:

---------------------------------------------------------------------------------
int xp = 250; //CENTRE POINT
int yp = 250; //CENTRE POINT
int offset = 0; //OFFSET VARIABLE

int wid1 = 150; //X-DISTANCE FROM CENTRE TO OUTER DIAGONALS
int wid2 = 50; //X-DISTANCE CONTROLLING SIZE OF DIAGONALS
int wid3 = 50; //X-DISTANCE AND SIZE OF TOP CHEVRONS
int wid4 = 100; //X-DISTANCE FROM CENTRE TO LOCUS OF ARCS

int hei1 = 50; //Y-DISTANCE FROM CENTRE TO OUTER DIAGONALS
int hei2 = 50; //Y-DISTANCE CONTROLLING SIZE OF DIAGONALS
int hei3 = 50; //Y-DISTANCE AND SIZE OF CHEVRONS
int hei4 = 100; //Y-DISTANCE FROM CENTRE TO LOCUS OF ARCS

float diam = (sqrt(20000)); //DIAMETER OF ARCS
float diam2 = (sqrt(2)); //SPECIAL CIRCUMSTANCE
---------------------------------------------------------------------------------

The reason for having multiple variables all with the value of 50 is out of a necessity to be able to control separate lines of the code. I'll now show what each part of the equation impacts.

---------------------------------------------------------------------------------
CODE UNCHANGED FROM ORIGINAL
---------------------------------------------------------------------------------


---------------------------------------------------------------------------------
int xp = 350; //CENTRE POINT SHIFTED 100PX TO THE RIGHT
-----------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------
int yp = 350; //CENTRE POINT SHIFTED 100PX DOWN
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int wid1 = 200; //X-DISTANCE FROM CENTRE TO OUTER DIAGONALS CHANGED BY 50PX
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int wid2 = 100; //X-DISTANCE CONTROLLING SIZE OF DIAGONALS CHANGED BY 50PX
As you can see, I've linked the size of the outer diagonals and the central x. I felt it was appropriate to link them.
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int wid3 = 100; //X-DISTANCE AND SIZE OF CHEVRONS CHANGED BY 50PX
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int wid4 = 150; //X-DISTANCE FROM CENTRE TO CENTRE OF ARCS CHANGED BY 50PX
This change doesn't affect the top and bottom arcs because there is no change from their location to the centre in terms of x.
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int hei1 = 100; //Y-DISTANCE FROM CENTRE TO OUTER DIAGONALS CHANGED BY 50PX
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int hei2 = 100; //Y-DISTANCE CONTROLLING SIZE OF DIAGONALS CHANGED BY 50PX
Again, these two sets of lines seemed appropriate to link.
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int hei3 = 100 //Y-DISTANCE AND SIZE OF CHEVRONS CHANGED BY 50PX
If I want to control these two aspects of the chevrons independently, I can still input values myself into the line data.
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
int hei4 = 150; //Y-DISTANCE FROM CENTRE TO CENTRE OF ARCS CHANGED BY 50PX
For the other two arcs, they don't actually have a y-component that changes from the centre point.
-----------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------- 
float diam = (sqrt(40000)); //DIAMETER OF ARCS CHANGED BY 58.58PX
If I want to control each arc separately, I can input the data manually.
-----------------------------------------------------------------------------------------

So now with all those changes update, I can get onto some creating for my final project!

No comments:

Post a Comment