Posts Tagged ‘mesh’
How to Meld a Gradient into a Flat Process Color – Part II
|
In Part 1 of this two part tutorial series, we learned how to code a script which converts a flat process color into its matching gradient. In this tutorial, we will learn to code a script that converts a gradient fill into a flat process color. We will melt the available gradient color into a flat process color, which will be a mixture of all the colors available in that gradient. This entire task will be performed via JavaScript script for Illustrator. The tutorial assumes that you’re familiar with the basics of scripting. For those who’ve directly landed on this tutorial, we have a little know-how covered about Illustrator’s Javascripts in Part 1 of this series. So without further delays, let’s get started!
Vector PlusWant access to the full Vector Source files and downloadable copies of every tutorial, including this one? Join Vector Plus for just 9$ a month. Tutorial Details
Purpose of the ScriptWe want this script to perform a very simple task. In Adobe Illustrator, when a user selects some objects filled with a CMYK Gradient Color, and executes this Script; the objects shall get converted into a Flat CMYK fill. This flat fill will be the mixture of all the colors available in the former gradient. See the image below for clarification. ![]() Hence, the aim of our script is to convert a Gradient CMYK Fill into a Flat CMYK Fill. Logic and AlgorithmThe logic for melting the colors of a gradient into a single color is simple and straightforward. We’ll pick all the colors from the gradient, find their average and assign it to the object as a new color. We can understand this in five steps, as shown below:
The above algorithm can be easily understood from the pictorial representation below. ![]() We have seen a brief overview of the logic. Let’s get started with the coding. Step 1 – Starting with the Code StructureOpen ExtendedScript Toolkit and create a new Javascript file (Command + N). Next, select Adobe Illustrator for the target application. ![]() In the code editing area, add the following code structure for certain validations and pre-requisite checks. if ( app.documents.length > 0 && app.activeDocument.pathItems.length > 0) { if(app.activeDocument.documentColorSpace == DocumentColorSpace.CMYK) { convertToFlat(); } else { alert("Convert the Objects into CMYK First", "CMYK Conversion required"); } }//end main if
else { alert("Either no document is available or the document is empty"); }
We are checking if at least one document with at least one object exists, so that we can work upon it. Next, we are checking whether the document color mode is CMYK or not. This is an essential step because all the logic for color conversion in this script is based upon CMYK colors. Step 2Let’s now start with the main function – function convertToFlat() {
var items = selection; var totalSelected = items.length;
if(totalSelected > 0) { // proceed with the main logic }
else { alert("Please select atleast one object"); }
}//end convertToGrad
Step 3Next, we will start a loop inside the “ if(totalSelected > 0) {
for(var j=0; j < totalSelected; j++) { var currentObject = app.activeDocument.selection[j];
if(currentObject.typename != "CompoundPathItem" && currentObject.typename != "GroupItem") { if(currentObject.filled==true && currentObject.fillColor.typename != "CMYKColor" && currentObject.fillColor.typename != "PatternColor" && currentObject.fillColor.typename != "SpotColor") {
// Color conversion Block
} //endif
else { alert("Fill an object with CMYK or Grayscale Gradient. Flat Colors, Patterns, Spot Colors and Empty Fills are not allowed."," Only Gradients Allowed"); } } //endif
else { alert("This script only works with Non-Compound Objects or Isolated Group items.nAny items with Groups or Compound Objects will be omitted.", "Ungroup or Isolate the Group Items"); }
}//endfor
}// endif
For each selected item, we are checking whether it is a Compound Path or a Group Item. If so, the script shall not execute anymore and return an alert message. Further, we are checking if the fill-type of the selected item is something other than Gradient Fill. i.e. If it is a spot color, flat CMYK color or a pattern; the script shall return an alert. These checks are performed because our script will only work for gradient filled non-compound path items. Step 4At this stage, we need to extract individual C, M, Y and K values for the colors residing at different gradient stops. For that, we will create some variables which will hold individual CMYK values. So, add the following variable declarations just inside the Color conversion block: var currentColor = currentObject.fillColor; var numOfStops = currentColor.gradient.gradientStops.length; var colorBox=[]; var cyanBox=[]; var magentaBox=[]; var yellowBox=[]; var blackBox=[]; var grayBox =[]; var cyanTotal = 0; var magentaTotal = 0; var yellowTotal = 0; var blackTotal = 0; var grayTotal = 0; We will see the role of each variable one-by-one:
Step 5We have performed the validations and checks. We have also created necessary containers to hold color values. Next, we will run a loop which reads each gradient stop one-by-one. For that, create a loop, as shown below: for(var k=0; k < numOfStops; k++) { colorBox[k] = currentColor.gradient.gradientStops[k].color; if(colorBox[k].typename == "GrayColor") {
// Extract Gray Color values
}
else {
// Extract CMYK Color values
}
}//end for k
For each gradient stop, we are checking if the available color is a Step 6 – Summation of GrayColor ValuesInside the " grayBox[k] = Math.round(colorBox[k].gray); grayTotal = grayTotal + grayBox[k]; Hence, Step 7 – Summation of CMYK Color valuesInside the " cyanBox[k] = Math.round(colorBox[k].cyan); magentaBox[k] = Math.round(colorBox[k].magenta); yellowBox[k] = Math.round(colorBox[k].yellow); blackBox[k] = Math.round(colorBox[k].black); cyanTotal = cyanTotal + cyanBox[k]; magentaTotal = magentaTotal + magentaBox[k]; yellowTotal = yellowTotal + yellowBox[k]; blackTotal = blackTotal + blackBox[k]; To understand what is being performed here, we will take an example of Cyan color. A similar operation is performed for magenta, yellow and black too. Once the summation is done, we can come out of the loop and proceed ahead for average. Step 8 – Averaging the Color ValuesWe have gathered the individual summation of } // end for k loop var finalBlack = blackTotal + grayTotal; var newCyan = Math.round(cyanTotal / numOfStops); var newMagenta = Math.round(magentaTotal / numOfStops); var newYellow = Math.round(yellowTotal / numOfStops); var newBlack = Math.round(finalBlack / numOfStops); In the above lines of code, we are dividing individual summations of C, M, Y and K by Note the tricky case of gray and black here. The summation of K is not just Why we have done that? There are cases when a gradient fill may contain both GrayColor stops and CMYK stops. In that case, the gray Color values are added to the K value of the CMYK color. Gray can not be added to cyan, magenta or yellow. It will fall in the category of K only. Now we have all the new averaged values for C, M, Y and K in hand. In the next step, we will implement these values as a new CMYK color on the current object. Step 9 – Implementing the New ColorTo implement the new color, we will create a new var newColor = new CMYKColor(); newColor.cyan = newCyan; newColor.magenta = newMagenta; newColor.yellow = newYellow; newColor.black = newBlack; currentObject.fillColor = newColor; We have created a |
20 Tutorials to Help Master Illustrator’s Gradient Mesh
|
The gradient mesh is one of the most powerful tools in your Illustrator toolbox, but it’s also one of the trickiest to get the hang of. This year I’m determined to master this amazing tool, so I’ve searched the web far and wide to pull together the best free training materials. This collection of tutorials covers everything from basic gradient mesh tool to some full on photorealistic vector designs. If, like me you have a mission to get to grips with gradient mesh, look no further than this collection of resources.
Gradient mesh capabilitiesYou only have to glance at amazing artwork such as this motorcycle rendering by Yukio Miyamoto to realise how powerful the gradient mesh tool can be. It allows the most minute control over colour gradients, enabling you to recreate highlights and shadows that help produce photorealistic images. I like to think of the gradient mesh like the great Nunchaku, it’s a weapon of awesome capabilities that when used to its full potential by masters like Bruce Lee or Michelangelo the turtle looks insanely awesome. However it takes years of practice to become a true ninja. The same goes with the gradient mesh, when in the hands of a veteran, it can be used to create some unbelieveable photorealistic artwork, but it takes time, dedication and mental power to become a true master. Wrap a scarf around your head Karate Kid style and let’s get down to some serious training with these tutorials! Gradient mesh tutorialsTips for Working with the Gradient Mesh Tool In IllustratorHow to Make a Vector Military Cap IconIllustrator Tutorial: Gradient Mesh FlowerCreate a Yummy Ice Cream Icon with Mesh Objects and BlendsCreate realistic illustrations using Illustrator’s Gradient MeshVectors Imitate Life with Gradient MeshGradient Mesh TutorialIllustrate a Pair of Sweet Gradient Mesh CherriesGradient Mesh Bell Pepper TutorialMaster the gradient mesh toolMake a Shiny Gum Ball Machine with Mesh GradientsGradient Mesh Editing TutorialHow to Create an Energy Saving Bulb in IllustratorMastering MeshMake an Aurora Borealis Design in IllustratorIllustrator Tutorial: Realistic CurtainVideo TutorialsSometimes it’s handy to get that extra level of help from a video screencast. These tutorials help you understand the actual workflow and see the techniques in action. |
How to Create a Mesh Flower in Illustrator
|
In this tutorial, we'll explain how to create a flower with Illustrator’s mesh tools and opacity masks. With these tools you have a high-degree of control and can create realistic looking illustrations. Let’s get started!
Final Image PreviewBelow is the final image we will be working towards. Want access to the full Vector Source files and downloadable copies of every tutorial, including this one? Join Vector Plus for just 9$ a month. Tutorial Details
![]() Step 1Open up a new document and select the Polygon Tool. Click once on the artboard and choose Radius 50pt and Sides: 6 in the pop up window. Fill the polygon with an orange color. ![]() Step 2Select the Mesh Tool (U) and start adding mesh points. Click once on the top line of the polygon. ![]() Step 3Then repeat the step by clicking in the middle and on the right of the top horizontal line of the polygon as shown. ![]() Step 4Then click once right into the middle of the polygon with the Mesh Tool (U). ![]() Step 5Select the Direct selection Tool (A) and highlight the center mesh point, then fill it with a darker orange. ![]() Step 6Next, select each corner mesh point and fill it with a yellow. ![]() Step 7Start dragging each middle mesh point of each side of the polygon towards the middle until you create a similar star shape, just like you see in the image below. ![]() Step 8Let’s move onto the flower pedal creation. Select the Pen Tool (P) and draw a similar shape as shown in the image below. Fill it with 5% Black. ![]() Step 9Create another shape similar to the one shown below, which will be the bottom part of the flower pedal. Fill it with a pink or any other color of your choice. Then go to Effect > Stylize > Feather, then set the Feather amount to 5pt. Place it on top of the gray pedal. ![]() Step 10Apply mesh points to the pedal with the Mesh Tool (U). Select random mesh points and fill them with a darker gray. ![]() Step 11Select the smaller pink shape and make a copy. Then scale it down to about 75% of the original one. Fill it with a darker pink or a purple. Apply a Feather effect of 2pt. ![]() Step 12Group the flower pedal and the two small shapes together. Then select the grouped shape and Rotate (R) and duplicate it until you have six pedals. |



































Follow Us!