Overblog Suivre ce blog
Editer la page Administration Créer mon blog
/ / /

Ce script donne un exemple de plusieurs techniques de dessin/peinture par script.

  

Il suffit de copier le script ci-dessous dans un fichier .JSX et de le lancer sous Photoshop (Fichier/Scripts/Parcourir) pour voir se construire une image en couleur de ces voeux ! 

Avant le lancement il faut sélectionner dans PS une jolie brosse (une forme) qui servira de base au script.

Le choix de la brosse détermine une grande part de l'apparence finale.

Mais rien n'empêche d'essayer plusieurs brosses... 

 

Par choix, le script n'utilise que du tracé sous Photoshop (pas de filtre). J'espère que cela pourra être utile aux scripteurs.

 

Avant le source, voici quelques images réalisées avec des brosses différentes.

Mais comme beaucoup de paramètres sont tirés au hasard, les images seront différentes même avec la même brosse. Et puis c'est amusant de voir se dérouler le script et l'image se construire progressivement !

 

Pour modifier les couleurs, à vous de touiller le code.

 

happynewyear01 100a4

 

 

happynewyear04 100a4

 

happynewyear08 100a4

 

/************************************************************************
   Happy New Year
 ************************************************************************
 28/12/2010 Habaki V1r01 : Creation
 ************************************************************************/
var ScriptName= "Happy New Year";

var docW = 3500; // Width
var docH = 2360; // Height
var docRes = 300; // Resolution
var ColorBG = "FFFFFF";

var pathNb = 0;
var pathHNY;
var typeUnitsSaved, rulerUnitsSaved;
var Ratio = docRes / 72;
/*----------------------------------------------------------------------*
                        Draw line
 *----------------------------------------------------------------------*/

function DrawLine(doc, x1,y1,x2,y2)
{
  var line    = new Array(new PathPointInfo, new PathPointInfo);
  var subPath = new Array(new SubPathInfo);
  var path;
 
  x1 /= Ratio;
  y1 /= Ratio;
  x2 /= Ratio;
  y2 /= Ratio;
 
  //alert(x1 + ", " + y1 + "\n" + x2 + ", " + y2);
  line[0].kind   = PointKind.CORNERPOINT;
  line[0].anchor  = new Array(x1, y1);
  line[0].leftDirection  = line[0].anchor;
  line[0].rightDirection = line[0].anchor;
 
  line[1].kind   = PointKind.CORNERPOINT;
  line[1].anchor  = new Array(x2, y2);
  line[1].leftDirection  = line[1].anchor;
  line[1].rightDirection = line[1].anchor;
 
  subPath[0].operation = ShapeOperation.SHAPEADD;
  subPath[0].closed = false;
  subPath[0].entireSubPath = line;
 
  pathNb++;
  path = doc.pathItems.add("line"+pathNb, subPath);
  path.strokePath(ToolType.BRUSH, true);
  path.remove();
 
  return(0);
}
/*----------------------------------------------------------------------*
                        Draw Square
 *----------------------------------------------------------------------*/
function DrawSquare(doc, x1,y1, size)
{
  var line = new Array(new PathPointInfo,new PathPointInfo,new PathPointInfo,new PathPointInfo);
  var subPath = new Array(new SubPathInfo);
  var path;
  var r = Math.floor((Math.random() + 0.5) * size / Ratio);
 
  //x1 /= Ratio;
  //y1 /= Ratio;
 
  if (r > x1) r = x1;
  if (r > y1) r = y1;
  if (x1+r > docW) r = docW-x1-1;
  if (y1+r > docH) r = docH-y1-1;
 
  //alert(x1 + ", " + y1);
  line[0].kind   = PointKind.CORNERPOINT;
  line[0].anchor  = new Array(x1-r, y1-r);
  line[0].leftDirection  = line[0].anchor;
  line[0].rightDirection = line[0].anchor;
 
  line[1].kind   = PointKind.CORNERPOINT;
  line[1].anchor  = new Array(x1+r, y1-r);
  line[1].leftDirection  = line[1].anchor;
  line[1].rightDirection = line[1].anchor;
 
  line[2].kind   = PointKind.CORNERPOINT;
  line[2].anchor  = new Array(x1+r, y1+r);
  line[2].leftDirection  = line[2].anchor;
  line[2].rightDirection = line[2].anchor;
 
  line[3].kind   = PointKind.CORNERPOINT;
  line[3].anchor  = new Array(x1-r, y1+r);
  line[3].leftDirection  = line[3].anchor;
  line[3].rightDirection = line[3].anchor;
 
  subPath[0].operation = ShapeOperation.SHAPEADD;
  subPath[0].closed = true;
  subPath[0].entireSubPath = line;
 
  pathNb++;
  path = doc.pathItems.add("pt"+pathNb, subPath);
  //path.fillPath(app.foregroundColor);
  path.fillPath();
  path.remove();
 
  return(0);
}
/*----------------------------------------------------------------------*
   Wait
 *----------------------------------------------------------------------*/
