Script to draw triangles within triangle?

Moderator: Kathy_9

Marak60
Posts: 6
Joined: Sun Jan 13, 2013 12:12 am
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Dell 0-C2KJT
processor: Intel Core i3 550 3.20GHz
ram: 8GB
Video Card: Intel HD Graphics
sound_card: RealTek
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: Westinghouse

Script to draw triangles within triangle?

Post by Marak60 »

I'd like to draw a 10-inch equilateral triangle, and then fill it with 0.5-inch triangles. Can anyone tell me the best way to do this? Some type of script, I assume?

Thanks,
Mark
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: Script to draw triangles within triangle?

Post by df »

If you're doing this once you won't need a script.

For the 10 inch triangle
1. Click File> New. In the New Image dialog box set the Units: to Inches. Set the Resolution to what you want. Width and Height to 10. Vector Background checked. Click OK.
2. Select the Preset Shape Tool (press P on your keyboard). In the Shapes list (between Presets and Retain Style on the Tools Toolbar) choose Triangle. Uncheck Retain Style. Check Create as vector. Line style should already be a straight line, change it if needed to what you like. Width is default at 1, try 10 for now.
3. On the Materials palette choose your stroke and fill colors. The half black, half white box will reset to black stroke, white fill.
4. Click and drag on the workspace to create your triangle.
5. At the top of PSP click Objects> Make same size> Both. Then click Objects> Align> Center on Canvas.

For the 0.5 inch triangles, repeat the same thing except for these changes:
1. use 0.5 inches.
2. change the Width to 5.
3. 4. 5. are the same.
6. Click Image> Canvas Size. Check the box for Lock aspect ratio (it should be 1.000 to 1). Set Width to 0.75. Placement should be the center selection. Click OK.
This will give you a bit of space around the triangles.

Now go back to your 10 inch triangle image.
a) Click the Stroke box on the Materials palette. When the Material Properties dialog box comes up choose the Pattern tab. Under Current Pattern click the image and a second dialog box will show up with the other images that are open on it first then some preset patterns built into PSP. Click the 0.5 inch triangle one. Set the Angle to 0, Scale to 100. Click OK. You should see the Stroke box change to the image of your 0.5 triangle.
b) Choose the Flood Fill Tool (F). Click the inside of your 10 inch triangle.

You can adjust any of these steps to your liking. If you want more triangles but the same size then don't bother resizing the Canvas Size in step 6.

If this isn't at all what you're talking about just let us know.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script to draw triangles within triangle?

Post by LeviFiction »

Heck if you're doing it twice or more you still won't need a script. Just need to export the resulting vector shape as a preset shape and you can use it time and time again.

Of course if you're good with scripts scripting probably makes it easier, as you just write in what you need, if not it's not that bad to do it manually.
https://levifiction.wordpress.com/
Marak60
Posts: 6
Joined: Sun Jan 13, 2013 12:12 am
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Dell 0-C2KJT
processor: Intel Core i3 550 3.20GHz
ram: 8GB
Video Card: Intel HD Graphics
sound_card: RealTek
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: Westinghouse

Re: Script to draw triangles within triangle?

Post by Marak60 »

df wrote:...If this isn't at all what you're talking about just let us know.
So close to what I need, df, but not quite. Using your fill method does in fact fill my large triangle up with smaller triangles, but they are not flush with the sides of the large triangle. It essentially creates rows of triangles, starting from the bottom of the large triangle, but it does not align them with the sides of the large triangle. So, for example, the 2nd row (from the bottom) of small triangles starts on the left with a partially painted triangle, giving the whole thing a ragged, rather than symmetric look. I really need a 10" triangle that is filled with 400 1/2" full (i.e. no partial) triangles.

Thanks so much for your reply. I don't suppose it would be terrible if I had to do this manually, but I thought I'd fish around for an automated solution in case I decided to change the size of either the large or small triangles.

