Tuesday, 14 April 2009

Vertex Functions Part 4

As can be seen from figure 4, the output couldn't be any different. There are a few things to note from this coding. First of all I changed the function name to triangleExplosion(), this could have been left as star() however it is a good idea to have meaningful names for functions in order to give some idea of what the function does.

The fill function has two arguments, the first argument, random(225,255), sets a colour with the value being randomly selected from the values between 225 and 255. The second argument set as 150 deals with the transparency of the colouring, enabling the triangles drawn underneath to still be visible.

Finally random integers are created to randomly pick which array coordinates are chosen to form the triangles.


Anti-aliasing

As mentioned previously the function smooth()needs further explanation. The use of this function anti-aliases the output. In other words this is a function to minimize the distortion viewed by an image. The smooth function basically, as it's name suggests smooths the edges of the images displayed by the running of the coding. In order to see this lets have a look at this simple example;


code 7 ;

size(300,300);

strokeWeight(2);

background(0);stroke(255);

fill(random(225,255),150);

float x = 0.3;

for(int i = 0; i<4;>

if (x > 0.5){

smooth();

ellipse(width*x,height*x,width/2,height/2);

}

else{

ellipse(width*x,height*x,width/2,height/2);

}

x = x + 0.12;

}




Figure 5: Circles and Anti-aliasing

The example above (code 7) should be very familiar too you by now. First of all the size of the output is set, along with the thickness of the drawn lines, by the use of the strokeWeight() function. The background is set to black and the stroke colour is set to white stroke(255) so its easy to show the differences. The fill function is used to colour in the drawn shapes and I have opted to add some transparency on to further help define the edges. I wanted to draw four circles so a for statement is used to create the four circles at differing positions, where the use of the if statement controls which shapes will appear with anti-aliasing on or off.

As we can see from the example (figure 5) the two circles drawn in the top right have the ant-aliasing function off, which is the default setting in processing. In order to switch it on the function smooth() must be added. This is the case for the two circle's toward the bottom right. If you notice the difference in outline producing a smooth flowing circle when anti-aliasing is switched on. However this function can have an impact on the performance of the coding as the anti-aliasing calculations take time.

No comments: