2021-11-22
Short quiz confirming knowledge
-
(xer) The function
xer :: (Double, Double) -> (Int, Int)
gives the grid coordinates of the square that contains the given coordinates. (See image.)The grid squares have side length 4. There is a grid with one square is centered at (-6.5,-6.5), another at (-6.5,-2.5), and more filling in the space.
For example,
xer (-6.4,-5.9) == (0,0)
andxer (6.5,2.5)==(3,2)
.
import CodeWorld
centers :: [(Double, Double)]
centers = [(x,y) | x<-[0..3], y<-[0..3]]
draw1 (x,y) = translated (f x) (f y) $ rectangle 4 4
where f w = 4*w-6.5
main = do
putStrLn $ show checks
drawingOf $ pictures $ coordinatePlane : map draw1 centers
checks = [ True ]
-
(Barbell) Make an
activityOf
in CodeWorld that has a solid orange rectangle with two blue circles, one on each end of the rectangle.- The width of the rectangle depends on the x-coordinate of the mouse. One of the vertical sides of the rectangle is at exactly the x-coordinate of the mouse.
- The radius of the circles depends on the y-coordinate. Initially the radius the distance of the mouse from the x-axis. However, the radius is restricted to never be less than 2 or more than 5.
-
(Tic-Lights) There is a 4x4 grid of orange squares, like the one used in question 1 above. Each has side length 4. Clicking in a square toggles its color between orange and blue.