Thanks again!
df
Posts: 1224
Joined: Mon Feb 08, 2010 11:21 pm
operating_system: Windows 11
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: GIGABYTE Z690 AERO G DDR4
processor: 13th Gen Intel Core i7-13700K
ram: 64gb
Video Card: RTX 3060 Ti 8gb GDRR6
Hard_Drive_Capacity: 1 Tb
Location: Washington State
Contact:

Re: Script to draw triangles within triangle?

Post by df »

Try asking here https://www.facebook.com/CreationCassel?ref=ts&fref=ts if you have a facebook account. This is a person who creates scripts. Usually not free but pretty cheep.
Regards, Dan

"Smoke me a kipper, I'll be back for breakfast."
Marak60
Posts: 6
Joined: Sun Jan 13, 2013 12:12 am
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Dell 0-C2KJT
processor: Intel Core i3 550 3.20GHz
ram: 8GB
Video Card: Intel HD Graphics
sound_card: RealTek
Hard_Drive_Capacity: 1TB
Monitor/Display Make & Model: Westinghouse

Re: Script to draw triangles within triangle?

Post by Marak60 »

Thanks, Dan, I'll do that.

Rgds,
Mark
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Re: Script to draw triangles within triangle?

Post by photodrawken »

I assume that this is the result you're looking for:
Image
Uploaded with ImageShack.us

To be honest, this effect is beyond the capabilities of PSP; at least when using the editing interface, and if it can be done via scripting would need some rather hellish coding. (I came close to creating a pattern that can be used as a fill, but the pattern itself, as well as the filling, are not precise enough in PSP to get a perfect result.)

The effect is dead simple to do in a vector editing program, however -- I did it in a couple of minutes in CorelDraw X5. Saved it as an EMF file to keep it as a vector object and copied the EMF into PSPX5 where I could easily modify the vector's line widths and colours, as well as its overall size.
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script to draw triangles within triangle?

Post by LeviFiction »

Hellish coding? I highly doubt it. You're talking about a simple drawing, in fact if you know the sizes and can convert to pixels it's essentilly nothing more than a repeating patthern. So with a little math, and some For loops you're pretty much good to go.

In fact you could write the entire vector string that way then using the commands inside of PSP to draw the result rather quickly.
https://levifiction.wordpress.com/
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Re: Script to draw triangles within triangle?

Post by photodrawken »

LeviFiction wrote:So with a little math, and some For loops you're pretty much good to go.
Yep, that's what I mean -- using a "for" statement to keep track of the iteration and devising a formula general enough to take the iteration number as a parameter to calculate the starting point of each small triangle can certainly be done in code, but it sure seems "rather" hellish to this hobbyist programmer. :mrgreen:
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script to draw triangles within triangle?

Post by LeviFiction »

In my mind that's the easiest part.

10 inches at 300dpi is 3000 pixels for the width, and the height should be around 8.66 inches so 2598 pixels. .5 inches would be 150 pixels wide and 129.9 pixels tall rounded. So 20 rows from bottom to top. The next triangle starts at the half-way point of a smaller triangle so we figure each new row will increase the starting X position by 75 pixels and end 75 pixels further in.

Code: Select all

#Draw original Triangle
blx = 0
bly = 2598

tx = 1500
ty = 0

brx = 3000
bry = 2598

#OriginalString + Move blx,bly Move tx,ty Move brx, bry Close

start = 0
end = 3000
y = 2598.0

#Use a while loop to allow for floating point numbers
while y > 0:
    for x in range(start,end,150):
        bl = x
        t= y + 129.9
        m=x+75
        br = x + 150

        #Create vector string using this the values above
        #Original String + Move bl,y Move m,y Move br, y Close
    start = start + 75
    end = end - 75
    y = y - 129.9

#Draw resulting vector
Of course I'm often proven wrong about these things. :mrgreen: Doesn't help that "code" (need to relearn how PSP identifies its vector strings) is off the top of my head.
https://levifiction.wordpress.com/
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Re: Script to draw triangles within triangle?

Post by photodrawken »

LeviFiction,

