Sign in to follow this  
toe_head2001

Spoked Wheel v1.1 (March 5, 2016)

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.GetSelection(src.Bounds).GetBoundsInt();
    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

Share this post


Link to post
Share on other sites

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Hello skullbonz,

 

Thanks for the tip, I tried Gears and this is what I came up " Not all spoked wheels are made the same"

gear-and-spoked-wheel-4e848f3.png

Share this post


Link to post
Share on other sites

Yes, the Spoked Wheel effect is designed to slice a circle into equal parts. In the example above, both have 5 spokes.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks toe_head2001, the adjustments work very well. The thicker lines are  large enough when working on a very large canvas.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this