CS 105 - Understanding Our Algorithmic World

CS 105 - Assignment One

Goals

  • Demonstrate your ability to create custom blocks
  • Demonstrate you familiarity with spatial programming
  • Demonstrate your knowledge of the use of reporters and predicates

Challenges

Start a new editor session. Save the project as Assignment01. Please do all of your work in this project.

Draw polygons

In Exercise 3, you created some basic blocks to draw general a square and two other shapes. Now, I would like you to generalize that to write a block that can draw arbitrary n-sided polygons.

Expectations

  • You should create a block that looks exactly like this: draw polygon block
  • When run, the block should draw a polygon with the specified sides and side length
  • The block should run clean -- it should handle pen up and pen down so that the drawing draws, but the pen is raised at the end.

Draw a brick wall

I would like you to make a draw brick wall block. When called with the value 10, it should produce a wall that looks like this:

brick wall

To help you manage the complexity, I would like you to create three other custom blocks: draw brick, row A block, and row B block.

The row A block block should draw a line of 6 full bricks.

The row B block block should a line with 5 full bricks and two partial bricks on each end (careful -- they are not quite half size).

The draw brick block should draw a single brick. In my picture, the bricks are 30 long and 10 wide (or high), and the "cement" is 4 wide. The draw brick block should manage the pen color and raising and lowering of the pen.

Drawing filled rectangles We have already developed a technique for drawing rectangles. However, you should not use that here, as there is a simpler way when you want a filled rectangle. Simply set the pen size to the rectangle height you want and move forward by the length. If you try this, however, you will end up with something a bit lozenge shaped, because the pen adds round caps on both ends (which makes corners look better -- something we are not interested in here). We can turn that off.

Internally, the pen has a property called "flat ends" which is False by default. Use the set flat ends block in your brick block to switch on flat line ends. Turn it back off after the brick is drawn.

Expectations

To get full credit

  • You must create the four blocks
  • The draw brick block should draw a brick of the appropriate color and size (color is your choice)
  • The draw brick block should manage the pen. The pen should be raised at the end, and the flat ends settings turned back off.
  • The row A block block should draw a line of 6 full bricks
  • The row B block block should a line with 5 full bricks and two partial bricks on each end. The row should be exactly the same length as the row produced by the row A block block block
  • The spacing between rows should be the same as the spacing between bricks
  • The draw brick wall block should draw a brick wall of the input number of rows. However to make your life easier, we will only test even numbers of rows (so the wall will always start on a A row and end on a B row)
  • All blocks should match the posted images (same text and type)

Draw with the mouse

You can turn the sprite into a paintbrush by having it follow the mouse.

If you look at the options on the go to block, you will see one of the options is to go to the cursor. If you combine this with a forever block, the sprite will chase the mouse wherever you drag it. If the pen is down, it will leave a mark.

Note: you will need to make sure that the sprite itself is not draggable -- uncheck the "draggable" checkbox at the top of the screen above the script area.

Make a new block: paint with mouse block

When this block is run, the sprite should chase the mouse forever. If the mouse button is pressed, it should draw. if the user stops holding down the button, it will stop drawing.

To make this more interesting, imagine the stage is split into four equal regions. In each region, the sprite should paint in a different color (color choice is yours, though it should be easy to tell them apart).

Expectations

To get full credit

  • You must create a paint with mouse block
  • The sprite should follow the mouse, only drawing if the button is depressed
  • When the block is activated, the stage should clear.
  • The sprite will continue to be a paintbrush until the stop button is pressed
  • In each of the four regions of the screen, the sprite should use a distinct color (it is expected that the color will stretch into neighboring regions if the mouse is moved quickly).

Exceeding expectations

For this assignment, you can exceed expectations by improving the brick wall in the following ways:

  • draw brick wall should work correctly if the number of rows is even or odd
  • draw brick wall should take a second input which is the length of the wall in bricks (i.e., the number of bricks in an A row). As this will necessitate changes to the internal blocks, attempting this relaxes the final expectation that the block text matches.

Since I want to encourage play, I will also consider other modifications, however, an E score will be at my discretion. Ask if you want to make sure that your contribution is sufficient.

Submitting

Share the project using the instructions from exercise 1.

Visit the assignment page on Canvas to submit the URL.