<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>richardjdare.com &#187; javascript</title>
	<atom:link href="http://richardjdare.com/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://richardjdare.com</link>
	<description>Games, Ideas, Imagination</description>
	<lastBuildDate>Thu, 06 Apr 2023 12:02:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>The Next Photoshop</title>
		<link>http://richardjdare.com/blog/2013/02/the-next-photoshop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-next-photoshop</link>
		<comments>http://richardjdare.com/blog/2013/02/the-next-photoshop/#comments</comments>
		<pubDate>Sun, 24 Feb 2013 15:06:12 +0000</pubDate>
		<dc:creator><![CDATA[Richard Dare]]></dc:creator>
				<category><![CDATA[photoshop]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[photoshop scripting]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://richardjdare.com/blog/?p=905</guid>
		<description><![CDATA[If you’ve read this blog for very long you’ll know that I am a big fan of Photoshop scripting and procedural graphics. Toxin, the iPhone.]]></description>
				<content:encoded><![CDATA[<p>If you’ve read this blog for very long you’ll know that I am a big fan of Photoshop scripting and procedural graphics. <a href="http://toxingame.com" target="_blank">Toxin</a>, the iPhone game I’ve been <a href="http://richardjdare.com/blog/category/toxin/" target="_blank">working on</a>, uses procedural art and animated image processing effects extensively. I don’t think the game would be possible without Photoshop scripting.</p>
<p>However, Photoshop’s scripting system is far from perfect. You cannot access pixel data from within scripts, nor can you draw lines or circles or anything like that. These limitations have become really frustrating to me.</p>
<p>For example, on the day I started work on Toxin, I needed to draw an ellipse with precise dimensions. The whole game takes place inside an ellipse, you see. I couldn’t do it in Photoshop by clicking and dragging, it was too inaccurate, so I wrote a C program using the <a href="http://alleg.sourceforge.net/" target="_blank">Allegro</a> game library to create the precise shapes I needed. These were then loaded into Photoshop and used as guides while I created the game artwork.</p>
<p>Later I discovered <a href="http://processing.org/" target="_blank">Processing</a>, which is much quicker to develop in than C. I soon developed a workflow where I would go back and forth between Photoshop and Processing, generating procedural content then processing it or running it through scripts until I got the desired result.</p>
<p>Processing, however has some frustrating quirks of its own. As a simplified front end to Java, you often get Java errors that are incomprehensible without digging into the underlying platform. Also, it cannot effectively save semi-transparent PNGs which means that the anti-aliased sprites I was creating all had a solid background which had to be removed. I ended up redesigning my workflow and using the excellent Ghost and AntiGhost plugins from <a href="http://www.flamingpear.com/download.html" target="_blank">Flaming Pear</a> to overcome these problems.</p>
<h3>From graphics app to graphics platform</h3>
<p>All these issues got me thinking about what I really want from a high end graphics program. What I want is something like a programmable, graphical <a href="http://en.wikipedia.org/wiki/Lisp_machine" target="_blank">Lisp Machine</a>; a powerful graphics programming platform with the UI of an art application, not an art application with a bolted-on scripting system.</p>
<p>I want the ability to programmatically control every aspect of Photoshop from both external scripts and from a real-time <a href="http://en.wikipedia.org/wiki/Read–eval–print_loop" target="_blank">REPL</a> inside Photoshop that works like the command line used in some CAD programs.</p>
<p>I want to be able to type<em> line(10,10,100,100)</em> and have a line appear on my presently selected image. I want to be able to open the REPL and assign my current selection to a variable which I can later re-select with a simple command. I want to be able to access the pixel data in my images, and write my own filters in Javascript within the scripting system itself. I think anyone in high-end graphics or scientific imaging would love something like this.</p>
<p>A true graphics platform like I have described would likely have to be written from the ground up with programmability built in. Nevertheless I did spend some time finding out how far I could go with Photoshop&#8217;s native capabilities.</p>
<p>I had the idea of writing a Photoshop plugin that contained a number of drawing functions which could be called from scripts via a Javascript library that integrates with the Photoshop document model. So you could write <em>PSDraw.line(10,10,100,100);</em> in ExtendScript Toolkit, and my Javascript library would construct a call to the plugin which would draw the line.</p>
<p>Unfortunately, it&#8217;s not possible to get information from a plugin back to the Photoshop script thats running it, so it wouldn&#8217;t be possible to do a <em>getPixel()</em> or anything like that. At best, this plugin/script combo would give us a somewhat clunky way of drawing programmatically but little else that would justify the effort involved. (have you ever seen the <a href="http://www.mactech.com/articles/mactech/Vol.15/15.04/PhotoshopPlug-InsPart1/index.html" target="_blank">Photoshop plugin API?</a>)</p>
<p>As a secondary option I thought about actually embedding <a href="https://code.google.com/p/v8/" target="_blank">V8</a> inside a plugin which would contain an editor and debugger. Besides the ugliness of having 2 distinct Javascript engines running in the same app, the plugin architecture put paid to this idea. Photoshop plugins are one-shot operations. Load the plugin, set the parameters, perform the operation, then shutdown. My idea would only be effective if the plugin was a persistent part of the Photoshop environment.</p>
<p>So the only options then, would be for Adobe to integrate scripting more completely, or for someone else to start making what would be a true sucessor to Photoshop.</p>
<p>&nbsp;</p>
<p><figure class='media-wrapper player'><iframe width="500" height="375" src="http://www.youtube.com/embed/mOZqRJzE8xg?wmode=transparent" frameborder="0" allowfullscreen wmode="Opaque"></iframe></figure></p>
]]></content:encoded>
			<wfw:commentRss>http://richardjdare.com/blog/2013/02/the-next-photoshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SpriteGrabber &#8211; Photoshop Scripting for Game Development</title>
		<link>http://richardjdare.com/blog/2009/06/spritegrabber-photoshop-scripting-for-game-development/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spritegrabber-photoshop-scripting-for-game-development</link>
		<comments>http://richardjdare.com/blog/2009/06/spritegrabber-photoshop-scripting-for-game-development/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 20:53:16 +0000</pubDate>
		<dc:creator><![CDATA[Richard Dare]]></dc:creator>
				<category><![CDATA[game development]]></category>
		<category><![CDATA[photoshop]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[photoshop scripting]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://richardjdare.com/blog/?p=25</guid>
		<description><![CDATA[One of the most common and tedious tasks in 2D game development is making sprite sheets from dozens or often hundreds of individual image files..]]></description>
				<content:encoded><![CDATA[<p>One of the most common and tedious tasks in 2D game development is making sprite sheets from dozens or often hundreds of individual image files. Back when I was making <a href="http://richardjdare.com/blog/games/">Starblaster</a>, I laid out several hundred sprites by hand. It took many, many hours and severely restricted my ability to experiment with different graphics. It&#8217;s even worse these days since most sprites use alpha channels; the semi-transparent images are almost impossible to line up by hand, and some particle effects are practically invisible unless they are laid on a dark background.</p>
<p>For my latest project (more info coming soon!) I decided I&#8217;d had enough of this drudgery, and wrote a Photoshop script to do the job for me.</p>
<p><img class="size-full wp-image-26 aligncenter" style="border-color: white;" title="spritegrabber01" src="http://richardjdare.com/blog/wp-content/uploads/2009/06/spritegrabber01.jpg" alt="SpriteGrabber v0.1" width="495" height="492" /></p>
<p>SpriteGrabber will take a directory full of image files and lay them out for you on one or more sprite sheets. Additionally, SpriteGrabber can export a text file containing information about each sprite. You can use this feature to generate calls to whatever function you use to load the sprites in your game.</p>
<h3>Instructions</h3>
<p>To run the script in Photoshop just go to File-&gt;Scripts-&gt;Browse and load the SpriteGrabber.jsx file from wherever you downloaded it to. It will run automatically and present you with the interface above.</p>
<p>Click &#8220;browse&#8221; and select the directory containing your sprites. SpriteGrabber will now process the directory and work out how many valid image files there are and how big the sprites are going to be. If you have different sized images in the directory, SpriteGrabber will use the largest dimensions to determine the sprite size.</p>
<p>Once the images are processed, the script will work out how many rows and columns there&#8217;ll be per page and how many pages will be needed to hold all the sprites. You can adjust the document width and height to alter these properties. Once you are happy, just click &#8220;Ok&#8221; to generate the sprite sheets.</p>
<h3>Datafile Export</h3>
<p>If you tick the &#8220;Enable datafile export&#8221; checkbox, SpriteGrabber will create a text file in the src directory called &#8220;SpriteInfo.txt&#8221;, containing a line of text for each sprite.</p>
<p>Each line is generated from the text entered into the &#8220;line template&#8221; edit box. Tags are used to substitute information about each sprite into the text.</p>
<p><strong>#i </strong>&#8211; Sprite index (0.. number of sprites in directory)</p>
<p><strong>#filename</strong> &#8211; Filename of source image</p>
<p><strong>#width</strong> &#8211; Sprite width</p>
<p><strong>#height</strong> &#8211; Sprite height</p>
<p><strong>#x</strong> &#8211; X position  of top left corner on spritesheet</p>
<p><strong>#y </strong>&#8211; Y position of top left corner on spritesheet</p>
<p>Lets say your game engine loads sprites like this: &#8220;SpriteManager-&gt;GetSprite(x,y,width,height);&#8221; and you have 300 sprites to load. You can generate all 300 calls by entering the following into the line template box:</p>
<p>SpriteManager-&gt;GetSprite(#x,#y,#width,#height);</p>
<p>SpriteGrabber will then generate 300 lines containing the correct coordinates and dimensions for each sprite. (This is probably a poor example as in real life you&#8217;d use a simple loop to do this, but it does illustrate how the feature works. The datafile export will come into its own when the next version is complete.)</p>
<h3>The Future</h3>
<p>SpriteGrabber is not intended as a masterclass in Photoshop scripting. In fact it&#8217;s the first script I&#8217;ve ever written, but it should help trim a few tedious hours off the development process. Soon I hope to have a new version ready that will be able to efficiently arrange sprites or textures of any size.</p>
<h3>Download</h3>
<p>SpriteGrabber has been tested on Photoshop CS2,CS4,CS5 for Windows Vista, and CS3,CS5 for Mac OS X.</p>
<h3><a href="http://richardjdare.com/files/spritegrabber-v0.5.zip" target="_blank"><img class="alignnone size-full wp-image-27" title="download" src="http://richardjdare.com/blog/wp-content/uploads/2009/06/download.png" alt="" width="160" height="45" /></a></h3>
]]></content:encoded>
			<wfw:commentRss>http://richardjdare.com/blog/2009/06/spritegrabber-photoshop-scripting-for-game-development/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
