Sg2.9
Stroke Rotation Raster
Recent RSS
Creator:  Jürg Lehni
Date:  29. June 2006, 01:49

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.

Please note:

This script is now included in the Examples/Rasters folder in the Scriptographer package.

error
From:  Caglar
Date:  19. November 2006, 00:39

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)

what value
From:  stephanie
Date:  18. July 2008, 22:05

it always crashes because of memory.
i want not millions of rasters only very rough, tried all kinds of values, but what is what? grid? stroke size? ok but even when i put grid 1 and stroke size 500 does not work:(:(

Re: what value
From:  zoster
Date:  29. January 2009, 17:34

cool tool! works for me!

from what i've seen, the number of elements = the nr of pixels (so scaqle down the image first. something aroung 60/40px shold work gret). grid size is the distance (in pt i think) between elements.

Rotation raster
From:  noko
Date:  31. March 2011, 16:06

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

Re: Rotation raster
From:  ken frederick
Date:  1. April 2011, 08:40

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

Re: Rotation raster
From:  noko
Date:  1. April 2011, 11:10

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? :)

Re: Rotation raster
From:  ken frederick
Date:  1. April 2011, 15:47

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

Re: Rotation raster
From:  noko
Date:  1. April 2011, 17:00

Thanks a lot Ken.

That was a great little tutorial!

I will try it as soon as I get home.

Noko.

Re: Rotation raster
From:  duyphamk
Date:  21. July 2011, 16:28

The strokes don't really rotate like the sample, only changing the stroke weight for me. I tried to increase the contrast of the image but it still doesn't work. Anyone has any tip? Thank you!

Re: Rotation raster
From:  Fabio
Date:  22. June 2012, 21:04

The same happens to me. The strokes do not rotate. I tried to use different image sizes, color, b&w, and nothing worked. Can you please tell us what we are missing?
Thank you very much!

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19