Thursday, December 01, 2022

On the speed of change.

Hi all, I haven't posted in a while, as I've been focused in other things, but I had an experience I thought needed sharing. Please indulge me, I promise, there is a nice script at the end of the story. :) 

A couple nights ago, I was working on an illustration, and wanted to 'explode' all the objects, such that they were spaced out from each other instead of touching, like this: 


I fired up my editor and started coding, and quickly realized, it has been so long, I've forgotten most of the Adobe scripting API. I looked at a few of my old examples, and re-looked up a quick script for creating vectors so I could calculate distances, and about 20 or so minutes in, realized how fiddly js4ai can be, and this was more effort than I wanted to spend right now on this, and that would have likely been the end of that.

...until today, when a friend at work posted a link to chat.openai.com, saying "Check this out, it's cool."

"Cool" might have been the understatement of the year. The site, exposes a conversational AI agent that can dialog. It was like talking to c3p0, but for real. So, I ran it through the gauntlet. 


It intelligently refused to predict the stock market.

It gave a logical response about the nature of consciousness.

It gave me a nice haiku about the nature of consciousness.

So I gave it some coding questions. I asked it to give me a regex that could parse a url. It did so, along with a nice explanation of what it was doing. 

... ok well this information is well known, google can do that. So I thought, let's give it something harder.


Here's where the magic happens. I entered into the prompt, something like: 

"Write me a javascript for Adobe Illustrator that moves each element in the selection 30 percent away from the selections center"

Four seconds later, it poops out the following script, and it WORKS!

   if (app.documents.length > 0) {

   // Get the current document and selection
   var doc = app.activeDocument;
   var sel = doc.selection;
 
   // Calculate the center of the selection
   var xCenter = 0;
   var yCenter = 0;
   for (var i = 0; i < sel.length; i++) {
     xCenter += sel[i].position[0];
     yCenter += sel[i].position[1];
   }
   xCenter /= sel.length;
   yCenter /= sel.length;
 
   // Move each selected object by 30% of its current distance from the center of the selection
   for (var i = 0; i < sel.length; i++) {
     var xDist = sel[i].position[0] - xCenter;
     var yDist = sel[i].position[1] - yCenter;
     var dist = Math.sqrt(xDist * xDist + yDist * yDist);
     var xMove = xDist * 0.3;
     var yMove = yDist * 0.3;
 
     sel[i].position = [sel[i].position[0] + xMove, sel[i].position[1] + yMove];
   }
 }

Please appreciate what this is doing. Based on a text description, an ai, in real time is writing a script using a proprietary API, and it added code comments too!!!

OMG. @#JNK$U)(@# :mind-blown: JFC 

Anyway. If you're a designer that wants a script, I am now obsolete. Sign up for an account with openai, and have fun! The sky is the limit. Link in the comments if you create anything cool!