6 kyu

Canvas Fun #2: Draw Rectangles

Description:

Welcome to Canvas Fun ;-) In this series, we'll learning how to draw the image on a canvas.

Task

Given twoRectangles, your task is to draw them on the canvas. The color of rectangles should be "blue", and if two rectangles have a intersecting part, this part should be "black" color.

twoRectangles is given by a 3D integer array. looks like this:

[[[0,0],[70,70]],[[30,30],[99,99]]]

- [0,0] and [70,70] are the x,y coordinates of 
  two diagonal points of the rectangle1.

- [30,30] and [99,99] are the x,y coordinates of 
  two diagonal points of the rectangle2.

It's guaranteed that the two points are in the diagonal position(no same x coordinates and y coordinates), but it's NOT guarantee that it's always be the main diagonal(may be the vice diagonal) and their order is also random. ;-)

The basic canvas(always 100 x 100 pixel),background color(white) are already difined in the initial code(please don't delete or modify them).

You just need to draw the rectangles, use the following two methods:

fillStyle(colorCode)

Set the color of fill action. colorCode can be a Hex string, such as "#ffffff","#000000"; Or a word of color, such as "white","black","gray".

In this kata, we using "blue" as the color of rectangles, and "black" as the color of intersecting part.

fillRect(x,y,width,height)

Coordinate x,y as the top-left coner of rectangle, drawing a rectangle of size width x height.

Example

For twoRectangles = [[[0,0],[70,70]],[[30,30],[99,99]]], the output image should be:

Intersecting part should be "black", other parts should be "blue".

For twoRectangles = [[[10,10],[90,90]],[[40,40],[60,60]]], the output image should be:

Rectangle2 inside rectangle1.

For twoRectangles = [[[10,10],[30,30]],[[60,60],[80,80]]], the output image should be:

There is no intersecting part.

Puzzles
Graphics

Stats:

CreatedMay 27, 2017
PublishedMay 27, 2017
Warriors Trained348
Total Skips9
Total Code Submissions573
Total Times Completed62
JavaScript Completions62
Total Stars19
% of votes with a positive feedback rating89% of 27
Total "Very Satisfied" Votes21
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • ZED.CWT Avatar
Ad