THGraphics External

Here is where the magnanimous folks that create externals post them (.zip archives only please).

Re: THGraphics External

Postby gonetriadrr » Fri Mar 18, 2011 7:06 am

gonetriadrr wrote:There appears to be an issue when filling 'compound paths'.


The good news.
Closing, reopening the project fixed the issue.
Had another round of flipped image, both x & y flipped.
Also, fixed by closing/reopening.

Neither issue repeated so far since installing version with releaseCanvas.

Thanks,

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Fri Mar 18, 2011 9:38 am

gonetriadrr wrote:Neither issue repeated so far since installing version with releaseCanvas


Although it may work it may impact memory consumption over a period of use.

I think the preferred method to restart a session is to:

"clearCanvas" followed by a "setCanvasSize"
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby Dan_Kelleher » Tue Mar 22, 2011 1:02 pm

On Thursday March 17, 2011 2:43 pm (see above, page 2, for the full message) I wrote:
However, as I see it, this BEHAVIOR THEY SHOW is NOT what I'd EXPECT FROM THEIR WRITTEN DESCRIPTION: (see the attached screenShot for the wriiten description at the top and the graphic example below)

Seems to be a Special Case for when only 2 paths are involved, Which they forgot to mention !! ??
1 L->R + 1 R->L = 0
therefore the points are outside and are not filled with the fillColor.... BUT THEY SHOW THEM FILLED

That message was based on a completely wrong understanding of how to go about thinking about winding rules used by Cocoa and Quartz based drawing methods.

March 17th was St Patrick's day. The Leprechauns are quite active then. They were helping me; reminding me, after a while (I'm a thick mic I guess), that making mistakes is a basis of my spirituality; my sameness and connectedness with others.

Winding rules are not really complicated and are very important since they control and predict which regions of a drawing will be filled with color+pattern and which will not be filled. If not filled they will be 100% transparent and underlying objects will be completely visible and able to respond to mouse clicks when the tool of the window is the browse tool.

