Jump to content

Plugin Suggestion: Random Dot Generation


Recommended Posts

Ok, so I was thinking about Photoshop brushes. You can set the scatter amount and stuff, which leads to random dots all over the place. Would it be possible (or practical may be the better word) to make a plugin that generates dots randomly? I've done something similar to what I mean with Flash here.

... ... ...

Well, there's my suggestion/request.

maker.jpg

ActionScript is infinitely different than any of the C languages, but on the offchance it helps, here's the scripting used to generate the dots.

if (_root.incolor == "random") {
for (i=0; i<_root.amount; i++) {
	var t = this.attachMovie("dot", "dot"+i, i);
	t._x = Math.random()*600;
	t._y = Math.random()*500;
	t._xscale = Math.random()*200+20;
	t._yscale = t._xscale;
	t.myColor = new Color("dot"+i);
	t.myColor.setRGB(random(999999));
}
} else {
for (i=0; i<_root.amount; i++) {
	var t = this.attachMovie("dot", "dot"+i, i);
	t._x = Math.random()*600;
	t._y = Math.random()*500;
	t._xscale = Math.random()*200+20;
	t._yscale = t._xscale;
	t.myColor = new Color("dot"+i);
	t.myColor.setRGB(_root.dotcolor);
}
}

Link to post
Share on other sites

Like this?

Here's the CodeLab source - I even commented it! :D

int Amount1=250;	//[1,1000]Amount
int Amount2=25;	//[0,1000]Minimum Size
int Amount3=50;	//[1,1000]Maximum Size
//submenu:Render

//=======================================================
//This is all so repeating the effect with Ctrl+F shows up different
//Only works when compiled - not within CodeLab
private byte instanceSeed = unchecked((byte)DateTime.Now.Ticks);
private int seedCount = 0;
private int Seed;

protected override void OnSetRenderInfo(EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs)
{
   this.Seed = seedCount ^ instanceSeed;
   seedCount++;
}
//=======================================================

unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
   Random r = new Random(this.Seed);

   //create a GDI+ graphics object
   Graphics g = Graphics.FromImage(dst.CreateAliasedBitmap());

   //enable antialiasing
   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

   //there's no point rendering outside of our given bounds
   g.Clip = new Region(rect);


   //=====================================================================
   //This is copies the source to the destination canvas - optimized for speed
   //So don't worry too much about understanding it - there are easier ways to do it
   for (int y = rect.Top; y     {
       ColorBgra* srcptr = src.GetPointAddressUnchecked(rect.Left, y);
       ColorBgra* dstptr = dst.GetPointAddressUnchecked(rect.Left, y);
       for (int x = rect.Left; x         {
           dstptr->Bgra = srcptr->Bgra;

           srcptr++;
           dstptr++;
       }
   }
   //====================================================

   for (int i = 0; i     {
       //==========================================
       //the try/catch block is in case the user selects a minimum higher than the maximum
       //as we don't want something so trivial to cause a crash
       int size = 0;
       try 
       {
           //determine the size
           size = r.Next(Amount2, Amount3);
       }
       catch { }
       //========================================

       //location...
       Point pt = new Point(r.Next(Math.Abs(src.Width - size)), r.Next(Math.Abs(src.Height - size)));

       //we're rendering in grayscale, so only need one byte
       byte color = (byte)r.Next(256);

       //create our brush
       Brush b = new SolidBrush(Color.FromArgb(color, color, color));

       //draw!
       g.FillEllipse(b, new Rectangle(pt.X, pt.Y, size, size));

       //clean up our resources
       b.Dispose();
   }
}

I didn't want to over complicate things, so it only renders in grayscale. You'll have to use other methods to color them. Personally, I think Gradient mapping would be easiest and most flexible, but to each his/her own.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to post
Share on other sites

Bug:

Minimum Size > Maximum Size = No Dots...

Edit:

Got this when I increased the max value higher than the hieght. Image was 800x600.

File: C:\Program Files\Paint.NET\Effects\RandomDots.dll
     Effect Name: PaintDotNet.Effects.UserScript
     Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.ArgumentOutOfRangeException: 'maxValue' must be greater than zero.
Parameter name: maxValue
  at System.Random.Next(Int32 maxValue)
  at PaintDotNet.Effects.UserScript.Render(Surface dst, Surface src, Rectangle rect)
  at PaintDotNet.Effects.UserScript.Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, Int32 startIndex, Int32 length)
  at PaintDotNet.Effects.BackgroundEffectRenderer.ThreadFunction()
  --- End of inner exception stack trace ---
  at PaintDotNet.Effects.BackgroundEffectRenderer.Join()
  at PaintDotNet.Effects.BackgroundEffectRenderer.Start()
  at PaintDotNet.Menus.EffectMenuBase.<>c__DisplayClassa.b__8(Object sender, EventArgs e)

 

Take responsibility for your own intelligence. ;) -Rick Brewster

Link to post
Share on other sites

Well, I know that.

You should link the max value to the min value when the min meets or exceed the max...like in "Add Noise".

Edit:

Can you add an option to stop the dots from overlapping?

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

This makes great star fields!1624_ad6871a0889fa2150b30191ce8a40b19

 

Take responsibility for your own intelligence. ;) -Rick Brewster

Link to post
Share on other sites

You mean Frosted Glass; Add Noise has no such binding. And neither will this, as long as it remains a CodeLab plugin.

CodeLab can't do that, you see. Not until BoltBait gets around to updating it for IndirectUI.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to post
Share on other sites
Edit:

Can you add an option to stop the dots from overlapping?

Please stop using edits to add completely new ideas! I'll only ever see them by raw chance. :roll:

And I really don't feel like tackling math that complicated right now. If someone else wants to, that's fine. Code is above.

Edit:Got this when I increased the max value higher than the hieght. Image was 800x600.

...

Fixed.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to post
Share on other sites

I made a color version (w00t! First plugin!).

I don't know how to switch back and forth, so you'll still want the previous one if you want grayscale (or just run B&W). I don't know how to create more sliders, so I can't make it so you can change which colors it chooses (right now, it just chooses a completely random value for red, green, and blue).

But I did compile it into a DLL, complete with an icon! Yay!

@pyrochild: I don't want to step on your toes, so if you'd prefer me to remove this plugin, I'll be more than happy to. It's essentially your code with two extra lines and a modification to two more, so it's obviously derivative.

Anywho, ScriptLab:

int Amount1=250;   //[1,1000]Amount
int Amount2=25;   //[0,1000]Minimum Size
int Amount3=50;   //[1,1000]Maximum Size
//submenu:Render

//=======================================================
//This is all so repeating the effect with Ctrl+F shows up different
//Only works when compiled - not within CodeLab
private byte instanceSeed = unchecked((byte)DateTime.Now.Ticks);
private int seedCount = 0;
private int Seed;

protected override void OnSetRenderInfo(EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs)
{
   this.Seed = seedCount ^ instanceSeed;
   seedCount++;
}
//=======================================================

unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
   Random r = new Random(this.Seed);

   //create a GDI+ graphics object
   Graphics g = Graphics.FromImage(dst.CreateAliasedBitmap());

   //enable antialiasing
   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

   //there's no point rendering outside of our given bounds
   g.Clip = new Region(rect);


   //=====================================================================
   //This is copies the source to the destination canvas - optimized for speed
   //So don't worry too much about understanding it - there are easier ways to do it
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
       ColorBgra* srcptr = src.GetPointAddressUnchecked(rect.Left, y);
       ColorBgra* dstptr = dst.GetPointAddressUnchecked(rect.Left, y);
       for (int x = rect.Left; x < rect.Right; x++)
       {
           dstptr->Bgra = srcptr->Bgra;

           srcptr++;
           dstptr++;
       }
   }
   //====================================================

   for (int i = 0; i < Amount1; i++) //loop through the number of dots we want
   {
       //==========================================
       //the try/catch block is in case the user selects a minimum higher than the maximum
       //as we don't want something so trivial to cause a crash
       int size = 0;
       try
       {
           //determine the size
           size = r.Next(Amount2, Amount3);
       }
       catch { }
       //========================================

       //location...
       Point pt = new Point(r.Next(Math.Abs(src.Width - size)), r.Next(Math.Abs(src.Height - size)));

       //we're rendering in color now!
       byte colorr = (byte)r.Next(256);
       byte colorg = (byte)r.Next(256);
       byte colorb = (byte)r.Next(256);

       //create our brush
       Brush b = new SolidBrush(Color.FromArgb(colorr, colorg, colorb));

       //draw!
       g.FillEllipse(b, new Rectangle(pt.X, pt.Y, size, size));

       //clean up our resources
       b.Dispose();
   }
}

ZIPped DLL is attached.

Random Dots - Color.zip

 

The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.
Amy: But how did it end up in there?
The Doctor: You know fairy tales. A good wizard tricked it.
River Song: I hate good wizards in fairy tales; they always turn out to be him.

Link to post
Share on other sites

Okay, cool. I wasn't sure...this is really my first foray into plugins in general, so I have no idea. :-D

 

The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.
Amy: But how did it end up in there?
The Doctor: You know fairy tales. A good wizard tricked it.
River Song: I hate good wizards in fairy tales; they always turn out to be him.

Link to post
Share on other sites
Would it be possible to add a "reseed" button, similar to the clouds render?

This is good, clean, wholesome fun :lol: and I'm sure I'll find a use for it sometime or another

to reseed it, just Ctrl-Z (Undo), Ctrl-F (Repeat effect)

Or, if you want to reseed while the dialog is still open, just change the value of a slider, then change it back.

It won't be able to have a reseed plugin unless the plugin is made into a full plugin, instead of a CodeLab prototype.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to post
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...