Open vzeddie opened 12 years ago
Pseudocode circle with radius r, centered at position x,y.
drawCircle(int r, int, x, int y){ for all x positions from -r to +r { let h be the height at this x position (from the circle equation x^2 + y^2 = r^2) draw a line from (x - radius + counter, y + h) to (x - radius + counter, y - h) } }
@acarrillo I need buttons that will allow a variable called "toolno" to cycle. Clicking a certain button will open up the line drawing tool while another button opens up the circle drawing tool. Also I need a button that will determine the radius of a drawn circle.
As of now, clicking the pen icon will switch to circle drawing mode or rectangle drawing mode and clicking anywhere else on the UI will revert it back to line drawing.
There are functions in graphics.c that will draw rectangles and another that will draw circles. But they are very crude right now.
Also, I don't know how I would create a fill tool.
Sure.
Here is another, more intuitive way that circle drawing might work: the user drags the cursor from one point to another, and that motion describes either the radius and a point on the circle, or a diameter of the circle. That way we only need one button for circle drawing.
On Mon, Jan 16, 2012 at 8:22 PM, azureity < reply@reply.github.com
wrote:
@acarrillo I need buttons that will allow a variable called "toolno" to cycle. Clicking a certain button will open up the line drawing tool while another button opens up the circle drawing tool. Also I need a button that will determine the radius of a drawn circle.
As of now, clicking the pen icon will switch to circle drawing mode or rectangle drawing mode and clicking anywhere else on the UI will revert it back to line drawing.
There are functions in graphics.c that will draw rectangles and another that will draw circles. But they are very crude right now.
Also, I don't know how I would create a fill tool.
Reply to this email directly or view it on GitHub: https://github.com/acarrillo/Cribble/issues/2#issuecomment-3521490
The problem is that is that clicking doesn't activate by clicking once. It continuously clicks. For example, if you hold down that pen size decrease button, it will continually decrease. It doesn't really allow the user to click just once, you know? So I think it would be easier to just set the radius with a slider or something. So now we have a drawCircle and drawRect function. They both work but they are...difficult to implement and making it user-friendly.
Is there a distinction between mouseup and mousedown that you can use? The mouse coordinates on mousedown are the center of the circle, and the coordinates on mouseup are a radius.
There is definitely a way to do it such that it will logically only click once. Pseudocode:
If circle tool selected, mouse is down and mouse_isDown == 0:
start drawing circle
initialCircleX = mouse.xcor
initialCircleY = mouse.ycor
mouse_isDown = 1;
else if mouse_isDown == 1:
Find the distance between initialCircleX and mouse.xcor, initialCircleY and mouse.ycor; these describe the circle to draw
else:
mouse_isDown = 0;
Does that make sense?
I guess it makes sense but I'm not too sure how to implement this in code. This code seems to cross between input.c and graphics.c. I tried a thing like what you said, Alex. I set a variable called 'iter' to increase after an initial xcor and initial ycor is selected, increment it, then click another point to draw from but it didn't work. I'll try it again some other time. We'll have time to do some of this stuff during class too so no worries. We're almost done anyway right? Almost everything from here on out is just optional and detailing, yes?
Also, I don't know how I would create a fill tool.
Making a "fill" tool would actually be a fun CS problem. I would recommend that you spread out from the clicked pixel in a "breadth-first search" manner, looking for pixels that are the same color as the one clicked. If a pixel is that original color, then change its color to be the new 'fill' color. Keep spreading about, with each pixel recursively (or iteratively) checking its neighbor's color. The recursive function would end when there are no more neighbors with the same color as the clicked pixel.
It's simple enough in my head but there is the problem of wanting to know what color the pixel is. Does the pixel know its color? If it doesn't then this won't work. I found SDL_getRGB but it's an odd function and I'm not too sure about what it does since it returns void.
Also, does anybody know when this is due?
I believe it sticks the rgb values into the last 3 parameters (which will be empty when you call the function). The middle parameter requires a little more research.
On Thu, Jan 19, 2012 at 10:49 PM, azureity < reply@reply.github.com
wrote:
It's simple enough in my head but there is the problem of wanting to know what color the pixel is. Does the pixel know its color? If it doesn't then this won't work. I found SDL_getRGB but it's an odd function and I'm not too sure about what it does since it returns void.
Also, does anybody know when this is due?
Reply to this email directly or view it on GitHub: https://github.com/acarrillo/Cribble/issues/2#issuecomment-3578811
My guess is that it stores the respective r, g, and b values at the locations of the the r, g, and b pointers that you pass in to the function. So you would do something like:
Uint8 r, g, b;
//pretend that pixel and fmt exist, and are the right thing
SDL_GetRGB(pixel, *fmt, *r, *g, *b);
printf("%d\n", r);
And no idea when it is due.
I managed to make a sort of "butterfly" tool. It symmetrically draws (line of symmetry is diagonal NW - SE).
ADD:
if (mouse.ycor >= 0) { /* TODO: Scale up from simple pen tool */ drawFilledRect(mouse.ycor-(tool_width/2), mouse.xcor-(tool_width/2), tool_width, tool_width, 0, 255, 255); }
into graphics.c after line 56.
But it's not very effective considering that there are some issues with the screen disappearing.