Coder Social home page Coder Social logo

3.3.for-loops's Introduction

For Loops Part 2

Today we will be continuing our examinination of for loops. Last class we discussed the basic structure of a for loop and how we could use this to draw iteratively in our programs.

For example, the loop shown below would draw cricles that are 100 pixels apart for the entire width of the page.

for(var x = 0; x < width; x += 100){
	ellipse(x, 100, 50, 50)
}

Tasks

Today we will be creating more complex drawings using for loops.

WARM-UP: Create the image shown below using a for loop. It should:

  • Start at the top of the page and stop at the bottom of the page
  • Repeat the same drawing every 100 pixels.

  1. Refactor your code from the warm up in order to create the drawing shown below. You should have targets drawn from the upper left corner to the lower right corner.

  1. Create a drawing that increments the x value by 5 times the amount of the y value. For example, if the y coodinate is 10, then the x coordinate would be 50.

  1. Use a for loop to draw two lines of circles:
  • One set of circles should go from left to right
  • One set of circle should go from the top of the page to the bottom.

  1. Use a for loop to draw two lines of circles:
  • One set of circle should go from the top of the page to the bottom.
  • One set of circles should form a diagonal from the upper left corner to the lower right corner

  1. Use a for loop to draw two lines of circles:
  • One set of circles should form a diagonal from the upper right corner to the lower left corner
  • One set of circles should form a diagonal from the upper left corner to the lower right corner

  1. Use for loop to create a page filled with a shape of your choice. For example, the image below has rows of white circles that were created using for loops.

  1. Add color to the drawing you created in problem 6. Have each row or column be its own distinct color. For example, the circle drawing for loop was updated to be columns of black and white.

  1. Make the color a random color every time a circle is drawn. This should result in circle being generated that are all a different RGB color.

  1. STRETCH: Try to put a conditional in your for loop (this can be a new one or any of the others you've written) so that all the shapes in a given row turn a color when the mouse is on the left side of the screen, and turn back when it's no longer there.

3.3.for-loops's People

Contributors

stevenjlance avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.