13
2
You just invited a liberal arts major to your house and you're telling him/her
"You know, I am a great programmer and I can do x and y and z..."
S/he quickly gets bored and asks you:
"If you really are a great programmer, can you make a programme to let me draw, I just need to draw lines on the screen by using the mouse, and selecting different colours in any manner".
Your code may import standard libraries. Your code may require the colours to be selected via the keyboard.
This is code-golf; shortest code wins.
Bullet points
The lines are drawn by moving the mouse around while pressing the left button.
Bresenham's Line Algorithm is not necessary any built-in algorithm will do the trick
If the user can change the line thickness in any way you get a * 0.8 bonus but it is not obligatory.
I guess it should be nicer to implement the line-drawing ourselves, but if you want you can import a library for that just say it in the code description.
The minimum is 5 different colours (red,green,blue,white,black). If you make them change randomly you get a penalty of *1.2. You may change them in any way you may want (both buttons and key presses are OK).
Drawing them pressing the mouse between to points or freehand would be best (i.e. as you do in paint) and gives you a bonus of *0.7 , but any other method is okay: (example) click two points and draw a line between those points?
The drawing canvas has to be 600x400
Changing the colour should change the colour only of the lines that will be drawn in the future.
Implementing a "Clear All " command is not obligatory but if you implement that you get *0.9 bonus.
Doesn't
*0.8
reduce original score to 80%? – Tomáš Zato - Reinstate Monica – 2016-02-02T13:01:17.0632
How are lines required to be drawn? Bresenham's Line Algorithm? Do the lines need to be variable thickness? Do we need to implement the line-drawing ourselves? Please specify more. And it is normally assumed that our code may "import standard libraries". How many colors must be choosable? Is 2 okay? Or how about randomly choosing color every time a keyboard button is pressed?
– Justin – 2014-11-20T22:40:02.5472Some more clarifications needed: How are the lines drawn? Do you click two points and draw a line between those points? How big does the drawing canvas have to be? How many colors must be supported? Can changing the color also change the color of every other line? Etc. This challenge is currently very underspecified. – Doorknob – 2014-11-20T22:53:02.847
@Quincunx I have put a Q & A in the question tell me if it is ok now. – Caridorc – 2014-11-21T10:28:54.457
2>
@steveverrill I made an error "while clicking the left button" – Caridorc – 2014-11-21T12:29:36.547
2>
The currently accepted answer does not implement drawing in white. Does the question need to be changed to make clear that the listed colours (red,green,blue,white,black) are not required, and it is only the number of colours which counts, or does the accepted answer need to have its score adjusted for not providing all of the required colours? – trichoplax – 2014-11-22T12:08:52.873
@githubphagocyte if you like, you may switch
purple
forwhite
, and save a byte in the process. There are shorter solutions now anyway; the accepted answer should be changed. – primo – 2014-11-22T14:39:00.310