function ForAWhile()
{
  DrawLine(app.activeDocument,-100,-100,-50,-50);
}
/*----------------------------------------------------------------------*
   Set Diameter
 *----------------------------------------------------------------------*/
function BrushDiameterSet(/* float */ Diam)
{
  var AD = new ActionDescriptor();
  var AR = new ActionReference();
  var AD2 = new ActionDescriptor();
 
  AR.putEnumerated(charIDToTypeID("Brsh"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
  AD.putReference(charIDToTypeID("null"), AR);
  AD2.putUnitDouble(stringIDToTypeID("masterDiameter"),
                    charIDToTypeID("#Pxl"), Diam);
  AD.putObject(charIDToTypeID("T   "), charIDToTypeID("Brsh"), AD2);
  executeAction(charIDToTypeID("setd"), AD, DialogModes.NO );
}
/*----------------------------------------------------------------------*
   Path
 *----------------------------------------------------------------------*/
var thePath = Array("HNY",PathKind.NORMALPATH
//SubPath 0 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(507,234),Array(407,585),Array(309,1002),Array(479,1037),Array(715,1063)
,Array(817,1045),Array(901,1009),Array(978,971),Array(1050,902),Array(1051,863)
,Array(1047,809),Array(1037,764),Array(977,707),Array(866,613),Array(813,571)
,Array(875,553),Array(929,523),Array(973,476),Array(987,424),Array(981,386)
,Array(897,321),Array(834,266),Array(775,231),Array(655,221),Array(578,218)
) // SubPath
//SubPath 1 ->
,Array(ShapeOperation.SHAPESUBTRACT,true
,Array(639,343),Array(596,502),Array(669,477),Array(735,446),Array(790,416)
,Array(828,381),Array(847,337),Array(776,329),Array(713,325)
) // SubPath
//SubPath 2 ->
,Array(ShapeOperation.SHAPESUBTRACT,true
,Array(560,683),Array(508,928),Array(611,935),Array(692,921),Array(759,893)
,Array(848,858),Array(913,789),Array(922,742),Array(913,714),Array(901,703)
,Array(881,661),Array(853,639),Array(758,626),Array(677,630),Array(636,645)
,Array(589,663)
) // SubPath
//SubPath 3 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(1224,680),Array(1160,740),Array(1134,787),Array(1117,841),Array(1121,891)
,Array(1131,940),Array(1181,971),Array(1256,1022),Array(1357,1052),Array(1450,1042)
,Array(1509,1017),Array(1553,971),Array(1565,921),Array(1550,879),Array(1522,830)
,Array(1469,775),Array(1403,719),Array(1336,679),Array(1301,657),Array(1255,659)
) // SubPath
//SubPath 4 ->
,Array(ShapeOperation.SHAPESUBTRACT,true
,Array(1390,774),Array(1337,796),Array(1303,828),Array(1276,880),Array(1268,922)
,Array(1275,960),Array(1295,981),Array(1321,975),Array(1343,961),Array(1375,935)
,Array(1406,893),Array(1426,830),Array(1428,789),Array(1409,773)
) // SubPath
//SubPath 5 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(1671,665),Array(1575,949),Array(1724,1045),Array(1773,875),Array(1804,963)
,Array(1964,1060),Array(2167,721),Array(2058,585),Array(1871,869),Array(1800,759)
) // SubPath
//SubPath 6 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(2217,623),Array(2085,964),Array(2233,1061),Array(2301,845),Array(2323,948)
,Array(2467,1043),Array(2655,703),Array(2559,554),Array(2375,824),Array(2330,721)
) // SubPath
//SubPath 7 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(2777,604),Array(2595,971),Array(2739,1091),Array(3015,1095),Array(2907,983)
,Array(2771,973),Array(2808,895),Array(2988,913),Array(2879,786),Array(2855,787)
,Array(2873,741),Array(3215,715),Array(3139,557)
) // SubPath
//SubPath 8 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(778,1174),Array(394,2031),Array(389,2035),Array(567,2070),Array(716,1738)
,Array(887,1741),Array(941,2073),Array(1120,2083),Array(886,1314)
) // SubPath
//SubPath 9 ->
,Array(ShapeOperation.SHAPESUBTRACT,true
,Array(824,1473),Array(740,1670),Array(867,1675)
) // SubPath
//SubPath 10 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(1237,2091),Array(1064,2045),Array(1232,1431),Array(1354,1561),Array(1413,1717)
,Array(1612,1295),Array(1713,1447),Array(1483,2004),Array(1320,1931),Array(1303,1784)
,Array(1237,2069)
) // SubPath
//SubPath 11 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(1815,1346),Array(1617,1914),Array(1785,1972),Array(1863,1713),Array(1884,1939)
,Array(2052,2006),Array(2351,1483),Array(2349,1452),Array(2364,1421),Array(2259,1277)
,Array(2236,1319),Array(2223,1370),Array(1998,1727),Array(1917,1472)
) // SubPath
//SubPath 12 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(2223,1894),Array(2444,1324),Array(2663,1283),Array(2746,1438),Array(2549,1467)
,Array(2497,1589),Array(2554,1587),Array(2680,1704),Array(2464,1695),Array(2413,1835)
,Array(2498,1834),Array(2634,1926),Array(2388,1973)
) // SubPath
//SubPath 13 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(2879,1305),Array(2629,1866),Array(2793,1969),Array(3199,1961),Array(3081,1858)
,Array(2806,1870),Array(2886,1680),Array(3123,1635),Array(3036,1516),Array(2933,1531)
,Array(2964,1444),Array(3397,1362),Array(3325,1225)
) // SubPath
//SubPath 14 ->
,Array(ShapeOperation.SHAPEADD,true
,Array(2552,1225),Array(2676,1136),Array(2724,1205),Array(2570,1256)
) // SubPath
);
/*----------------------------------------------------------------------*
   Build path from Data
 -> pathHNY
 *----------------------------------------------------------------------*/
function PathBuild(path)
{
  var spath;
  var line;
  var subPath;
  var pointInfo, pathInfo;
 
  subPath = new Array();
  for (var j=2;j<path.length;j++) {
    spath = path[j];
   
    line = new Array();
    for (var k=2;k<spath.length;k++) {
      pointInfo = new PathPointInfo();
      pointInfo.kind  = PointKind.CORNERPOINT;
      spath[k][0] /= Ratio;
      spath[k][1] /= Ratio;
      pointInfo.anchor  = spath[k];
      pointInfo.leftDirection = pointInfo.anchor;
      pointInfo.rightDirection = pointInfo.anchor;
      line[k-2] = pointInfo;
    } // for
   
    pathInfo = new SubPathInfo();
    pathInfo.operation = spath[0];
    pathInfo.closed = spath[1];
    pathInfo.entireSubPath = line;
    subPath[j-2] = pathInfo;
  } // for
  pathHNY = doc.pathItems.add(path[0], subPath);
  pathHNY.deselect();
  return(pathHNY);
}
/*----------------------------------------------------------------------*
   Main
 *----------------------------------------------------------------------*/
typeUnitsSaved  = app.preferences.typeUnits;
rulerUnitsSaved = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits  = TypeUnits.PIXELS;

try {
  var doc;
  var x1,y1,x2,y2;
  var i, j;
  var LPath,L0, L1, L2, L3, LT;
  var color;
  var path0;
 
  if (confirm("Avant de Commencer, Selectionner une jolie brosse !"
              +"\nPar exemple le Brin d'Herbe..."
              +"\nEst-ce fait ?"
              +"\n(le script dure quelques minutes: selon la brosse et l'ordi !)"
              , true, ScriptName)) {
   
    app.backgroundColor.rgb.hexValue = ColorBG;
   
    doc = app.documents.add(docW,docH, docRes,
           "HappyNewYear",
           NewDocumentMode.RGB, DocumentFill.BACKGROUNDCOLOR);
    //doc = app.activeDocument;
   
    L0 = doc.activeLayer;
    L1=doc.artLayers.add();
    L1.name = "Lignes";
    L2=doc.artLayers.add();
    L2.name = "Contour";
    L3=doc.artLayers.add();
    L3.name = "Carres";
    LT=doc.artLayers.add();
    LT.name = "Sign";
    LT.kind = LayerKind.TEXT;
    LT.textItem.contents = "Habaki";
    LT.textItem.size = 20;
    LT.textItem.font = "Arial";
    LT.textItem.color.rgb.hexValue = "FFFFFF";
    LT.translate(docW*4/5, docH*4/5 + 100);
    LT.visible = false;
    LPath =doc.artLayers.add();
    LPath.name = ScriptName;
    doc.activeLayer = LPath;
   
    PathBuild(thePath);
    color = new SolidColor();
    color.rgb.hexValue = ColorBG;
    //pathHNY.fillPath(color);
    pathHNY.makeSelection();
    doc.selection.fill(color);
    doc.selection.deselect();
   
    BrushDiameterSet(docRes);
   
    // Lignes
    doc.activeLayer = L1;
    app.backgroundColor.rgb.hexValue = "000000";
    x1 = Math.random()*docW;
    y1 = Math.random()*docH;
    for (i=0;i<200;i++) {
      x2 = (Math.random()*1.4 - 0.2)*docW;
      y2 = (Math.random()*1.4 - 0.2)*docH;
      color = Math.floor(Math.random() * 0x0FFFFFF).toString(16);
      color = "000000".slice(0,6-color.length) + color;
      app.foregroundColor.rgb.hexValue = color;
      DrawLine(doc,x1,y1,x2,y2);
      x1 = x2;
      y1 = y2;
    } // for
   
    // Fond noir
    L0.invert();
    ForAWhile();
   
    // Rouge
    doc.activeLayer = L3;
    app.foregroundColor.rgb.hexValue = "FF0000";
    app.backgroundColor.rgb.hexValue = "000000";
    pathHNY.makeSelection();
    doc.selection.fill(app.foregroundColor);
    doc.selection.deselect();
    x2 = y2 = 0;
    for (i=2;i<thePath.length;i++) {
     path0 = thePath[i];
     if (path0[0] != ShapeOperation.SHAPEADD) continue;
     for (j=2;j<path0.length;j++) {
       app.foregroundColor.rgb.red = Math.floor(Math.random()*255);
        x1 = path0[j][0];
        y1 = path0[j][1];
        //alert(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
        DrawSquare(doc,x1,y1,200);
        ForAWhile();
        x2 = x1;
        y2 = y1;
     } // for
    } // for
   
    pathHNY.makeSelection();
    doc.selection.invert();
    doc.selection.clear();
    doc.selection.deselect();
   
    LPath.visible = false;
   
    doc.activeLayer = L2;
    BrushDiameterSet(docRes/3);
    app.foregroundColor.rgb.hexValue = "FFFFFF";
    app.backgroundColor.rgb.hexValue = "FFFFFF";
    pathHNY.strokePath(ToolType.BRUSH, false);
    pathHNY.strokePath(ToolType.BRUSH, false);
   
    LT.visible = true;
    pathHNY.remove();
    LPath.remove();
    doc.flatten();
    //alert("Fini", ScriptName);
  }
} catch (e) {
  alert("Selectionner une Brosse svp !"
      + "\nC'est sans doute le probleme !");
  alert(e.message, ScriptName);
}
app.preferences.rulerUnits = rulerUnitsSaved;
app.preferences.typeUnits  = typeUnitsSaved;

 

Partager cette page

Repost 0
Published by