The key idea, which Terry mentioned in his response to my message, is to use an imagined "ray" coming from a point (any point) and projecting outward toward the edge of the drawing. The direction of such a ray is, unexpectedly (at least for relatively simple drawings and I'm assuming all drawings), not important. The number of drawing paths crossed by the ray and the direction in which the crossed paths were drawn by your code, are used, together with the current winding rule to determine whether the region of interest is filled or not.

My original misunderstanding was due to not paying attention to the following initial paragraph in the Cocoa Drawing Guide. I printed out only the page with the diagrams and the rules but the introductory paragraph was on the previous page !
I then went away with the rules and the examples and did my stinkinThinkin. :oops:
Sorry Gals & Guys,
-Dan
Ray Idea+Winding Rules.jpg
Ray Idea+Winding Rules.jpg (19.54 KiB) Viewed 10927 times
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby Dan_Kelleher » Tue Mar 22, 2011 5:41 pm

I used Terry's example code that he provided (see March 18 above in this thread, page 2) as an aid to understanding winding rules in Cocoa drawing and the image produced is shown below.

It helped me to understand how to use imagined rays together with the winding rules to determine which areas will be filled and which will not be filled.
Rays + winding Rules B.jpg
Rays + winding Rules B.jpg (61.28 KiB) Viewed 10923 times

Rays + winding Rules A.jpg
Rays + winding Rules A.jpg (60.48 KiB) Viewed 10923 times
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby sctell » Wed Mar 23, 2011 11:20 am

Hi,

I have just posted an update of this external.

It can be found at the top of the thread.

-----------------
The main change is the addition of three very simple functions to allow the creation of a Pie Chart.

get THGraphics("setSegmentData",tText,tValue,tFillColor)
get THGraphics("drawPieChart",tRadius)
get THGraphics("clearSegmentData")

The canvas is automatically resized in the external to allow for the radius specified and a legend.
-------------------
In addition one more primitive function has been added:

appendPathWithArcWithCenter

-------------------
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Sat Mar 26, 2011 11:26 am

Hi,

A few more additions to the primitives section of the external.

I don't think there are many more. I need to look through NSBezierPath to check.

Anyway, the new functions are:

--------------
setDefaultWindingRule

setMiterLimit
setDefaultMiterLimit

setFlatness
setDefaultFlatness

setLineDash (an interesting function with peculiar settings)
--------------

The update can be found at the top of the thread.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Thu Mar 31, 2011 12:50 pm

Dan_Kelleher wrote:\BezierPenTool --> SuperCard object(s) --> THGraphics XFcn (or "CG" XFcn") --> -Dan

Thanks to bad weather keeping me cooped up, have an update of BezierPenTool nearly ready to post.
Update will include rendering via THGraphics. With aid of Terry's 'image' external, will include raster image fills & such.
Still quite buggy, sorry to say.
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby Dan_Kelleher » Thu Mar 31, 2011 2:27 pm

gotta love that bad weather :roll:

I've been working on a tracing utility to get points and I never knew there were so many ways to not get a mouseUp message when the mouse comes up !

not shoot_me though

If it wasn't so sunny here the last few days or if I had the 18 kitchen cabinet doors sanded, I'd be in fat city (that's a good place in this instance)

-Dan
man is always fickle... wanting what is not
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby mrBean » Thu Mar 31, 2011 7:53 pm

Since THGraphics only takes RGB values would it be possible to add a color converter function to the external?

For example:

HEX(6f,e3,df)
HSB(360,50%,60%)

get THGraphics("linearGradientInPath",HEX(6f,e3,df),HSB(360,50%,70%),tDegrees)
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: THGraphics External

Postby sctell » Thu Mar 31, 2011 11:19 pm

Upon further consideration, a separate external to convert cmyk to rgb would be more suitable for my purposes and general use.



This is the next on the list.

cmykToRGB

rgbToCMYK

put THColorSpace("cmykToRGB",tCMYK) into myRGB

or something similar?
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Fri Apr 01, 2011 10:23 am

Hi,

There is an update that is not really an update at the top of the thread.

I have removed the pie chart from this external as I am in the process of producing an external called THChart which will contain a number of charting options.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Fri Apr 01, 2011 10:47 am

sctell wrote:
Upon further consideration, a separate external to convert cmyk to rgb would be more suitable for my purposes and general use.



This is the next on the list.

cmykToRGB

rgbToCMYK

put THColorSpace("cmykToRGB",tCMYK) into myRGB

or something similar?


That would be beautiful :D
Thanks!
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby mrBean » Sat Apr 02, 2011 1:44 pm

sctell wrote:
Upon further consideration, a separate external to convert cmyk to rgb would be more suitable for my purposes and general use.



This is the next on the list.

cmykToRGB

rgbToCMYK

put THColorSpace("cmykToRGB",tCMYK) into myRGB

or something similar?


That's not really what I'm talking about. I was thinking more in the lines of converting to a RGB value on the fly as part of the THGraphics syntax. for example; say i want to create a linear gradient, but I'm working with HEX color values instead of RGB. Instead of converting the HEX value to RGB and then passing it to THGraphics, I was thinking I would be able to tell THGraphics that the color value is HEX and it would convert the value to RGB as apart of it normal operations.

sample syntax; THGraphics("linearGradientInPath",HEX(6f,e3,df),"0,1,0,1","45")

I know its kind of a mute point, but i though it was cool.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: THGraphics External

Postby mrBean » Tue Apr 05, 2011 12:15 pm

I created an example of a Photoshop style color palette from a project I'm currently working on. Originally I used an open source UNIX program called ImageMagick to generate gradients for me. I since have replaced ImageMagick with THGraphics external. The example has a bunch of stuff in it including some color math, and other color tools.
Last edited by mrBean on Wed Apr 06, 2011 12:16 pm, edited 1 time in total.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: THGraphics External

Postby codegreen » Tue Apr 05, 2011 12:25 pm

FYI 'color' is most likely going to be a reserved word in SC 4.8, so you might want to tweak your scripts now accordingly...

HTH,
-Mark
codegreen
 
Posts: 1517
Joined: Mon Jul 14, 2008 11:03 pm

Re: THGraphics External

Postby sctell » Tue Apr 05, 2011 11:19 pm

Hi Mark,

How does the reserved word issue work and does it affect externals in any way?
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby codegreen » Wed Apr 06, 2011 12:41 am

sctell wrote:How does the reserved word issue work and does it affect externals in any way?

You can't use reserved words as SuperTalk variable names. If you try an error is thrown -- which is exactly what happened when I ran Sean's project because I'm using a 4.8 development build in which 'color' is already a language token. I just thought he might like to know about that before his sample project got into wide circulation...

There is no such restriction on external names. They're higher up in the message hierarchy than built-in commands and functions, so if name conflicts occur the external will take precedence. This won't always produce a scriptError (in fact it may be intentional) so any problems accidental collisions create may be harder to debug. Renaming externals won't normally cause them to break though so the fix is usually pretty simple; still judicious choice of external names can prevent a lot of grief.

When choosing variable names it's prudent to pick ones that aren't English words (or even xtalk-flavored combinations of words in forms such as allowXXX, doXXX, dontXXX, or hasXXX) as this makes them much less likely to conflict with language tokens added later.

There are several popular schemes for variable naming, and even the most simplistic (e.g., the hoary xtalk convention of preceding English words with 'the') tend to produce names that -- while not especially illuminating -- are unlikely to conflict with future tokens. Choosing ordinary English words (especially common names of properties of onscreen objects) basically amounts to riding around with your head sticking out of the side window of the car -- it's not illegal, but sooner or later you'll probably wish you hadn't...

-Mark
codegreen
 
Posts: 1517
Joined: Mon Jul 14, 2008 11:03 pm

Re: THGraphics External

Postby mrBean » Wed Apr 06, 2011 12:16 pm

I have updated my example to make it sc4.8 compliant. I put a 'X' next to the word color, and just for good measure I also put an X next to updateColor, and pColor.

Photoshop style color palette.sc45.zip
sc4.8 compliant
(1.07 MiB) Downloaded 343 times

I created an example of a Photoshop style color palette from a project I'm currently working on. Originally I used an open source UNIX program called ImageMagick to generate gradients for me. I since have replaced ImageMagick with THGraphics external. The example has a bunch of stuff in it including some color math, and other color tool
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: THGraphics External

Postby gonetriadrr » Fri Apr 08, 2011 8:46 am

Hi Terry,

Is it possible to add something like 'fillWithPatternFile' and 'clipImageFile' options?
And option to disable antialiasing per object or globally?

Thanks,
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Fri Apr 08, 2011 10:12 am

gonetriadrr wrote:Is it possible to add something like 'fillWithPatternFile' and 'clipImageFile' options?


Do you mean:

get THGraphics("fillPathWithPatternFile",tPathToPatternFile)

get THGraphics("strokePathWithPatternFile",tPathToPatternFile) (do you need this?)

get THGraphics("clipImageFile",tPathToImageFile)
(the original image will not be altered)

This will be possible as NSImage(this is what the external uses) will be able to import using:

- (id)initWithContentsOfFile:(NSString *)filename

Here is a list of image formats supported by NSImage.

Portable Document Format (PDF) - I think without intervention it will load the first page
Encapsulated PostScript (EPS)
Tagged Image File Format (TIFF)
Joint Photographic Experts Group (JPEG), JPEG-2000
Graphic Interchange Format (GIF)
Portable Network Graphic (PNG)
Macintosh Picture Format (PICT) - transparency as SuperCard not supported without intervention.
Windows Bitmap Format (DIB)
Windows Icon Format
Icon File Format (.icns)

gonetriadrr wrote:And option to disable antialiasing per object or globally?


This is a more extensive modification.

I will do the image thing first and then look at disabling antialiasing on a global scale probably with something like:

get THGraphics("setAntialiasing","false") or "true" with the default being "true"

Why do you want antialiasing off out of interest?

With the THBarChart external I turned off antialiasing when producing the bars and axes as the appearance was much better but turned it back on for text as text with antialiasing off looks rather poor (in my opinion).

Similarly oval lines look poor with antialiasing off.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Sat Apr 09, 2011 12:24 pm

sctell wrote:
gonetriadrr wrote:Is it possible to add something like 'fillWithPatternFile' and 'clipImageFile' options?


Do you mean:

get THGraphics("fillPathWithPatternFile",tPathToPatternFile)

get THGraphics("strokePathWithPatternFile",tPathToPatternFile) (do you need this?)

get THGraphics("clipImageFile",tPathToImageFile)
(the original image will not be altered)


Thats the ticket!
sctell wrote:
gonetriadrr wrote:And option to disable antialiasing per object or globally?


This is a more extensive modification.

I will do the image thing first and then look at disabling antialiasing on a global scale probably with something like:

get THGraphics("setAntialiasing","false") or "true" with the default being "true"

Why do you want antialiasing off out of interest?


Excessive blurring of images used as pattern fills.
But, blurring may be the result of using the image xternal to rotate/resize/crop to fit the path bounds and canvas size, and not the fault of the rendering xternal. I'll have to compare to be sure.
IIRC, CoreGraphics provided an interpolation parameter to help control blurring of raster sources.

Thanks!
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Sat Apr 09, 2011 12:36 pm

Hi,

Three new functions as requested:

get THGraphics("fillPathWithPatternFile",tPathToFile)

get THGraphics("strokePathWithPatternFile",tPathToFile)

get THGraphics("clipImageFile",tPathToFile)

It is the scripters responsibility to check the path is POSIX and pointing to a valid image that NSImage can handle.
See the list of suitable image types in the previous message.

The new download is available at the top of this thread.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Sun Apr 10, 2011 7:47 am

Hi,

gonetriadrr wrote:Excessive blurring of images used as pattern fills.
But, blurring may be the result of using the image xternal to rotate/resize/crop to fit the path bounds and canvas size, and not the fault of the rendering xternal. I'll have to compare to be sure.
IIRC, CoreGraphics provided an interpolation parameter to help control blurring of raster sources.


I have been looking at this and do not believe it is anything to do with THGraphics.

Cocoa provides [[NSGraphicsContext] currentContext] setImageInterpolation: NSImageInterpolationHigh]

The available constants from Apples Docs are:
--------------------------
NSImageInterpolationDefault
Use the context’s default interpolation.

NSImageInterpolationNone
No interpolation.

NSImageInterpolationLow
Fast, low-quality interpolation.

NSImageInterpolationMedium
Medium quality, slower than NSImageInterpolationLow.

NSImageInterpolationHigh
Slower, higher-quality interpolation.
-----------------------------------------------------

to provide control of the blurring. Probably a cocoa equivalent of CoreGraphics.

This has not been implemented in the image external.

I will implement it and post an update.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Sun Apr 10, 2011 7:55 am

On investigating the blurring issue I should bring to your attention (perhaps you are already aware) that a pixel centre is not on integer boundaries but rather between.

An example:

draw these two lines with a line size of 1.0

get THGraphics("moveToPoint","20,10")
get THGraphics("lineToPoint","20,200")

get THGraphics("moveToPoint","10.5,10")
get THGraphics("lineToPoint","10.5,200")

Note the difference in quality between the two lines

This is as a result of antialiasing of the line on x = 20 as the line is not on a pixel centre.

You can cure this by moving your coordinates appropriately.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Tue Apr 12, 2011 9:42 am

sctell wrote:Why do you want antialiasing off out of interest?


I'm looking to do shaped gradient blends with transparency.
Filling compound paths of increasing size, each iteration having the outermost path of the previous in common.
IIRC, while experimenting with python, i noticed that turning antialiasing off improved results.
I'll test again with your external to see if my memory is correct.

BTW: Thanks for the revised image externals!

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

PreviousNext

Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest

cron