Skip to content

Instantly share code, notes, and snippets.

@gmegidish
Last active January 12, 2020 20:29
Show Gist options
  • Save gmegidish/f108a8df352ae059ab4cd41df0037617 to your computer and use it in GitHub Desktop.
Save gmegidish/f108a8df352ae059ab4cd41df0037617 to your computer and use it in GitHub Desktop.
Welcome, traveller!
Here's your task for today --
- You are given a .shapes file format. Each line in this file represents a shape in an image.
- A shape can be a square, a rect, a circle, an ellipse, a line, polyline and polygon.
- Each shape has different arguments, the last argument is the color in which to paint (#rrggbb). See sample file below.
- There are no empty lines in this file, and list of shapes end when file ends.
Shapes and formats:
- sq <X> <Y> <STRIDE> <COLOR> # square
- rt <X> <Y> <WIDTH> <HEIGHT> <COLOR> # rect
- cl <X> <Y> <DIAMETER> <COLOR> # circle
- ln <X0> <Y0> <X1> <Y1> <COLOR> # line
- pl <X0> <Y0> <X1> <Y1> ... <Xn> <Yn> <COLOR> # polyline
You need to write a tool, that when executed as `php main.php input.shapes output.svg` will:
1. Create an svg file that represents these shapes, saved to disk.
2. Print out the sum of lengths of all shapes (length or circumference when applicable)
Take into consideration these points:
1. How easy will it be to add more shapes in the future?
2. How easy will it be to change output to be a png?
What we'd like to see:
1. Working software :)
2. Clean code and proper classes
3. Design patterns in use
4. Code-review (done together)
Good luck!
We're here for questions and help!
Enjoy the time and music.
-- Gil & TestFairy
==== file: "input.shapes" ========
sq 10 10 30 #000000
rt 60 10 10 10 #ff0000
cl 25 75 20 #00ff00
ln 10 50 110 150 #00ffff
pl 60 110 65 120 70 115 75 130 80 125 85 140 90 135 95 150 100 145 #ffff00
pl 50 160 55 180 70 180 60 190 65 205 50 195 35 205 40 190 30 180 45 180 50 160 #66ff66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment