Im working on a paint program with layers like in photoshop, and im having some problems drawing the really smooth circles that photoshop do.
i've made a function for anti-aliasing if that's nessesary...
when selecting a quite big size on the airbrush in photoshop you get a nice gradient circle...when i made a function like this, it doesnt fill all the pixels it should and it fills some of them twice.
can you please help me with the code....
here's some of the code i use:
VB Code:
For Radius = 0 to TempRadius
For Angle = 0 to Pi2 Step 1 / Radius
X = Cos(Angle) * Radius
Y = Sin(Angle) * Radius
Next
Next
this will not draw gradient thou...but it draws a filled circle...
please help me fix this code.
look at this image...
the filled circle at the left is how i want it to look....(i can fix the gradient myself later on...)
the circle at the right is how it looks...
it's drawn with rgb(255,0,0) and 50% opacity....you can see that some pixels are drawn on top of each other...
Circle drawing works different. First you calculate the bounding square (or rectangle, for ellipses). The you go through it top down. For each line you calculate how many pixels to the left and right from the center you have to go and color them. You'll want to color each pixel seperatly to be ready for patterns and gradients.
It works like this:
Radius: 3
Center: (3,3)
Bounding Square: (0,0)->(6,6)
Code:
##
####
######
######
####
##
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
When you get to patterns or gradients, you simply have to calculate the color for each pixel just before setting it.
E.g. linear gradient from white to black, starting at 0,0 and ending at 6,6. Distance: sqrt(6*6+6*6)
Pixel at 2,2. Distance to gradient start: sqrt(2*2+2*2). Distance to gradient end: sqrt(4*4+4*4). This means it is one third to black. Pixel result is one third end color (RGB 0,0,0) and two thirds start color (RGB 255,255,255), resulting in ~ RGB 170,170,170. Set pixel 2,2 to this color. Advance to next pixel to be colored and repeat.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Originally posted by CornedBee If I may add: those computations are the reason why all serious drawing apps are written in C++: computations simply catch VB at its worst.
for x=sin(2*pi-angle) *radius to sin(angle)*radius
setpixel
next
next
it works pretty allright.
now there's another program with the layers.
they work, but they're really slow cus when adding a pixel to a layer i redim an 1d array and add the x, y, opacity, r, g, b values...
the problem here is when painting above another pixel that pixel gets drawn 2 times or even more times if you draw alot...
i want to make a loop that checks if 2 pixels are at the same x and y position and then mix them together (in the array) and then remove one of them.
how should this be done?
something like this:
VB Code:
for layer = 0 to layercount -1
for i = 0 to layers(layer).pixelcount-1
for j = 0 to layers(layer).pixelcount-1
if i<>j then
if layers(layer).pixels(i).x = layers(layer).pixels(j).x _
and layers(layer).pixels(i).y = layers(layer).pixels(j).y _
then
'fix pixels
end if
end if
next
next
next
how should the code for "fixing" the pixels be?
should i take the average of the 2 pixel colors?
how about the opacity? average too?
do you think that its better to make a 2d array for the pixels?
so i dont have to store the x and y...cus then i can "mix" the pixels when drawing them instead of making a huge loop-in-loop-in-loop to check all pixels...
i didnt look through your code but i think it would be easy if i just made a function that looks through the lines as a square and check if the distance from a point is closer than the radius.