Jump to content
How to Install Plugins ×

Spoked Wheel v1.1 (March 5, 2016)


toe_head2001

Recommended Posts

Spoked Wheel

Effects -> Render -> Spoked Wheel

 

ui.pngex1.png

 

Change Log

v1.1 (March 5, 2016)

  • Changed: The range for Line Thicknesses now maxes out at 100

v1.0 (Feb 20, 2016)

  • Initial release

 

Download

SpokedWheel.zip

 

Spoiler

SpokedWheel.png <---- Icon

GPL v3


// Name: Spoked Wheel
// Submenu: Render
// Author: toe_head2001
// Title:
// Version: 1.1
// Desc: Generates a Spoked Wheel
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 5; // [3,20] Spokes
DoubleSliderControl Amount2 = 1; // [0.1,1] Wheel Size
DoubleSliderControl Amount3 = 0.333; // [0.1,0.9] Axle Size
IntSliderControl Amount4 = 2; // [1,100] Rim Thickness
ListBoxControl Amount5 = 0; // Rim Style|Solid|Dashed|Dotted
IntSliderControl Amount6 = 2; // [1,100] Spoke Thickness
ListBoxControl Amount7 = 0; // Spoke Style|Solid|Dashed|Dotted
IntSliderControl Amount8 = 2; // [1,100] Axle Thickness
ListBoxControl Amount9 = 0; // Axle Style|Solid|Dashed|Dotted
AngleControl Amount10 = 0; // [-180,180] Rotation
ColorWheelControl Amount11 = ColorBgra.FromBgr(0,0,0); // Color
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = EnvironmentParameters.SelectionBounds;
    float centerX = ((selection.Right - selection.Left) / 2f) + selection.Left;
    float centerY = ((selection.Bottom - selection.Top) / 2f) + selection.Top;
    float diameter = (float)Amount2 * Math.Min(selection.Width - 4, selection.Height - 4) - Amount4;
    float radius = diameter / 2f;
    float offsetX = centerX - radius;
    float offsetY = centerY - radius;
    float axleDiameter = (float)Amount3 * diameter;
    float axleOffsetX = centerX - axleDiameter / 2f;
    float axleOffsetY = centerY - axleDiameter / 2f;
    float start = (float)Amount10;
    float sweep = 360f / Amount1;

    dst.CopySurface(src, rect.Location, rect);

    using (Graphics wheel = new RenderArgs(dst).Graphics)
    {
        wheel.SmoothingMode = SmoothingMode.AntiAlias;
        wheel.Clip = new Region(rect);
        
        using (Pen wheelPen = new Pen(Amount11))
        {
            // Draw Rim
            wheelPen.Width = Amount4;
            wheelPen.DashStyle = getDashStyle(Amount5);
            wheel.DrawEllipse(wheelPen, offsetX, offsetY, diameter, diameter);
            
            // Draw Spokes
            wheelPen.Width = Amount6;
            wheelPen.DashStyle = getDashStyle(Amount7);
            for (int spoke = 0; spoke < Amount1; spoke++)
            {
                float degrees = start + sweep * spoke;
                double radians = Math.PI / 180 * degrees;

                float startX = (float)(radius * Amount3 * Math.Sin(radians));
                float startY = (float)(radius * Amount3 * Math.Cos(radians));
                
                float endX = (float)(radius * Math.Sin(radians));
                float endY = (float)(radius * Math.Cos(radians));

                wheel.DrawLine(wheelPen, centerX - startX, centerY - startY, centerX - endX, centerY - endY);
            }
            
            // Draw Axle
            wheelPen.Width = Amount8;
            wheelPen.DashStyle = getDashStyle(Amount9);
            wheel.DrawEllipse(wheelPen, axleOffsetX, axleOffsetY, axleDiameter, axleDiameter);
        }
    }
}

static DashStyle getDashStyle(byte style)
{
    DashStyle dashStyle;
    switch (style)
    {
        case 0: // Solid
            dashStyle = DashStyle.Solid;
            break;
        case 1: // Dashed
            dashStyle = DashStyle.Dash;
            break;
        case 2: // Dotted
            dashStyle = DashStyle.Dot;
            break;
        default:
            dashStyle = DashStyle.Solid;
            break;
    }
    return dashStyle;
}

 

 

Edited by toe_head2001
  • Upvote 7

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

You could shorten up the UI by changing those radio buttons into drop-down lists.

 

Dang it, I meant to change those before posting. Anyway, they're drop-down lists now.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

Thank you, toe_head! I'm sure I'll find a use for this... ;)        :beer:  :pizza:

 

 

 

Just what I needed, Thank you!

 

Space, the final frontier...

 

 

Eli, Beam me up!!   :)       (I'm a huge Trekkie...)

Link to comment
Share on other sites

  • 2 weeks later...

Version 1.1 posted. The Line Thicknesses can now go up to 100.

 

Sorry Eli, I had this new version ready two weeks ago when you asked me about the line thickness. I simply forgot to post it.

  • Upvote 3

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

  • 2 weeks later...

Here's the plugin compiled for the old PdN: Spoked Wheel 1.1 for PdN 3.5.11.zip

 

This may be a far-fetched application, but I think this is good for creating chopped trees, or maybe circular woody mazes. Of course the spoked wheel was just the starting point after which I had to do a couple additional things, but anyway, the spoked wheel took part and that's what counts :) Here are two quickies whose main objects I believe resemble chopped trees (maybe the first one looks more like a circular maze JC_thinking.gif). Perhaps the textures can be improved.

 

Scene 1:

 

Spoked_Wheel_Chopped_Tree_Trunk_scene_1.
 

Scene 2:

 

Spoked_Wheel_Chopped_Tree_Trunk_scene_2.

  • Upvote 2
Link to comment
Share on other sites

  • 2 years later...
6 minutes ago, Eli said:

would it be possible to have more spokes?  Something like 32. :)  Thanks! 

 

There is no technical limitation, so if you want 32, just edit the source file.

 

Change this from:

IntSliderControl Amount1 = 5; // [3,20] Spokes

to this:

IntSliderControl Amount1 = 5; // [3,32] Spokes

 

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

  • 10 months later...

This is a neat little render tool for creating spokes behind a central object. I was wondering if the spokes could be made to taper as they got closer to the axle?

Link to comment
Share on other sites

28 minutes ago, toe_head2001 said:

 

Sorry, there's no easy way to do that.

Agreed, there is actually a theoretical way I know how to do it. But, it requires warping image assuming distance from center is y and square borders as x, then create linear stroke, and transform it back where x axis is x and y axis is y. But, that is not easy at all.

 

Actually maybe polar transformation would be easier to code in. A lot easier in fact.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

The thing is that it's not consistent within the spokes. That's why I suggest polar transform. Generate the outlines within pre-transform vector, then polar transform right back. But, I'm not so qualified to know c# limitation in context of paint.net, but this is indeed possible within g'mic-qt and c++ within other programs.

Edited by Reptillian

G'MIC Filter Developer

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...