The Stroke Rotation Raster changes stroke width and rotation of a given graphic object according to the gray values of the pixels in a raster image.
This script is now included in the Examples/Rasters folder in the Scriptographer package.
C:\Program Files\Adobe\Adobe Illustrator CS2\Plug-ins\Scriptographer\Scriptographer\scripts\scripts\textpencil.js:205,0: TypeError: Cannot read property "0" from undefined (C:\Program Files\Adobe\Adobe Illustrator CS2\Plug-ins\Scriptographer\Scriptographer\scripts\scripts\textpencil.js#205)
java.lang.NullPointerException
at com.scriptographer.ai.Tool.setScript(Tool.java:68)
at com.scriptographer.gui.MainDialog$ToolButton.onClick(MainDialog.java:286)
at com.scriptographer.adm.Button.onNotify(Button.java:75)
at com.scriptographer.adm.NotificationHandler.onNotify(NotificationHandler.java:55)
C:\Program Files\Adobe\Adobe Illustrator CS2\Plug-ins\Scriptographer\Scriptographer\scripts\rasters\raster.js:11,0: TypeError: Cannot call method "getSelectedItems" of null (C:\Program Files\Adobe\Adobe Illustrator CS2\Plug-ins\Scriptographer\Scriptographer\scripts\rasters\raster.js#11)
java.lang.NullPointerException
at com.scriptographer.ai.Tool.setScript(Tool.java:68)
at com.scriptographer.gui.MainDialog$ToolButton.onClick(MainDialog.java:286)
at com.scriptographer.adm.Button.onNotify(Button.java:75)
at com.scriptographer.adm.NotificationHandler.onNotify(NotificationHandler.java:55)
Hej. Great work!
I wonder if anybody knows how to create a script that only affects the rotation (and NOT the width) of the stroke based on the grey values.
The idea is to create something like this:
monalisa
that's pretty easy, you'd have to modify jürgs "Stroke Raster Rotation" with something like this (caveat: untested)
//grab brightness from image
var bright = raster.getPixel( new Point(x,y) ).gray;
//brightness * 360 = angle
var deg = 360 * bright;
//draw line
var line = new Path.Line( x,y-(size*0.5), x,y+(size*0.5) );
line.strokeWidth = 1;
line.rotate( deg * (180/Math.PI) );
Ken
Thanks for your answer Ken.
But I am afraid that my js knowledge is not enough to make the script work.
I get an error in line 29: "var line = new Path.Line( x,y-(size*0.5), x,y+(size*0.5) );"
This is what I used:
include('Raster.js');
function createDot(x, y, dot) {
var item = dot.clone();
//grab brightness from image
var bright = raster.getPixel( new Point(x,y) ).gray;
//brightness * 360 = angle
var deg = 360 * bright;
item.strokeWidth = radius * values.scale;
item.position += new Point(x, y) * values.size;
item.rotate(radius * Math.PI * 2);
return item;
}
if (initRaster()) {
var components = {
size: { value: 10, label: 'Grid Size' },
scale: { value: 10, label: 'Stroke Scale' }
};
//draw line
var line = new Path.Line( x,y-(size*0.5), x,y+(size*0.5) );
line.strokeWidth = 1;
line.rotate( deg * (180/Math.PI) );
}
Any suggestions? :)
your error is because what i wrote is rather generic. to achieve what you want within the 'template' of jürgs script. would look like this:
the script works uses one main function (well... sort of, but let's not complicate things)
function createDot(x,y, dot, radius)
and all of the variables we need for your effect are already being passed to this function,
x,y = obvious
dot = the building block of the raster
radius = the grayscale value of the pixel read from the x,y of the image
therefore all we have to do is modify the createDot function.
//------------------------------------
function createDot(x, y, dot, radius) {
// brightness * 360 = rotation angle
var deg = 360 * radius;
// the snap method (below) allows us to lock our angle
// to certain increments (90 in your case)
deg = snap(deg, values.snap);
var item = dot.clone();
item.strokeWidth = dot.strokeWidth;
item.position += new Point(x, y) * values.size;
item.rotate( deg );
return item;
}
//------------------------------------
as you can see it didn't take much modification, now let's add a field to the pop-up window so we can change our what our angles will lock to
//------------------------------------
if (initRaster()) {
var components = {
size: { value: 10, label: 'Grid Size' },
scale: { value: 10, label: 'Stroke Scale' },
// a 'snap' variable is added to our pop-up window
// which allows to access it (values.snap) in our createDot function above
snap: { value: 90, label: 'Rotation Snap' }
};
var values = Dialog.prompt('Enter Raster Values:', components);
if (values) {
executeRaster(createDot);
}
}
//------------------------------------
lastly, let's not forget to include the function which gives us our snap value
//------------------------------------
// snap methods
function snap(value, snapAmt, roundFunction) {
if (roundFunction === undefined) roundFunction = Math.round;
return snapAmt * roundFunction(value / snapAmt);
}
//------------------------------------
hopefully this will help you a bit when creating your own scripts and if you haven't already i'd recommend going through the tutorials on this site http://scriptographer.org/tutorials/
Ken