I have been given the go ahead to do chunk 46, which will be along the lines of lines. There isnt much on the subject of maths that my mind retains for long but one of the very few lessons that stuck was in Geometry and the subject was lines. I suppose that everyone was taught this lesson, and how by placing lines correctly on a grid produces curves. To me it is equivalent to the chemistry lesson where mixing 2 clear liquids produced a coloured one. It was on the strength of this long remembered concept, I decided to do Chunk 46.
To jog everyones memory we will repeat the lesson by placing lines along the x and y axes of a grid but we will be using Processing instead of squared paper and a sharp pencil.
int n=0;
void setup(){
size(400,400);
strokeWeight(1);
background(255);
}
void draw(){
line(0,n,n+10,height);
n+=10;
delay(200);
if(n>height){
n=0;
}}
Using Processing it has not taken us long to produce this sketch and not a smudge in sight! We even slowed it down by a fifth of a second, to help demonstrate what was happening!
Now we have produced our sketch, we decide to repeat the exercise, in the four corners of our screen. Unfortunately we dont have a calculator to work this out for us and we have to calculate the beginning and ending of each line in the virtual graph.
line(0,n,n+10,height);
Fortunately we have a pattern to guide us, in the code we used to create the first sketch. We can see that the pattern starts at zero across and a variable n, which increases by ten each time the draw method is exited and reexecuted. The end coordinate is the value of n+10 and is always the height of the screen downwards. To make our next pattern at the bottom right corner we know the first coordinate should start at the width of the screen across and have n pixels down. On each iteration, the point should have a variable number across and a fixed value equal to the height of the screen. If we are careful not to hard code any of the integers used to draw our sketch, this will mean our code can run in any size of window.
The way we coded the pattern sketch was ok to demonstrate the lines being drawn but we shall place the code in a for loop now, as we are using steps to increment the value of the gaps between the lines.
Try to calculate the statements needed to draw the other three patterns. The mathematically minded can use their free time to come up with some other patterns to use in their program and those whose mathematics are more artistic will come up with loads of new patterns as they try to work out the numbers.
Add a function to change the stroke colour each time the draw loop repeats. The finished sketch should look like the illustration and hopefully you will have thought up some new patterns, which we shall use in the next section.
Tuesday, 31 March 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment