Saturday, January 3, 2015

Trying to plot a sine wave using Javascript in a Photoshop Script


I have to create this sine wave inside a layer on an image I already have.


The image is 600 dpi, 10x10cm and I have a new layer created at the top that is selected.


The image is CMYK.


I have to run this javascript that creates a sine wave that is 20 px away for the four margins.


I have ever created a script for photoshop.



I am experimenting with this script that is a copy paste from several things I have found on the web.


app.bringToFront();  

app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var Colour = new SolidColor;
Colour.rgb.hexValue = '000000';



var document = app.documents.add();

var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');


var divisions = 100;
var pi = 3.1415;

var step = pi/divisions;

var margin = 20;

var w = app.activeDocument.width.toString().replace(' px', '');
var h = app.activeDocument.height.toString().replace(' px', '');

w = parseInt(w);
h = parseInt(h);


var marginX = 20;
var marginY = 20;

var amplitude = h-2*marginY;

var fn = "Math.sin(x)*amplitude";

for (var positionX = 0; positionX < pi; step++)
{
makeSine (positionX+marginX, amplitude);

}

function makeSine(positionX, amplitude)
{

var y = eval(fn);
// HERE COMES THE MAGIC FUNCTION
}

This creates a new image completely blank because I need a magic function to put where it is written... "HERE COMES THE MAGIC FUNCTION"... 😃



Thanks for any help




No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...