How to draw lines without using any line functions.
in
Programming Questions
•
3 months ago
Hi all!
I have a bit of a challenging question to ask...
I'm making a paint editor with 10px wide cells and currently I have it set so every frame it colours the cell beneath the mouse red, but this leaves gaps between the previous and current mouse positions.
As I treat each cell as a rectangle, I cannot use the provided line(), vertex(), rect() etc. functions. I have simplified my program for the purpose of this question below:
- int wid, hei; //amount of cells on the canvas
- color[][] colours;
-
- void setup() {
- size(500, 500);
- noStroke();
- wid = int(width/10); hei = int(height/10);
- colours = new color[wid][hei];
- for (int x=0;x<wid;x++) {
- for (int y=0;y<hei;y++) {
- colours[x][y] = color(255, 232, 200); //setting all pixels to a cream colour
- }
- }
- }
-
- void draw() {
- //displaying all cells with the appropriate colour
- for (int y=0;y<int(height/10);y++) {
- for (int x=0;x<int(width/10);x++) {
- fill(colours[x][y]);
- rect(x*10, y*10, 10, 10);
- }
- }
- if(mousePressed&&!(mouseX==pmouseX&&mouseY==pmouseY)){
- newColour();
- }
- }
-
- void mousePressed(){
- newColour();
- }
-
- void newColour(){ //I might have to change the way this works
- if(mouseX>=0&&mouseX<width&&mouseY>=0&&mouseY<height){
- colours[int(mouseX/10)][int(mouseY/10)] = color(200, 0, 0); //set the pixel the mouse is currently positioned over to red.
- }
- }
In short, what would be the best way to make this:
Rather than this (which is what happens at the moment):
Any help will, as always, be greatly appreciated :)
1