OK, although I don't know Python (I'm a C# guy :wink: ), that seems like an approach that should work.

I'm assuming that:
1. The code construct "for x in range(start,end,150):" means that the variable "x" has an initial value of "start", an ending value of "end", and has the "start" variable incremented by "150" px each time through the "for" loop. Right?

2. "y = y - 129.9" is what ultimately limits the creation of shapes to 20 rows. Am I correct?

3. "end = end - 75": is what stops the drawing of shapes on each row so that no shapes are drawn past the edge of the original triangle. Correct?

I have no idea what the various "Move" statements do, but I'll assume they somehow deal with drawing a line from a starting point to an ending point. Is that right?

One of these years, I'll get back into coding and see if I can create an add-in for CDR that does this. (CDR implements the VSTA editor and lets me write the code in C#.) In general, the thing I question is the resolution-dependent nature of the code. I'm thinking that it would be better (maybe easier, too) to only use the dimensionless units of pixels and the trigonometric functions to get the heights and widths. Since the resulting drawing will be a vector image, it can be resized after the fact in the PSP editing window without losing resolution or precision, etc.

Intresting, for sure....
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script to draw triangles within triangle?

Post by LeviFiction »

I got into Python because it's used in all of my favorite applications. xD

1) Correct
2) Correct, starting from the bottom and moving up.
3) Correct
4) The "move" statements are actually pseudo pseudo SVG descriptors. My SVG Export script has the details of how PSP defines its vectors but I couldn't remember where I saved it so I just pseudoed it up.

As for why I did the script this way, the script is dedicated to this topic where the specific dimensions were listed in inches and I always assume 300dpi. Since it is vector whether it be dependent or independent is moot. It'll simply create a single vector shape (using multiple contours....maybe even reversing the inner contours for a fun half-filled half-empty appearance when the fill is turned on) and is easily resized from there. But you're right, if we wanted a truly useful script it would include the ability to use any sizes for the main triangle and the smaller ones.
https://levifiction.wordpress.com/
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Re: Script to draw triangles within triangle?

Post by photodrawken »

LeviFiction wrote:I got into Python because it's used in all of my favorite applications. xD
Hee...hee. That just goes to show that you're using all the wrong applications! :D
LeviFiction wrote:It'll simply create a single vector shape (using multiple contours....maybe even reversing the inner contours for a fun half-filled half-empty appearance when the fill is turned on)
I don't understand what you mean by PSP creating a vector shape using multiple contours. Is that a uniquely PSP way of drawing vectors?
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script to draw triangles within triangle?

Post by LeviFiction »

No, not unique to PSP. PSP's method is in fact very generic. Actually it was the fact that PSP used such a standard way of describing the vector paths that made simple shape conversion to SVG so easy.

Though Vectors themselves can be made and described in many different ways and many programs handle them differently. Anime Studio, for example, allows you to close a vector and continue to have another contour connected to one of the vertexes of the first contour where PSP would never allow that. I've played with others that didn't allow multiple contours per path but would gladly group multiple paths.

The point of the description was 2 fold. 1) To let anyone curious about the final object know that it'll be a single path and 2) to describe how the contours would be used to potentially cut holes in the base countour. You may know how it's done, but not everyone reading will.
https://levifiction.wordpress.com/
photodrawken
Posts: 684
Joined: Wed Sep 26, 2012 8:40 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
ram: 16Gb
Hard_Drive_Capacity: 324Gb
Location: USA

Re: Script to draw triangles within triangle?

Post by photodrawken »

With apologies to the OP for leading this discussion somewhat astray....

I'm still confused about what a "contour" is in the context of a PSP vector object. Reading the Help, it seems that the word "contour" is superfluous -- it's not just a line segment, but rather a grouping of line segments, which is what a "path" is. ?? :?

Getting back to your script: are you saying that it's creating one object? IOW, there's no "separation" (or distinction) between the outer triangle and the filling triangles?
Ken
Yes, I think it can be eeeeeasily done...
Just take everything out on Highway 61.
Post Reply