Jump to content

GDI+ & randoms problems


Red ochre

Recommended Posts

I have written a plugin to be called 'Facet'. I have run into 3 problems - one of which I have solved!

I do not think the first two are solvable, but would like to be proved wrong.

Feel free to criticize the coding too - (not too harsh!)

Here is a link to the VS2010 project file and a .dll (fully stable - just not perfect - try it on an object - works well on faces!)

http://i.imgur.com/hVuGZ7P.png

VS2010 project file = https://www.dropbox.com/s/z9fcnmpvnicsfwh/FacetVSproject.zip?dl=0

.dll = https://www.dropbox.com/s/kvqk3mqp1sgi8t7/Facet.zip?dl=0

Problems:

---------------------------------------------------------

1. Gaps between antialiased filled paths.

http://i.imgur.com/qnlRfko.png

I have tried filling the whole figure first with minimal success but this also ruins the antialiasing on the edges of the figure. (try last checkbox). I can't cover the join with a line (as I did on Dryad) since I am using linear gradient brushes.

Increasing the size of the path either results in skewing the figure or means huge amounts trigonometry. The problem is most easily seen with a small number of cells with a contrasting layer below.

Any ideas?

(I think the antialiasing is applied to wrong side of the bounding line - it should be adding AA'd pixels to the outside of the path in my opinion.)

---------------------------------------------------------

2. Randoms not changing quickly enough resulting in patterns around the 'Nadir'.

http://i.imgur.com/L7xM6Mn.png

I have tried delay loops between calling the randoms, 'Thread.Sleep', even storing the randoms in an array in a different order from which I am using them. Nothing works. It is most obvious with the controls on default settings except for size randomness, which produces concentric 'waves' around the nadir. See pic.

Since it is less obvious when position randomness is increased, I am less worried about this.

---------------------------------------------------------

3. Solved - but thought it may help others.

I was getting an 'out of memory error' and thought it was a problem with my disposing of graphics objects - it wasn't!

The PointFs for a linear gradient brush must be atleast 1 pixel apart. Not being equal is not enough.

psuedo:

if(here == there){don't use a LGBrush;}//doesn't work

if((Math.Abs(here.X - there.X) > 1||(Math.Abs(here.Y - there.Y) > 1)){you can use LGBrush;}//does work

--------------------------------------------------------

I will probably publish this soon (with the faults), unless anyone can see a soloution, particularly for problem 1.

Also please report any crashes (now problem 3 is solved it has been very stable for me).

Many thanks

  • Upvote 2

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Perfect! - problem 1 solved. :)

Thank you so much - this really improves the effect and will be a useful technique for other plugins too.
You are a genius and a gentleman! B) - I was tying myself in knots trying to solve that one. :roll:
I will tidy up the code a bit and publish very soon.

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

I haven't tested this yet 'cause I'm not home but what if you changed

 

                    float Randsize = (float)(myrandoms[c, 2]) / 500;//between 0 and 2 roughly
                    float Randapexh = (float)(myrandoms[c, 3]) / 500;
 
to 
 
                    float Randsize = (float)(myrandoms[c, 2]) / 500f;
                    float Randapexh = (float)(myrandoms[c, 3]) / 500f;

 

read below

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

I think I found it

I believe since this variable is not a local variable it's not initialized null but as a default

 

private static Random RandomNumber;

 

so this never executes

 
            if (RandomNumber == null)
            {
 
                RandomNumber = new Random((instanceSeed) ^ (randomSeed << 16) ^ (rect.X << 8) ^ rect.Y);
            }
 
 
Post Edit 

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

I tried simply removing the "if(RandomNumber == null)" condition - just leaving
"RandomNumber = new  Random((instanceSeed) ^ (randomSeed << 16) ^ (rect.X << 8) ^ rect.Y);"

Unfortunately this still shows the patterns around the nadir. The RandomNumber seems to be same for all 'cells' with the same distance value?

I also tried moving "RandomNumber = new Random((etc" to inside the loop that loads the array. The circular pattern is still there? Even tried altering the algorithm to include the loop counter,'r', so different for each loop. Still no joy.

I can only think that the C# I write and the JIT code that gets compiled, execute in a different order perhaps?
Way out of my depth again!

Don't worry about this TR - I will publish with the non-random randoms. They're good for making circular mountain scapes! :lol:

And many thanks again for solving problem 1 - that makes a huge difference.
 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

 

What post?

:lol:

Reminds me of the sign "This is not here" at the  beginning of the Imagine video.

Yes - TR was very helpful and together we spotted the flaw in my code.

I was mixing a random number with a calculated one and instead of creating a new variable for the result it was feeding the altered calculated value back into the algorithm in the next loop. Resulting in radial patterns around the Nadir.

So Problem 2 now also solved! B)

I've got to tidy up the code and hopefully publish soon (real life rather busy at the moment).

Thanks again TR - really useful having someone experienced to bounce ideas off. :beer:

 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...