Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // exercise: draw random horizontal lines that start at the left border and end at the right border
- // creating a variable to hold the y value of the line (the distance from the top)
- var y = 0;
- function setup() {
- // defining the size of the canvas, in pixels
- createCanvas(900, 600);
- background(50, 100, 150);
- // slowing down the sketch to 5 frames a second
- frameRate(5);
- }
- function draw() {
- // the whole canvas will be redrawn every frame
- //background(50, 100, 150);
- // stetting the stroke to white: stroke(255,255,255) can be replaced by stroke(255)
- stroke(255);
- // a new random line will be drawn every frame
- //line(random(width), random(height), random(width), random(height));
- // a new random height is being selected every frame
- y = random(height);
- // print y value to the console, just as a test
- println(y);
- // this y value is used for both points in the line statement
- // x1 is set to 0 to have the line start at the left border and x2 to width to have it end at the right border
- line(0, y, width, y);
- // idea: comment out the background statement in the draw() function
- // idea: comment out the frameRate statement in the setup() function or increase its value
- // variation of the exercise: have random vertical lines starting on the top and ending at the bottom
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement