Wither Posted February 8, 2008 Posted February 8, 2008 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. 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); } } Quote YouTube | Myspace | deviantART
pyrochild Posted February 8, 2008 Posted February 8, 2008 Like this? Here's the CodeLab source - I even commented it! 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. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
barkbark00 Posted February 8, 2008 Posted February 8, 2008 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) Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
pyrochild Posted February 8, 2008 Posted February 8, 2008 That's not a bug, that's common sense. The number n in 10 Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
barkbark00 Posted February 8, 2008 Posted February 8, 2008 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! Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
pyrochild Posted February 8, 2008 Posted February 8, 2008 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. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
barkbark00 Posted February 8, 2008 Posted February 8, 2008 You mean Frosted Glass...Right, sorry! Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
pyrochild Posted February 8, 2008 Posted February 8, 2008 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. 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. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
david.atwell Posted February 8, 2008 Posted February 8, 2008 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 Quote 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.
pyrochild Posted February 8, 2008 Posted February 8, 2008 I wouldn't have posted the source if I didn't want people modifying it. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
david.atwell Posted February 8, 2008 Posted February 8, 2008 Okay, cool. I wasn't sure...this is really my first foray into plugins in general, so I have no idea. :-D Quote 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.
R3VENGE Posted February 8, 2008 Posted February 8, 2008 wow this looks like a great idea Quote psn id: R3V-fiR3
Curmudgeon Posted February 8, 2008 Posted February 8, 2008 Would it be possible to add a "reseed" button, similar to the clouds render? This is good, clean, wholesome fun and I'm sure I'll find a use for it sometime or another Quote
pyrochild Posted February 8, 2008 Posted February 8, 2008 Would it be possible to add a "reseed" button, similar to the clouds render?This is good, clean, wholesome fun 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. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
D.C. (Conviction Posted February 8, 2008 Posted February 8, 2008 actually, i tried that this morning and it kept doing the same thing Quote ~97% of teens won't stand up for Anything. Put this on your sig if you're one of the 3% who've fallen down trying. Oh, and there's 3 types of people in this world...
Curmudgeon Posted February 8, 2008 Posted February 8, 2008 Thanks, I just figured that out before you replied. Before, I was cancelling, then went back to render>random dots each time Quote
pyrochild Posted February 8, 2008 Posted February 8, 2008 actually, i tried that this morning and it kept doing the same thing Are you using it within CodeLab, or are you using the DLL? It will only work if you use the DLL. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
D.C. (Conviction Posted February 8, 2008 Posted February 8, 2008 I'm using the dll Quote ~97% of teens won't stand up for Anything. Put this on your sig if you're one of the 3% who've fallen down trying. Oh, and there's 3 types of people in this world...
MadJik Posted February 16, 2008 Posted February 16, 2008 This is my version (my view) of the Random dot generator: -Reseed, -Fill (or not) -Border (or not) -Random color(s) -etc... I didn't find a efficient solution to check if dots are overlapping... Should I publish it in the plugin forum? Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal
Mike Ryan Posted February 16, 2008 Posted February 16, 2008 Wow. Nice job Madjik! Definetly post it! Edit: Found a bug. The secondary and primary are backwards. Quote
MadJik Posted February 16, 2008 Posted February 16, 2008 Thanks for the Wow! I don't see the bug! Primary is inside, Secondary is the border, and vice-versa in Secondary mode... And so if you uncheck 'Filled' and check 'borders', only secondary is used for the border. This is the way it is made! Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal
Mike Ryan Posted February 16, 2008 Posted February 16, 2008 Oh ok! I understand now! I had thought that it was just confused in code or something. Also, src? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.