Here is my drawing machine; it can draw lines and circles with white, blue, green or red on the black background.
Here is the coding for the drawing machine i have created.
float oldX; float oldY; void setup() { size(1200, 600); background(0, 0, 0); } void draw() { strokeWeight(2); smooth(); fill(255, 0, 0); rect(10, 10, 25, 25 ); fill(0, 0, 255); rect(35, 10, 25, 25 ); fill(0, 255, 0); rect(10, 35, 25, 25); fill(255); rect(35, 35, 25, 25); if(mousePressed) { if(mouseX > 10 && mouseX < 35){ if(mouseY >10 && mouseY < 35){ stroke(255, 0, 0); } if(mouseY>35 && mouseY < 60){ stroke(0, 255, 0); } } if(mouseX > 35 && mouseX < 60){ if( mouseY > 10 && mouseY <35){ stroke(0, 0, 255); } if(mouseY > 35 && mouseY < 50){ stroke(255); } } if(mousePressed){ line(mouseX, mouseY, oldX, oldY); } } oldX=mouseX; oldY=mouseY; } void keyPressed() { if (key == 'c') { background(0); } if (key == 'o') { noFill(); ellipse(mouseX, mouseY, 100, 100); } oldX=mouseX; oldY=mouseY; }
It took quite a while figuring out how I can make circles as I forgot that the last two numbers are supposed to be fore the radius (I thought they were for coordinates).
To improve this, I could either add more colours to it or provide different shapes or size of circle.