Advertisement
xeromino

sketch01_b

Oct 17th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // exercise: draw random horizontal lines that start at the left border and end at the right border
  2.  
  3. // creating a variable to hold the y value of the line (the distance from the top)
  4. var y = 0;
  5.  
  6. function setup() {
  7.   // defining the size of the canvas, in pixels
  8.   createCanvas(900, 600);
  9.   background(50, 100, 150);
  10.   // slowing down the sketch to 5 frames a second
  11.   frameRate(5);
  12. }
  13.  
  14. function draw() {
  15.   // the whole canvas will be redrawn every frame
  16.   //background(50, 100, 150);
  17.   // stetting the stroke to white: stroke(255,255,255) can be replaced by stroke(255)
  18.   stroke(255);
  19.   // a new random line will be drawn every frame
  20.   //line(random(width), random(height), random(width), random(height));
  21.   // a new random height is being selected every frame
  22.   y = random(height);
  23.   // print y value to the console, just as a test
  24.   println(y);
  25.   // this y value is used for both points in the line statement
  26.   // 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
  27.   line(0, y, width, y);
  28.  
  29.   // idea: comment out the background statement in the draw() function
  30.   // idea: comment out the frameRate statement in the setup() function or increase its value
  31.   // variation of the exercise: have random vertical lines starting on the top and ending at the bottom
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement