<?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>soledad penadés</title>
	<atom:link href="http://soledadpenades.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://soledadpenades.com</link>
	<description>repeat 4[fd 100 rt 90]</description>
	<lastBuildDate>Wed, 25 Apr 2012 21:10:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Late Spectrum tribute</title>
		<link>http://soledadpenades.com/2012/04/25/late-spectrum-tribute/</link>
		<comments>http://soledadpenades.com/2012/04/25/late-spectrum-tribute/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 21:10:33 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[retro]]></category>
		<category><![CDATA[spectrum]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=3964</guid>
		<description><![CDATA[Sorry for being late to the Speccy 30th anniversary party. Life got in the way. But I&#8217;m sure you understand. Although it&#8217;s not like I was a Spectrum expert anyway. In fact, we never were more than simple acquaintances, so to speak. While I spent evenings with my eyes fixated on a green screen, and [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for being late to the <a href="http://en.wikipedia.org/wiki/Sinclair_Spectrum">Speccy</a> 30th anniversary party. Life got in the way. But I&#8217;m sure you understand.<br />
<span id="more-3964"></span><br />
Although it&#8217;s not like I was a Spectrum expert anyway. In fact, we never were more than simple acquaintances, so to speak. While I spent evenings with my eyes fixated on a <a href="http://en.wikipedia.org/wiki/Amstrad_PCW">green screen</a>, and secretly longed for a magic event that would convert the phosphorus into something multicolour, our neighbour next door was playing games with his Spectrum.</p>
<p>He was subscribed to <a href="http://www.microhobby.org/">Micro-Hobby</a>; each month we saw the magazine punctually standing out of their postbox, wrapped in plastic cellophan. His face when collecting the magazine was one of anticipated joy. I could just imagine &#8211;maybe even envy&#8211; what he was about to experience. Games, demos, utilities. Digital sounds, colours. The novelties, the excitement of new things to come. All in the accompanying tapes, or in the listings inside the magazine.</p>
<p>I had to be content with turtle graphics, and a ridiculous beeper.</p>
<p>Granted, even though it was monochrome, it was extremely cool anyway &#8211;almost no one else in the school had ever put a finger over a computer keyboard <em>ever</em>&#8211;, but the rest of the world was trying hard to make me feel <em>green</em> with envy. There was no way I could escape knowing that there were other sorts of computers which could make noises and show colour graphics.</p>
<p>One went to buy a dishwasher and there were several Spectrum models, games and accessories for them, side by side with fridges, ovens and whatnot. Even newsagents had a stand or a couple of shelves with Spectrum tapes at quite cheap prices. </p>
<p>Talking about newspapers, one of the most popular &#8211;&#8221;El País&#8221;&#8211; published the usual week-end supplement: interviews, opinion columns, fashion, cooking, etc. There was also a little sort-of leaflet in the center of the magazine, called &#8220;Pequeño País&#8221;, which roughly consisted in a handful of pages covering topics that children and youngsters could be interested in: movie and book reviews, a couple of comic pages from some well-known author (e.g. <a href="http://en.wikipedia.org/wiki/Blueberry_(comics)">Blueberry</a>), and maybe some more by an unknown but promising author.</p>
<p>As home computing grew in popularity during the 80s, in 1987 they started a new section, <a href="http://www.speccy.org/trastero/cosas/Revi/El_Tebeo_Informatico/Tebeo.html">El Tebeo Informático</a>, where they would review computer games. Probably even accompany the review with some cheats, in the shape of BASIC &#8216;pokes&#8217; or loaders. Of course, none of those games was published for the PCW, so I could only look at the screenshots, read the descriptions and dream with that day in which I would be able to experience those games myself.</p>
<p><img src="/imgs/2012/DavidElGnomo.gif" alt="David el Gnomo para Spectrum" /></p>
<p>One of my birthday presents was a cassette tape with the original soundtrack from a famous animated series (at the time), <a href="http://en.wikipedia.org/wiki/David_el_gnomo">David el Gnomo</a>. Of course, I was cursed with the best of the bad luck: the latest track in the B-side was a <a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0016905">computer game</a> for the Spectrum. In my innocence, I ended up one day subversively sneaking in the computer room and carefully examining the PCW&#8217;s disk drive, trying to find out if there was a way to fit the tape into the 3&#8243; drive, and thus play the game. Evidently, that didn&#8217;t work, and unfortunately there&#8217;s no available dump for the game, so the only thing I have ever seen to date are those screenshots from World Of Spectrum.</p>
<p>Sometimes, when we went to department stores, I was left on my own so that I could peruse the book shelves in order to find something I liked, while the rest of the family did the same. I loved going to the computer books section, and finding all those books on computer graphics, sound, and games&#8230; but I was then quite disappointed when finding that most of them were written with Spectrum Basic in mind, and thus even if I got the book I wouldn&#8217;t be able to type in and play with its listings.</p>
<p>The situation regarding technical press was more or less the same. Since no magazine was published exclusively for PCW users in Spain, I got to read Amstrad User. It was only about Amstrad at the beginning, but when Amstrad acquired Sinclair they ended up writing more and more about the Spectrum, even covering that <a href="http://www.crashonline.org.uk/58/pc200.htm">PC200</a> sort of strange hybrid fiasco between PC and Spectrum.</p>
<p><img src="/imgs/2012/spectrum_pack_t.jpg" alt="super spectrum pack" /></p>
<p>Around the summer of 1990 Amstrad released a series of super attractive Spectrum packs. They consisted in the computer, plus six games and a joystick! Woooow! I tried &#8211;in vain&#8211; to get one. I argued I had got my best marks <em>ever</em>, and if we got the Spectrum I would use the joystick to play games, so no keyboard would get damaged with repetitive <em>kick-kick-kick-kick</em> motions (such as when playing <a href="http://en.wikipedia.org/wiki/Last_Ninja_2">Last Ninja 2</a>) but that didn&#8217;t work. Instead, we got a PC that I was occasionally allowed to use. Granted, it was <em>way</em> faster than a Spectrum could ever hope to be, with its humble Z80 at 3.5MHz, and the <a href="http://soledadpenades.com/2012/04/09/webgl-vga/">VGA graphics</a> were way better, but somehow the Spectrum aesthetics had grown on me. I had heard and read so much about the Speccy, that I was missing it already.</p>
<p>Years later, emulators became feasible, but alas!, I didn&#8217;t have an Internet connection to download one&#8230;</p>
<p><img src="/imgs/2012/hobbytex_t.jpg" alt="Hobbytex" /></p>
<p>However, there was a way. It was quite a feat itself, now that I recall it, and certainly shows the lengths curiosity can drive people to. I used to buy a PC magazine, PCMania. The publishers, HobbyPress, maintained an Ibertex node. Ibertex was the Spanish network equivalent to the French <a href="http://en.wikipedia.org/wiki/Minitel">Minitel</a>. Each month they included their client software in the accompanying floppy disk. This client was quite advanced compared to the standard Ibertex clients, as it not only handled downloads but also was able to fragment them in parts, and therefore downloads could be resumed, a very nice feature as the phone line quality was fragile, so to speak.</p>
<p><img src="/imgs/2012/hobbytex_downloading.jpg" alt="Hobbytex downloading" /></p>
<p>Using that system, I downloaded Pedro Gimeno&#8217;s <a href="http://www.formauri.es/personal/pgimeno/spec/spec.html">Spectrum emulator</a>, and a couple of legendary Spanish Spectrum games: <a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0005977">La aventura original</a> and <a href="http://www.worldofspectrum.org/infoseekid.cgi?id=0000273">Army moves</a>. I still can&#8217;t understand how that could even run and be playable. I mean, an emulator for a 3.5MHz machine, running under a 12MHz machine! Spectrum emulators for nowadays phones can hardly process user input without lagging. I don&#8217;t know how Pedro did it, but I certainly played those games for weeks. It was great! And it was also certainly funny to be discovering the joys of the Spectrum while everyone in the media was already talking about the Internet, Mosaic, or the WWW.</p>
<p>However, I learnt a lot about the Spectrums since then; and all thanks to the Internet. I played more games thanks to emulators and sites such as <a href="http://www.worldofspectrum.org/">World of Spectrum</a>; I have listened to <a href="http://supersole.net/blog/post/109-1-bit-music">lots of Speccy music</a> (the so-called beeper music). Also I have enjoyed some glorious demos that pushed the envelope quite further, such as <q>Aah&#8230; the tape loading era</q>:</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/OJ01EDhL0VM" frameborder="0" allowfullscreen></iframe></p>
<p>or the <q>revision 2012 invtro</q>:</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/eFtmqCjU6Wo" frameborder="0" allowfullscreen></iframe></p>
<p>I even went as far as learning how the <a href="https://en.wikipedia.org/wiki/Attribute_clash">attribute clash</a> worked, and implemented a &#8220;ZX Spectrum&#8221; effect for my <em>8 bit retro camera</em> application for Android, <a href="http://5013.es/p/7">Nerdstalgia</a>. Yay!</p>
<p>At the end I never owned an Spectrum, but I feel like I owe them a little bit of my computer curiosity/motivation. So&#8230; here&#8217;s for 30 more years of retro-computer inspiration and achievements! <strong>Long live the Speccy, and all his cousins!</strong></p>
 <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=3964&amp;md5=5285c9a5df6dc79c747e4b8c45d88e9d" title="Flattr" target="_blank"><img src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2012/04/25/late-spectrum-tribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=8399&amp;amp;url=http%3A%2F%2Fsoledadpenades.com%2F2012%2F04%2F25%2Flate-spectrum-tribute%2F&amp;amp;language=en_GB&amp;amp;category=text&amp;amp;title=Late+Spectrum+tribute&amp;amp;description=Sorry+for+being+late+to+the+Speccy+30th+anniversary+party.+Life+got+in+the+way.+But+I%27m+sure+you+understand.%0D%0A%0D%0AAlthough+it%27s+not+like+I+was+a+Spectrum+expert+anyway.+In+fact%2C+we+never+were+more+than+simple+acquaintances%2C+so+to+speak.+While+I+spent+evenings+with+my+eyes+fixated+on+a+green+screen%2C+and+secretly+longed+for+a+magic+event+that+would+convert+the+phosphorus+into+something+multicolour%2C+our+neighbour+next+door+was+playing+games+with+his+Spectrum.%0D%0A%0D%0AHe+was+subscribed+to+Micro-Hobby%3B+each+month+we+saw+the+magazine+punctually+standing+out+of+their+postbox%2C+wrapped+in+plastic+cellophan.+His+face+when+collecting+the+magazine+was+one+of+anticipated+joy.+I+could+just+imagine+--maybe+even+envy--+what+he+was+about+to+experience.+Games%2C+demos%2C+utilities.+Digital+sounds%2C+colours.+The+novelties%2C+the+excitement+of+new+things+to+come.+All+in+the+accompanying+tapes%2C+or+in+the+listings+inside+the+magazine.%0D%0A%0D%0AI+had+to+be+content+with+turtle+graphics%2C+and+a+ridiculous+beeper.%0D%0A%0D%0AGranted%2C+even+though+it+was+monochrome%2C+it+was+extremely+cool+anyway+--almost+no+one+else+in+the+school+had+ever+put+a+finger+over+a+computer+keyboard+ever--%2C+but+the+rest+of+the+world+was+trying+hard+to+make+me+feel+green+with+envy.+There+was+no+way+I+could+escape+knowing+that+there+were+other+sorts+of+computers+which+could+make+noises+and+show+colour+graphics.%0D%0A%0D%0AOne+went+to+buy+a+dishwasher+and+there+were+several+Spectrum+models%2C+games+and+accessories+for+them%2C+side+by+side+with+fridges%2C+ovens+and+whatnot.+Even+newsagents+had+a+stand+or+a+couple+of+shelves+with+Spectrum+tapes+at+quite+cheap+prices.+%0D%0A%0D%0ATalking+about+newspapers%2C+one+of+the+most+popular+--%22El+Pa%C3%ADs%22--+published+the+usual+week-end+supplement%3A+interviews%2C+opinion+columns%2C+fashion%2C+cooking%2C+etc.+There+was+also+a+little+sort-of+leaflet+in+the+center+of+the+magazine%2C+called+%22Peque%C3%B1o+Pa%C3%ADs%22%2C+which+roughly+consisted+in+a+handful+of+pages+covering+topics+that+children+and+youngsters+could+be+interested+in%3A+movie+and+book+reviews%2C+a+couple+of+comic+pages+from+some+well-known+author+%28e.g.+Blueberry%29%2C+and+maybe+some+more+by+an+unknown+but+promising+author.%0D%0A%0D%0AAs+home+computing+grew+in+popularity+during+the+80s%2C+in+1987+they+started+a+new+section%2C+El+Tebeo+Inform%C3%A1tico%2C+where+they+would+review+computer+games.+Probably+even+accompany+the+review+with+some+cheats%2C+in+the+shape+of+BASIC+%27pokes%27+or+loaders.+Of+course%2C+none+of+those+games+was+published+for+the+PCW%2C+so+I+could+only+look+at+the+screenshots%2C+read+the+descriptions+and+dream+with+that+day+in+which+I+would+be+able+to+experience+those+games+myself.%0D%0A%0D%0A%0D%0A%0D%0AOne+of+my+birthday+presents+was+a+cassette+tape+with+the+original+soundtrack+from+a+famous+animated+series+%28at+the+time%29%2C+David+el+Gnomo.+Of+course%2C+I+was+cursed+with+the+best+of+the+bad+luck%3A+the+latest+track+in+the+B-side+was+a+computer+game+for+the+Spectrum.+In+my+innocence%2C+I+ended+up+one+day+subversively+sneaking+in+the+computer+room+and+carefully+examining+the+PCW%27s+disk+drive%2C+trying+to+find+out+if+there+was+a+way+to+fit+the+tape+into+the+3%22+drive%2C+and+thus+play+the+game.+Evidently%2C+that+didn%27t+work%2C+and+unfortunately+there%27s+no+available+dump+for+the+game%2C+so+the+only+thing+I+have+ever+seen+to+date+are+those+screenshots+from+World+Of+Spectrum.%0D%0A%0D%0ASometimes%2C+when+we+went+to+department+stores%2C+I+was+left+on+my+own+so+that+I+could+peruse+the+book+shelves+in+order+to+find+something+I+liked%2C+while+the+rest+of+the+family+did+the+same.+I+loved+going+to+the+computer+books+section%2C+and+finding+all+those+books+on+computer+graphics%2C+sound%2C+and+games...+but+I+was+then+quite+disappointed+when+finding+that+most+of+them+were+written+with+Spectrum+Basic+in+mind%2C+and+thus+even+if+I+got+the+book+I+wouldn%27t+be+able+to+type+in+and+play+with+its+listings.%0D%0A%0D%0AThe+situation+regarding+technical+press+was+more+or+less+the+same.+Since+no+magazine+was+published+exclusively+for+PCW+users+in+Spain%2C+I+got+to+read+Amstrad+User.+It+was+only+about+Amstrad+at+the+beginning%2C+but+when+Amstrad+acquired+Sinclair+they+ended+up+writing+more+and+more+about+the+Spectrum%2C+even+covering+that+PC200+sort+of+strange+hybrid+fiasco+between+PC+and+Spectrum.%0D%0A%0D%0A%0D%0A%0D%0AAround+the+summer+of+1990+Amstrad+released+a+series+of+super+attractive+Spectrum+packs.+They+consisted+in+the+computer%2C+plus+six+games+and+a+joystick%21+Woooow%21+I+tried+--in+vain--+to+get+one.+I+argued+I+had+got+my+best+marks+ever%2C+and+if+we+got+the+Spectrum+I+would+use+the+joystick+to+play+games%2C+so+no+keyboard+would+get+damaged+with+repetitive+kick-kick-kick-kick+motions+%28such+as+when+playing+Last+Ninja+2%29+but+that+didn%27t+work.+Instead%2C+we+got+a+PC+that+I+was+occasionally+allowed+to+use.+Granted%2C+it+was+way+faster+than+a+Spectrum+could+ever+hope+to+be%2C+with+its+humble+Z80+at+3.5MHz%2C+and+the+VGA+graphics+were+way+better%2C+but+somehow+the+Spectrum+aesthetics+had+grown+on+me.+I+had+heard+and+read+so+much+about+the+Speccy%2C+that+I+was+missing+it+already.%0D%0A%0D%0AYears+later%2C+emulators+became+feasible%2C+but+alas%21%2C+I+didn%27t+have+an+Internet+connection+to+download+one...%0D%0A%0D%0A%0D%0A%0D%0AHowever%2C+there+was+a+way.+It+was+quite+a+feat+itself%2C+now+that+I+recall+it%2C+and+certainly+shows+the+lengths+curiosity+can+drive+people+to.+I+used+to+buy+a+PC+magazine%2C+PCMania.+The+publishers%2C+HobbyPress%2C+maintained+an+Ibertex+node.+Ibertex+was+the+Spanish+network+equivalent+to+the+French+Minitel.+Each+month+they+included+their+client+software+in+the+accompanying+floppy+disk.+This+client+was+quite+advanced+compared+to+the+standard+Ibertex+clients%2C+as+it+not+only+handled+downloads+but+also+was+able+to+fragment+them+in+parts%2C+and+therefore+downloads+could+be+resumed%2C+a+very+nice+feature+as+the+phone+line+quality+was+fragile%2C+so+to+speak.%0D%0A%0D%0A%0D%0A%0D%0AUsing+that+system%2C+I+downloaded+Pedro+Gimeno%27s+Spectrum+emulator%2C+and+a+couple+of+legendary+Spanish+Spectrum+games%3A+La+aventura+original+and+Army+moves.+I+still+can%27t+understand+how+that+could+even+run+and+be+playable.+I+mean%2C+an+emulator+for+a+3.5MHz+machine%2C+running+under+a+12MHz+machine%21+Spectrum+emulators+for+nowadays+phones+can+hardly+process+user+input+without+lagging.+I+don%27t+know+how+Pedro+did+it%2C+but+I+certainly+played+those+games+for+weeks.+It+was+great%21+And+it+was+also+certainly+funny+to+be+discovering+the+joys+of+the+Spectrum+while+everyone+in+the+media+was+already+talking+about+the+Internet%2C+Mosaic%2C+or+the+WWW.%0D%0A%0D%0AHowever%2C+I+learnt+a+lot+about+the+Spectrums+since+then%3B+and+all+thanks+to+the+Internet.+I+played+more+games+thanks+to+emulators+and+sites+such+as+World+of+Spectrum%3B+I+have+listened+to+lots+of+Speccy+music+%28the+so-called+beeper+music%29.+Also+I+have+enjoyed+some+glorious+demos+that+pushed+the+envelope+quite+further%2C+such+as+Aah...+the+tape+loading+era%3A%0D%0A%0D%0A%0D%0A%0D%0Aor+the+revision+2012+invtro%3A%0D%0A%0D%0A%0D%0A%0D%0AI+even+went+as+far+as+learning+how+the+attribute+clash+worked%2C+and+implemented+a+%22ZX+Spectrum%22+effect+for+my+8+bit+retro+camera+application+for+Android%2C+Nerdstalgia.+Yay%21%0D%0A%0D%0AAt+the+end+I+never+owned+an+Spectrum%2C+but+I+feel+like+I+owe+them+a+little+bit+of+my+computer+curiosity%2Fmotivation.+So...+here%27s+for+30+more+years+of+retro-computer+inspiration+and+achievements%21+Long+live+the+Speccy%2C+and+all+his+cousins%21&amp;amp;tags=retro%2Cspectrum%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Simple yet Frequently Asked Questions on three.js (SFAQ)</title>
		<link>http://soledadpenades.com/2012/04/17/simple-yet-frequently-asked-questions-on-three-js-sfaq/</link>
		<comments>http://soledadpenades.com/2012/04/17/simple-yet-frequently-asked-questions-on-three-js-sfaq/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 19:43:37 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[sfaq]]></category>
		<category><![CDATA[three.js]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=3957</guid>
		<description><![CDATA[As promised, here&#8217;s what I learnt with my latest test with three.js :-D How do I get smooth color transitions between the vertices of a face? If you want to get color &#8220;interpolation&#8221; like the faces in the image&#8230; &#8230; you have to do a few things: Create a colors array, with as many entries [...]]]></description>
			<content:encoded><![CDATA[<p>As <a href="http://soledadpenades.com/2012/04/16/mesh-subdivision-2012-extended-edition/">promised</a>, here&#8217;s what I learnt with my <a href="http://lab.soledadpenades.com/js/mesh_subdivision">latest test</a> with <a href="https://github.com/mrdoob/three.js">three.js</a> :-D<br />
<span id="more-3957"></span></p>
<h3>How do I get smooth color transitions between the vertices of a face?</h3>
<p>If you want to get color &#8220;interpolation&#8221; like the faces in the image&#8230;<br />
<img src="/imgs/2012/ms02.jpg" alt="mesh subdivision" /></p>
<p>&#8230; you have to do a few things:</p>
<ol>
<li>Create a colors array, with as many entries as vertices in your mesh.</li>
<li>Set the colors array as the <strong>vertexColors</strong> property of the geometry</li>
<li>Using <strong>THREE.MeshBasicMaterial</strong>, set the <strong>vertexColors</strong> property to <strong>THREE.VertexColors</strong></li>
</ol>
<p>This would create a single-triangle mesh, with red, green and blue colors in each vertex respectively:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> vertices <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> colors <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> faces <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> geometry<span style="color: #339933;">,</span> material<span style="color: #339933;">,</span> mesh<span style="color: #339933;">;</span><br />
<br />
vertices.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
colors.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Color</span><span style="color: #009900;">&#40;</span>0xFF0000<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
vertices.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
colors.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Color</span><span style="color: #009900;">&#40;</span>0x00FF00<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
vertices.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
colors.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Color</span><span style="color: #009900;">&#40;</span>0x0000FF<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// 0, 1 and 2 are the indices of the vertices in the vertices array</span><br />
faces.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Face3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
geometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Geometry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertices</span> <span style="color: #339933;">=</span> vertices<span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">faces</span> <span style="color: #339933;">=</span> faces<span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertexColors</span> <span style="color: #339933;">=</span> colors<span style="color: #339933;">;</span><br />
<br />
material <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">MeshBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> vertexColors<span style="color: #339933;">:</span> THREE.<span style="color: #660066;">VertexColors</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
mesh <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Mesh</span><span style="color: #009900;">&#40;</span>geometry<span style="color: #339933;">,</span> material<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<h3>How do I change the line width of an object displayed as wireframe?</h3>
<p>Using <strong>THREE.MeshBasicMaterial</strong>, set the value of the wireframeLinewidth property:</p>
<p>E.g. for a black, three units thick wireframe material:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> mat <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">MeshBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> wireframeLinewidth<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> color<span style="color: #339933;">:</span> 0x000000<span style="color: #339933;">,</span> wireframe<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<h3>How do I make an object display as double-sided?</h3>
<p>I thought this was a property that had to be set in the material, but I was wrong. It&#8217;s an Object3D property, so if you want an object to display both of its sides, you have to do:</p>
<div class="syhi_block"><code>mesh.<span style="color: #660066;">doubleSided</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span></code></div>
<h3>Why aren&#8217;t the children objects hidden when the parent is <em>invisible</em>?</h3>
<p>For optimisation reasons this is not automatic. So you have to manually iterate over the parent&#8217;s children and set their visible property explicitly. But three.js has a utility function for traversing object hierarchies:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> visible <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
THREE.<span style="color: #660066;">SceneUtils</span>.<span style="color: #660066;">traverseHierarchy</span><span style="color: #009900;">&#40;</span>parent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>child<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; child.<span style="color: #660066;">visible</span> <span style="color: #339933;">=</span> visible<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<h3>How do I get the camera position updated? It&#8217;s not moving even if I change its position!</h3>
<p>Ah, because you have to tell it where to <em>lookAt</em>. Assuming <em>camera_x</em>, <em>camera_y</em> and <em>camera_z</em> are numbers, and <em>cam_target</em> is a <strong>Vector3</strong>:</p>
<div class="syhi_block"><code>camera.<span style="color: #660066;">position</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> camera_x<span style="color: #339933;">;</span><br />
camera.<span style="color: #660066;">position</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> camera_y<span style="color: #339933;">;</span><br />
camera.<span style="color: #660066;">position</span>.<span style="color: #660066;">z</span> <span style="color: #339933;">=</span> camera_z<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
camera.<span style="color: #660066;">lookAt</span><span style="color: #009900;">&#40;</span> cam_target <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<p>Every time you change either the camera position or the target position (or both!) you need to call <strong>camera.lookAt</strong> or you won&#8217;t get any visible result.</p>
<p>This seems to be a recent change in three.js. Apparently the camera was automatically updated in older revisions.</p>
<h3>How do I get the contents of the current canvas? All I get is an empty, transparent image in Chrome!</h3>
<p>This is an <a href="http://code.google.com/p/chromium/issues/detail?id=82086">expected</a> behaviour of the WebGL implementation. The solution is to create the WebGL context with the <em>preserveDrawingBuffer</em> flag. Of course, three.js already has that in mind!</p>
<p>So you simply have to add that parameter when initialising the renderer:</p>
<div class="syhi_block"><code>renderer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">WebGLRenderer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> preserveDrawingBuffer<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<p>Once that&#8217;s done you can happily extract screenshots of the current output with the usual <strong>canvas.toDataURL</strong> (although I <a href="http://soledadpenades.com/2012/04/16/mesh-subdivision-2012-extended-edition/">used</a> <strong>canvas.toBlob</strong> for directly downloading the image to the browser).</p>
<h3>How do I modify a geometry dynamically? (from javascript, not in a vertex shader)</h3>
<p>This is my super favourite question, so I left it for the end!</p>
<p>You can change the vertices position in a geometry once it&#8217;s been added to the scene, but you won&#8217;t notice any difference until you let three.js know that you&#8217;ve changed something in the object!</p>
<p>That&#8217;s done with:</p>
<div class="syhi_block"><code>mesh.<span style="color: #660066;">geometry</span>.__dirtyVertices <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span></code></div>
<p>every time you&#8217;ve modified the geometry and need to get it updated in the screen.</p>
<p><a href="http://mrdoob.com">Mr.doob</a> told me it&#8217;s also possible to modify other geometry properties, such as the vertex colors. If you modify the vertex colors, you then need to set the __dirtyColors property to true.</p>
<p>Actually, this is not the &#8216;proper&#8217; way of doing things with WebGL. Every time a geometry is marked as &#8216;dirty&#8217;, it needs to be re-sent and re-created in the GPU, so to speak. Therefore, this flexibility comes at a cost; the larger the geometry, the slowest it&#8217;ll be. I should be doing these calculations in a vertex shader, running in the GPU, but since I&#8217;m still learning I&#8217;m allowing myself this little computational luxury ;-)</p>
 <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=3957&amp;md5=873c8f2ce88b6b1c66096437672c5720" title="Flattr" target="_blank"><img src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2012/04/17/simple-yet-frequently-asked-questions-on-three-js-sfaq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=8399&amp;amp;url=http%3A%2F%2Fsoledadpenades.com%2F2012%2F04%2F17%2Fsimple-yet-frequently-asked-questions-on-three-js-sfaq%2F&amp;amp;language=en_GB&amp;amp;category=text&amp;amp;title=Simple+yet+Frequently+Asked+Questions+on+three.js+%28SFAQ%29&amp;amp;description=As+promised%2C+here%27s+what+I+learnt+with+my+latest+test+with+three.js+%3A-D%0D%0A%0D%0AHow+do+I+get+smooth+color+transitions+between+the+vertices+of+a+face%3F%0D%0A%0D%0AIf+you+want+to+get+color+%22interpolation%22+like+the+faces+in+the+image...%0D%0A%0D%0A%0D%0A...+you+have+to+do+a+few+things%3A%0D%0A%0D%0A%0D%0A%09Create+a+colors+array%2C+with+as+many+entries+as+vertices+in+your+mesh.%0D%0A%09Set+the+colors+array+as+the+vertexColors+property+of+the+geometry%0D%0A%0D%0A%09Using+THREE.MeshBasicMaterial%2C+set+the+vertexColors+property+to+THREE.VertexColors%0D%0A%0D%0A%0D%0AThis+would+create+a+single-triangle+mesh%2C+with+red%2C+green+and+blue+colors+in+each+vertex+respectively%3A%0D%0A%0D%0A%0D%0Avar+vertices+%3D+%5B%5D%2C+colors+%3D+%5B%5D%2C+faces+%3D+%5B%5D%2C+geometry%2C+material%2C+mesh%3B%0D%0A%0D%0Avertices.push%28+new+THREE.Vertex%28+new+THREE.Vector3%280%2C+0%2C+0%29+%29+%29%3B%0D%0Acolors.push%28+new+THREE.Color%280xFF0000%29+%29%3B%0D%0A%0D%0Avertices.push%28+new+THREE.Vertex%28+new+THREE.Vector3%280%2C+1%2C+0%29+%29+%29%3B%0D%0Acolors.push%28+new+THREE.Color%280x00FF00%29+%29%3B%0D%0A%0D%0Avertices.push%28+new+THREE.Vertex%28+new+THREE.Vector3%281%2C+1%2C+0%29+%29+%29%3B%0D%0Acolors.push%28+new+THREE.Color%280x0000FF%29+%29%3B%0D%0A%0D%0A%2F%2F+0%2C+1+and+2+are+the+indices+of+the+vertices+in+the+vertices+array%0D%0Afaces.push%28+new+THREE.Face3%280%2C+1%2C+2%29+%29%3B%0D%0A%0D%0Ageometry+%3D+new+THREE.Geometry%28%29%3B%0D%0Ageometry.vertices+%3D+vertices%3B%0D%0Ageometry.faces+%3D+faces%3B%0D%0Ageometry.vertexColors+%3D+colors%3B%0D%0A%0D%0Amaterial+%3D+new+THREE.MeshBasicMaterial%28%7B+vertexColors%3A+THREE.VertexColors+%7D%29%3B%0D%0A%0D%0Amesh+%3D+new+THREE.Mesh%28geometry%2C+material%29%3B%0D%0A%0D%0A%0D%0AHow+do+I+change+the+line+width+of+an+object+displayed+as+wireframe%3F%0D%0A%0D%0AUsing+THREE.MeshBasicMaterial%2C+set+the+value+of+the+wireframeLinewidth+property%3A%0D%0A%0D%0AE.g.+for+a+black%2C+three+units+thick+wireframe+material%3A%0D%0A%0D%0A%0D%0Avar+mat+%3D+new+THREE.MeshBasicMaterial%28%7B+wireframeLinewidth%3A+3%2C+color%3A+0x000000%2C+wireframe%3A+true+%7D%29%3B%0D%0A%0D%0A%0D%0AHow+do+I+make+an+object+display+as+double-sided%3F%0D%0A%0D%0AI+thought+this+was+a+property+that+had+to+be+set+in+the+material%2C+but+I+was+wrong.+It%27s+an+Object3D+property%2C+so+if+you+want+an+object+to+display+both+of+its+sides%2C+you+have+to+do%3A%0D%0A%0D%0A%0D%0Amesh.doubleSided+%3D+true%3B%0D%0A%0D%0A%0D%0AWhy+aren%27t+the+children+objects+hidden+when+the+parent+is+invisible%3F%0D%0A%0D%0AFor+optimisation+reasons+this+is+not+automatic.+So+you+have+to+manually+iterate+over+the+parent%27s+children+and+set+their+visible+property+explicitly.+But+three.js+has+a+utility+function+for+traversing+object+hierarchies%3A%0D%0A%0D%0A%0D%0Avar+visible+%3D+false%3B%0D%0ATHREE.SceneUtils.traverseHierarchy%28parent%2C+function%28child%29+%7B%0D%0A%09child.visible+%3D+visible%3B%0D%0A%7D%29%3B%0D%0A%0D%0A%0D%0AHow+do+I+get+the+camera+position+updated%3F+It%27s+not+moving+even+if+I+change+its+position%21%0D%0A%0D%0AAh%2C+because+you+have+to+tell+it+where+to+lookAt.+Assuming+camera_x%2C+camera_y+and+camera_z+are+numbers%2C+and+cam_target+is+a+Vector3%3A%0D%0A%0D%0A%0D%0Acamera.position.x+%3D+camera_x%3B%0D%0Acamera.position.y+%3D+camera_y%3B%0D%0Acamera.position.z+%3D+camera_z%3B%0D%0A%09%09%0D%0Acamera.lookAt%28+cam_target+%29%3B%0D%0A%0D%0A%0D%0AEvery+time+you+change+either+the+camera+position+or+the+target+position+%28or+both%21%29+you+need+to+call+camera.lookAt+or+you+won%27t+get+any+visible+result.%0D%0A%0D%0AThis+seems+to+be+a+recent+change+in+three.js.+Apparently+the+camera+was+automatically+updated+in+older+revisions.%0D%0A%0D%0AHow+do+I+get+the+contents+of+the+current+canvas%3F+All+I+get+is+an+empty%2C+transparent+image+in+Chrome%21%0D%0A%0D%0AThis+is+an+expected+behaviour+of+the+WebGL+implementation.+The+solution+is+to+create+the+WebGL+context+with+the+preserveDrawingBuffer+flag.+Of+course%2C+three.js+already+has+that+in+mind%21%0D%0A%0D%0ASo+you+simply+have+to+add+that+parameter+when+initialising+the+renderer%3A%0D%0A%0D%0A%0D%0Arenderer+%3D+new+THREE.WebGLRenderer%28%7B+preserveDrawingBuffer%3A+true+%7D%29%3B%0D%0A%0D%0A%0D%0AOnce+that%27s+done+you+can+happily+extract+screenshots+of+the+current+output+with+the+usual+canvas.toDataURL+%28although+I+used+canvas.toBlob+for+directly+downloading+the+image+to+the+browser%29.%0D%0A%0D%0AHow+do+I+modify+a+geometry+dynamically%3F+%28from+javascript%2C+not+in+a+vertex+shader%29%0D%0A%0D%0AThis+is+my+super+favourite+question%2C+so+I+left+it+for+the+end%21%0D%0A%0D%0AYou+can+change+the+vertices+position+in+a+geometry+once+it%27s+been+added+to+the+scene%2C+but+you+won%27t+notice+any+difference+until+you+let+three.js+know+that+you%27ve+changed+something+in+the+object%21%0D%0A%0D%0AThat%27s+done+with%3A%0D%0A%0D%0A%0D%0Amesh.geometry.__dirtyVertices+%3D+true%3B%0D%0A%0D%0A%0D%0Aevery+time+you%27ve+modified+the+geometry+and+need+to+get+it+updated+in+the+screen.%0D%0A%0D%0AMr.doob+told+me+it%27s+also+possible+to+modify+other+geometry+properties%2C+such+as+the+vertex+colors.+If+you+modify+the+vertex+colors%2C+you+then+need+to+set+the+__dirtyColors+property+to+true.%0D%0A%0D%0AActually%2C+this+is+not+the+%27proper%27+way+of+doing+things+with+WebGL.+Every+time+a+geometry+is+marked+as+%27dirty%27%2C+it+needs+to+be+re-sent+and+re-created+in+the+GPU%2C+so+to+speak.+Therefore%2C+this+flexibility+comes+at+a+cost%3B+the+larger+the+geometry%2C+the+slowest+it%27ll+be.+I+should+be+doing+these+calculations+in+a+vertex+shader%2C+running+in+the+GPU%2C+but+since+I%27m+still+learning+I%27m+allowing+myself+this+little+computational+luxury+%3B-%29&amp;amp;tags=sfaq%2Cthree.js%2Cwebgl%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Mesh subdivision (2012 extended edition)</title>
		<link>http://soledadpenades.com/2012/04/16/mesh-subdivision-2012-extended-edition/</link>
		<comments>http://soledadpenades.com/2012/04/16/mesh-subdivision-2012-extended-edition/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 21:54:15 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[demoscene]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[three.js]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=3947</guid>
		<description><![CDATA[Back in 2004, when I was starting to experiment with OpenGL, I had the idea of creating meshes from scratch. This will come in handy for intros, since this way I won&#8217;t be needing to include the meshes&#8217; data with the executable!, I thought. I would create a simple base pyramidal mesh, and subdivide it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lab.soledadpenades.com/js/mesh_subdivision/#eyJudW1iZXJfcGFzc2VzIjo4LCJiYWNrZ3JvdW5kX2NvbG9yIjoxMjMwMzI5MSwid2lyZWZyYW1lIjp0cnVlLCJ3aXJld2lkdGgiOjEsIndpcmVjb2xvciI6MCwiY29sb3JfMSI6MTY3MTE2ODAsImNvbG9yXzIiOjY1MjgwLCJjb2xvcl8zIjoyNTUsIndvYmJseSI6ZmFsc2UsIndvYmJseV9zcGVlZCI6MSwicm90YXRpb25fc3BlZWRfeCI6MSwicm90YXRpb25fc3BlZWRfeiI6MSwiY2FtZXJhX3giOjAsImNhbWVyYV95IjowLCJjYW1lcmFfeiI6MTAsImRyYXdfYXhpcyI6dHJ1ZX0="><img src="/imgs/2012/ms01.jpg" alt="mesh subdivision 2012" /></a></p>
<p>Back in 2004, when I was starting to experiment with OpenGL, I had the idea of creating meshes <em>from scratch</em>. <q>This will come in handy for intros, since this way I won&#8217;t be needing to include the meshes&#8217; data with the executable!</q>, I thought.</p>
<p>I would create a simple base pyramidal mesh, and subdivide it until I got something with more vertices and faces, but properly connected (not just a bunch of random points). So I when I had a couple of free days, I came up with <a href="http://soledadpenades.com/2004/04/19/improving-mesh-subdivision/">a very rough way</a> of creating and subdividing meshes. It was very raw, but I loved that I had done it myself!<br />
<span id="more-3947"></span><br />
<a href="http://soledadpenades.com/2004/04/19/improving-mesh-subdivision/"><img src="http://www.soledadpenades.com/imgs/mesh_sdv_3passes_fixed_lw.png" /></a></p>
<p>At the end, I didn&#8217;t use it for any intro at all, but I used the <em>trick</em> in a demo instead, called <a href="http://soledadpenades.com/projects/demoscene/codecolors-by-ppg/">codecolors</a> (<a href="https://github.com/sole/demoscene/tree/master/releases/ppg/ppg_05_cc/src">source code</a>, if you&#8217;re feeling adventurous). Although it&#8217;s hard to notice, since everything was generously blurred (I had recently learned how to get a cheap motion blur effect and was really eager to use it in every single frame!).</p>
<p>Fast forward to 2012. I am learning (tinkering with?) <a href="https://github.com/mrdoob/three.js">three.js</a> and I wanted to find out how to manipulate vertex data dynamically. I somehow remembered this experiment and where I left it (<q>Next step is playing with the vertices!</q>), and I decided to continue it.</p>
<p>Once I got the basics working, I thought it would be neat to have some way of interacting with the scene&#8211;so I added <a href="https://code.google.com/p/dat-gui/">dat.gui</a>, which are the controls on top right. Then I also wanted to save the images, as I once I added controls for altering the look I started getting great imagery! So I added <a href="https://github.com/eligrey/FileSaver.js">FileSaver.js</a> and <a href="https://github.com/eligrey/canvas-toBlob.js">canvas-toBlob.js</a>, since browser support for downloading images is still a bit incomplete (so to speak).</p>
<p>And finally I thought: <q>hey, storing images is ok, but what if I want to modify an existing configuration?</q>. So I added support for storing the current configuration via some simple location hash serialising. I am not sure if it&#8217;s the best way but it seems to work well enough for now!</p>
<p><a href="http://lab.soledadpenades.com/js/mesh_subdivision/#eyJudW1iZXJfcGFzc2VzIjo0LCJiYWNrZ3JvdW5kX2NvbG9yIjoxMjMwMzI5MSwid2lyZWZyYW1lIjpmYWxzZSwid2lyZXdpZHRoIjoxLCJ3aXJlY29sb3IiOjE2NzExNjgwLCJjb2xvcl8xIjoxNjcxMTY4MCwiY29sb3JfMiI6NjUyODAsImNvbG9yXzMiOjI1NSwid29iYmx5IjpmYWxzZSwid29iYmx5X3NwZWVkIjoxLCJyb3RhdGlvbl9zcGVlZF94IjoxLCJyb3RhdGlvbl9zcGVlZF96IjoxLCJjYW1lcmFfeCI6MCwiY2FtZXJhX3kiOjAsImNhbWVyYV96IjoxMCwiZHJhd19heGlzIjp0cnVlfQ=="><img src="/imgs/2012/ms02.jpg" alt="mesh subdivision 2012" /></a></p>
<p>Oh, and since I just <em>love</em> text effects, I added a silly text-manipulation thingie to dynamically alter the innerText of the page contents. Just because!</p>
<p>It&#8217;s fun to play with all the settings and seeing what happens. I have found myself mesmerised just by looking at the end result. Some images seem really organic; others look very fractal/spaceish to me. (Don&#8217;t forget to make it <a href="http://lab.soledadpenades.com/js/mesh_subdivision/#eyJudW1iZXJfcGFzc2VzIjo1LCJiYWNrZ3JvdW5kX2NvbG9yIjoxMjMwMzI5MSwid2lyZWZyYW1lIjp0cnVlLCJ3aXJld2lkdGgiOjEsIndpcmVjb2xvciI6MTY3MTE2ODAsImNvbG9yXzEiOjE2NzExNjgwLCJjb2xvcl8yIjo2NTI4MCwiY29sb3JfMyI6MjU1LCJ3b2JibHkiOnRydWUsIndvYmJseV9zcGVlZCI6OS43MDMyOTY3MDMyOTY3MDMsInJvdGF0aW9uX3NwZWVkX3giOjEsInJvdGF0aW9uX3NwZWVkX3oiOjEsImNhbWVyYV94IjoyMDAsImNhbWVyYV95IjoyMDAsImNhbWVyYV96IjoyMDAsImRyYXdfYXhpcyI6dHJ1ZX0=">wobbly</a>! &#8211;looks like someone is having a discussion inside the pyramid!).</p>
<p>I&#8217;m <em>very</em> happy with the end result, and even more about the development process. I can vividly recall the many hours I spent in 2004 dealing with arrays and memory allocation for such a simple task as this one. Quite unproductive, to be honest! But Javascript + WebGL totally ROCK! Also, after so many years of trying to explain what the demoscene and realtime is about, it&#8217;s great to be able to demonstrate it <em>in realtime</em>. Yay!</p>
<p>I&#8217;ll write about the new &#8220;Simple yet Frequently Asked Questions&#8221; about three.js that I encountered while doing this experiment&#8230; but that will be tomorrow, if you don&#8217;t mind!</p>
<p>Have fun! :)</p>
 <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=3947&amp;md5=71ce55931be4ec0f0a529035f5efa2d9" title="Flattr" target="_blank"><img src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2012/04/16/mesh-subdivision-2012-extended-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=8399&amp;amp;url=http%3A%2F%2Fsoledadpenades.com%2F2012%2F04%2F16%2Fmesh-subdivision-2012-extended-edition%2F&amp;amp;language=en_GB&amp;amp;category=text&amp;amp;title=Mesh+subdivision+%282012+extended+edition%29&amp;amp;description=%0D%0A%0D%0ABack+in+2004%2C+when+I+was+starting+to+experiment+with+OpenGL%2C+I+had+the+idea+of+creating+meshes+from+scratch.+This+will+come+in+handy+for+intros%2C+since+this+way+I+won%27t+be+needing+to+include+the+meshes%27+data+with+the+executable%21%2C+I+thought.%0D%0A%0D%0AI+would+create+a+simple+base+pyramidal+mesh%2C+and+subdivide+it+until+I+got+something+with+more+vertices+and+faces%2C+but+properly+connected+%28not+just+a+bunch+of+random+points%29.+So+I+when+I+had+a+couple+of+free+days%2C+I+came+up+with+a+very+rough+way+of+creating+and+subdividing+meshes.+It+was+very+raw%2C+but+I+loved+that+I+had+done+it+myself%21%0D%0A%0D%0A%0D%0A%0D%0AAt+the+end%2C+I+didn%27t+use+it+for+any+intro+at+all%2C+but+I+used+the+trick+in+a+demo+instead%2C+called+codecolors+%28source+code%2C+if+you%27re+feeling+adventurous%29.+Although+it%27s+hard+to+notice%2C+since+everything+was+generously+blurred+%28I+had+recently+learned+how+to+get+a+cheap+motion+blur+effect+and+was+really+eager+to+use+it+in+every+single+frame%21%29.%0D%0A%0D%0AFast+forward+to+2012.+I+am+learning+%28tinkering+with%3F%29+three.js+and+I+wanted+to+find+out+how+to+manipulate+vertex+data+dynamically.+I+somehow+remembered+this+experiment+and+where+I+left+it+%28Next+step+is+playing+with+the+vertices%21%29%2C+and+I+decided+to+continue+it.%0D%0A%0D%0AOnce+I+got+the+basics+working%2C+I+thought+it+would+be+neat+to+have+some+way+of+interacting+with+the+scene--so+I+added+dat.gui%2C+which+are+the+controls+on+top+right.+Then+I+also+wanted+to+save+the+images%2C+as+I+once+I+added+controls+for+altering+the+look+I+started+getting+great+imagery%21+So+I+added+FileSaver.js+and+canvas-toBlob.js%2C+since+browser+support+for+downloading+images+is+still+a+bit+incomplete+%28so+to+speak%29.%0D%0A%0D%0AAnd+finally+I+thought%3A+hey%2C+storing+images+is+ok%2C+but+what+if+I+want+to+modify+an+existing+configuration%3F.+So+I+added+support+for+storing+the+current+configuration+via+some+simple+location+hash+serialising.+I+am+not+sure+if+it%27s+the+best+way+but+it+seems+to+work+well+enough+for+now%21%0D%0A%0D%0A%0D%0A%0D%0AOh%2C+and+since+I+just+love+text+effects%2C+I+added+a+silly+text-manipulation+thingie+to+dynamically+alter+the+innerText+of+the+page+contents.+Just+because%21%0D%0A%0D%0AIt%27s+fun+to+play+with+all+the+settings+and+seeing+what+happens.+I+have+found+myself+mesmerised+just+by+looking+at+the+end+result.+Some+images+seem+really+organic%3B+others+look+very+fractal%2Fspaceish+to+me.+%28Don%27t+forget+to+make+it+wobbly%21+--looks+like+someone+is+having+a+discussion+inside+the+pyramid%21%29.%0D%0A%0D%0AI%27m+very+happy+with+the+end+result%2C+and+even+more+about+the+development+process.+I+can+vividly+recall+the+many+hours+I+spent+in+2004+dealing+with+arrays+and+memory+allocation+for+such+a+simple+task+as+this+one.+Quite+unproductive%2C+to+be+honest%21+But+Javascript+%2B+WebGL+totally+ROCK%21+Also%2C+after+so+many+years+of+trying+to+explain+what+the+demoscene+and+realtime+is+about%2C+it%27s+great+to+be+able+to+demonstrate+it+in+realtime.+Yay%21%0D%0A%0D%0AI%27ll+write+about+the+new+%22Simple+yet+Frequently+Asked+Questions%22+about+three.js+that+I+encountered+while+doing+this+experiment...+but+that+will+be+tomorrow%2C+if+you+don%27t+mind%21%0D%0A%0D%0AHave+fun%21+%3A%29&amp;amp;tags=demoscene%2Chtml5%2Cjavascript%2Copengl%2Cthree.js%2Cwebgl%2Cblog" type="text/html" />
	</item>
		<item>
		<title>WebGL VGA</title>
		<link>http://soledadpenades.com/2012/04/09/webgl-vga/</link>
		<comments>http://soledadpenades.com/2012/04/09/webgl-vga/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 00:17:53 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[retro]]></category>
		<category><![CDATA[three.js]]></category>
		<category><![CDATA[vga]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=3937</guid>
		<description><![CDATA[For some odd reason, I happened to remember a little demo that came with the first 16 bit computer I ever used&#8211;an Amstrad PC 2286. It was meant for showing off the capabilities of the new and shiny Paradise VGA graphics adapter that the 2000 line of computers incorporated. 256 simultaneous colours! 640&#215;350 graphics! So [...]]]></description>
			<content:encoded><![CDATA[<p>For some odd reason, I happened to remember a little demo that came with the first 16 bit computer I ever used&#8211;an Amstrad PC 2286. It was meant for showing off the capabilities of the new and shiny Paradise VGA graphics adapter that the 2000 line of computers incorporated. 256 simultaneous colours! 640&#215;350 graphics! So stunning back then! I ran this demo from time to time, admiring all those colours at the same time on the screen. Then I learnt how to make the computer output them with GW-Basic, but that is another story.</p>
<p>I wanted to watch that demo again, but it seems that the Amstrad PC line of computers doesn&#8217;t get as much love as the CPCs do. So there is hardly any software repository (or dump) for those computers, and thus I couldn&#8217;t locate that demo. It doesn&#8217;t help that I didn&#8217;t remember its filename either&#8230;</p>
<p>But I found several images depicting the demo, and somehow I decided that <em>rebuilding</em> the demo was an excellent idea &#8211;and a great excuse to learn <a href="https://github.com/mrdoob/three.js">three.js</a>!</p>
<p>This is how the original looked:</p>
<p><img src="/imgs/2012/amstrad_pc2086.jpg" alt="VGA demo" /></p>
<p>And <a href="http://lab.soledadpenades.com/js/webgl_vga/">this</a> is what I ended up with:</p>
<p><a href="http://lab.soledadpenades.com/js/webgl_vga/"><img src="/imgs/2012/amstrad_pc2086_revisited.png" alt="VGA demo + webgl 2012" /></a><br />
<span id="more-3937"></span><br />
In the process I thought I would spice things up a little. Since rotations are &#8220;cheap&#8221; with WebGL, I made things move around, mostly by rotating them. I also added some scaling here and there, and liberally used Math.sin and Math.cos (as Javascript is <em>so</em> fast nowadays too). Still, I didn&#8217;t go too far, for the sake of keeping some resemblance to the original!</p>
<h2>SFAQ</h2>
<p>Although three.js is designed to be simple and intuitive, I had several <q>how do I do this apparently simple thing with three.js?</q> moments, so I thought it would be interesting to write these down as a sort of &#8220;SFAQ&#8221; (Silly Frequently Asked Questions). There we go:</p>
<h3>How do I make a line?</h3>
<p>You first create a geometry, then add vertices to its <em>vertices</em> property. Then create a material to set the line color, and use both the geometry and the material to create a line.</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> geometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Geometry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> material <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">LineBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> color<span style="color: #339933;">:</span> 0xFF0000 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> line <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Line</span><span style="color: #009900;">&#40;</span>geometry<span style="color: #339933;">,</span> material<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<p>Actually, you can create the line skipping the material creation. It will get a randomly assigned colour then.</p>
<h3>How do I make a line strip? (i.e. a series of connected segments)</h3>
<p>You start with a geometry, like in the line example above, but add as many points as you require. Then when creating the line you specify that the line type is THREE.LineStrip:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> geometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Geometry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// ... add as many vertices as you need</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> material <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">LineBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> color<span style="color: #339933;">:</span> 0xFF0000 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> line <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Line</span><span style="color: #009900;">&#40;</span>geometry<span style="color: #339933;">,</span> material<span style="color: #339933;">,</span> THREE.<span style="color: #660066;">LineStrip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<h3>How do I make a line in which each segment has a different colour?</h3>
<p>The answer to this is <strong>vertex colours</strong>, which works in the same way as the homonym concept in OpenGL: you need to specify a colour per vertex, instead of just a colour for the entire line. The way to specify the colours is to add instances of THREE.Color with the desired colour to the <strong>colors</strong> property, and then tell the line material to use them, as follows:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> geometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Geometry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">colors</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Color</span><span style="color: #009900;">&#40;</span> 0xFF0000 <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">colors</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Color</span><span style="color: #009900;">&#40;</span> 0x00FF00 <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> material <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">LineBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> vertexColors<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> line <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Line</span><span style="color: #009900;">&#40;</span>geometry<span style="color: #339933;">,</span> material<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></code></div>
<p>I&#8217;m using this for the odd colourful figure on top left.</p>
<h3>How do I build hierarchies of objects?</h3>
<p>You can use the generic THREE.Object3D class as container for other objects. When you add children to that object, and move it, the children will move along with the parent:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> container <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Object3D</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> geometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">CubeGeometry</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> cube <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Mesh</span><span style="color: #009900;">&#40;</span>geometry<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
container.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>cube<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<br />
cube.<span style="color: #660066;">position</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Local x = 0</span><br />
container.<span style="color: #660066;">position</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// The cube's 'world' X coordinate at this point is 10</span></code></div>
<p>I used this for the &#8220;moire blocks&#8221; in the middle of the screen.</p>
<h3>How do I change the colour of an object after having instantiated it?</h3>
<p>Simply access its material.color property and change it as required:</p>
<div class="syhi_block"><code><span style="color: #003366; font-weight: bold;">var</span> geometry <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Geometry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
geometry.<span style="color: #660066;">vertices</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vertex</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Vector3</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> material <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">LineBasicMaterial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> color<span style="color: #339933;">:</span> 0xFF0000 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> line <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> THREE.<span style="color: #660066;">Line</span><span style="color: #009900;">&#40;</span>geometry<span style="color: #339933;">,</span> material<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// the line is red</span><br />
<br />
<span style="color: #006600; font-style: italic;">// But if we change its green attribute to 1...</span><br />
line.<span style="color: #660066;">material</span>.<span style="color: #660066;">color</span>.<span style="color: #660066;">g</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// ...the line is yellow now!</span></code></div>
<p>This technique is used for animating the colour of the rectangles on top right.</p>
<h2>A call for help!</h2>
<p>If you know the file name, or have a copy of the original demo, please let me know! I would love to watch it again after so many years! Hopefully it will work with DOSBox. Please! :-)</p>
 <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=3937&amp;md5=21d51722868ccc951ca3f6167f765e69" title="Flattr" target="_blank"><img src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2012/04/09/webgl-vga/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=8399&amp;amp;url=http%3A%2F%2Fsoledadpenades.com%2F2012%2F04%2F09%2Fwebgl-vga%2F&amp;amp;language=en_GB&amp;amp;category=text&amp;amp;title=WebGL+VGA&amp;amp;description=For+some+odd+reason%2C+I+happened+to+remember+a+little+demo+that+came+with+the+first+16+bit+computer+I+ever+used--an+Amstrad+PC+2286.+It+was+meant+for+showing+off+the+capabilities+of+the+new+and+shiny+Paradise+VGA+graphics+adapter+that+the+2000+line+of+computers+incorporated.+256+simultaneous+colours%21+640x350+graphics%21+So+stunning+back+then%21+I+ran+this+demo+from+time+to+time%2C+admiring+all+those+colours+at+the+same+time+on+the+screen.+Then+I+learnt+how+to+make+the+computer+output+them+with+GW-Basic%2C+but+that+is+another+story.%0D%0A%0D%0AI+wanted+to+watch+that+demo+again%2C+but+it+seems+that+the+Amstrad+PC+line+of+computers+doesn%27t+get+as+much+love+as+the+CPCs+do.+So+there+is+hardly+any+software+repository+%28or+dump%29+for+those+computers%2C+and+thus+I+couldn%27t+locate+that+demo.+It+doesn%27t+help+that+I+didn%27t+remember+its+filename+either...%0D%0A%0D%0ABut+I+found+several+images+depicting+the+demo%2C+and+somehow+I+decided+that+rebuilding+the+demo+was+an+excellent+idea+--and+a+great+excuse+to+learn+three.js%21%0D%0A%0D%0AThis+is+how+the+original+looked%3A%0D%0A%0D%0A%0D%0A%0D%0AAnd+this+is+what+I+ended+up+with%3A%0D%0A%0D%0A%0D%0A%0D%0AIn+the+process+I+thought+I+would+spice+things+up+a+little.+Since+rotations+are+%22cheap%22+with+WebGL%2C+I+made+things+move+around%2C+mostly+by+rotating+them.+I+also+added+some+scaling+here+and+there%2C+and+liberally+used+Math.sin+and+Math.cos+%28as+Javascript+is+so+fast+nowadays+too%29.+Still%2C+I+didn%27t+go+too+far%2C+for+the+sake+of+keeping+some+resemblance+to+the+original%21%0D%0A%0D%0ASFAQ%0D%0A%0D%0AAlthough+three.js+is+designed+to+be+simple+and+intuitive%2C+I+had+several+how+do+I+do+this+apparently+simple+thing+with+three.js%3F+moments%2C+so+I+thought+it+would+be+interesting+to+write+these+down+as+a+sort+of+%22SFAQ%22+%28Silly+Frequently+Asked+Questions%29.+There+we+go%3A%0D%0A%0D%0AHow+do+I+make+a+line%3F%0D%0A%0D%0AYou+first+create+a+geometry%2C+then+add+vertices+to+its+vertices+property.+Then+create+a+material+to+set+the+line+color%2C+and+use+both+the+geometry+and+the+material+to+create+a+line.%0D%0A%0D%0A%0D%0Avar+geometry+%3D+new+THREE.Geometry%28%29%3B%0D%0A%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%280%2C+0%2C+0%29+%29+%29%3B%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%28100%2C+0%2C+0%29+%29+%29%3B%0D%0A%0D%0Avar+material+%3D+new+THREE.LineBasicMaterial%28%7B+color%3A+0xFF0000+%7D%29%3B%0D%0Avar+line+%3D+new+THREE.Line%28geometry%2C+material%29%3B%0D%0A%0D%0A%0D%0AActually%2C+you+can+create+the+line+skipping+the+material+creation.+It+will+get+a+randomly+assigned+colour+then.%0D%0A%0D%0AHow+do+I+make+a+line+strip%3F+%28i.e.+a+series+of+connected+segments%29%0D%0A%0D%0AYou+start+with+a+geometry%2C+like+in+the+line+example+above%2C+but+add+as+many+points+as+you+require.+Then+when+creating+the+line+you+specify+that+the+line+type+is+THREE.LineStrip%3A%0D%0A%0D%0A%0D%0Avar+geometry+%3D+new+THREE.Geometry%28%29%3B%0D%0A%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%280%2C+0%2C+0%29+%29+%29%3B%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%28100%2C+0%2C+0%29+%29+%29%3B%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%28100%2C+100%2C+0%29+%29+%29%3B%0D%0A%2F%2F+...+add+as+many+vertices+as+you+need%0D%0A%0D%0Avar+material+%3D+new+THREE.LineBasicMaterial%28%7B+color%3A+0xFF0000+%7D%29%3B%0D%0Avar+line+%3D+new+THREE.Line%28geometry%2C+material%2C+THREE.LineStrip%29%3B%0D%0A%0D%0A%0D%0AHow+do+I+make+a+line+in+which+each+segment+has+a+different+colour%3F%0D%0A%0D%0AThe+answer+to+this+is+vertex+colours%2C+which+works+in+the+same+way+as+the+homonym+concept+in+OpenGL%3A+you+need+to+specify+a+colour+per+vertex%2C+instead+of+just+a+colour+for+the+entire+line.+The+way+to+specify+the+colours+is+to+add+instances+of+THREE.Color+with+the+desired+colour+to+the+colors+property%2C+and+then+tell+the+line+material+to+use+them%2C+as+follows%3A%0D%0A%0D%0A%0D%0Avar+geometry+%3D+new+THREE.Geometry%28%29%3B%0D%0A%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%280%2C+0%2C+0%29+%29+%29%3B%0D%0Ageometry.colors.push%28new+THREE.Color%28+0xFF0000+%29+%29%3B%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%28100%2C+0%2C+0%29+%29+%29%3B%0D%0Ageometry.colors.push%28new+THREE.Color%28+0x00FF00+%29+%29%3B%0D%0A%0D%0Avar+material+%3D+new+THREE.LineBasicMaterial%28%7B+vertexColors%3A+true+%7D%29%3B%0D%0Avar+line+%3D+new+THREE.Line%28geometry%2C+material%29%3B%0D%0A%0D%0A%0D%0AI%27m+using+this+for+the+odd+colourful+figure+on+top+left.%0D%0A%0D%0AHow+do+I+build+hierarchies+of+objects%3F%0D%0A%0D%0AYou+can+use+the+generic+THREE.Object3D+class+as+container+for+other+objects.+When+you+add+children+to+that+object%2C+and+move+it%2C+the+children+will+move+along+with+the+parent%3A%0D%0A%0D%0A%0D%0Avar+container+%3D+new+THREE.Object3D%28%29%3B%0D%0Avar+geometry+%3D+new+THREE.CubeGeometry%2810%2C+10%2C+10%29%3B%0D%0Avar+cube+%3D+new+THREE.Mesh%28geometry%29%3B%0D%0A%0D%0Acontainer.add%28cube%29%3B%0D%0A%0D%0A%0D%0Acube.position.x+%3D+0%3B+%2F%2F+Local+x+%3D+0%0D%0Acontainer.position.x+%3D+10%3B+%2F%2F+The+cube%27s+%27world%27+X+coordinate+at+this+point+is+10%0D%0A%0D%0A%0D%0AI+used+this+for+the+%22moire+blocks%22+in+the+middle+of+the+screen.%0D%0A%0D%0AHow+do+I+change+the+colour+of+an+object+after+having+instantiated+it%3F%0D%0A%0D%0ASimply+access+its+material.color+property+and+change+it+as+required%3A%0D%0A%0D%0A%0D%0Avar+geometry+%3D+new+THREE.Geometry%28%29%3B%0D%0A%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%280%2C+0%2C+0%29+%29+%29%3B%0D%0Ageometry.vertices.push%28new+THREE.Vertex%28+new+THREE.Vector3%28100%2C+0%2C+0%29+%29+%29%3B%0D%0A%0D%0Avar+material+%3D+new+THREE.LineBasicMaterial%28%7B+color%3A+0xFF0000+%7D%29%3B%0D%0Avar+line+%3D+new+THREE.Line%28geometry%2C+material%29%3B%0D%0A%0D%0A%2F%2F+the+line+is+red%0D%0A%0D%0A%2F%2F+But+if+we+change+its+green+attribute+to+1...%0D%0Aline.material.color.g+%3D+1%3B%0D%0A%0D%0A%2F%2F+...the+line+is+yellow+now%21%0D%0A%0D%0A%0D%0AThis+technique+is+used+for+animating+the+colour+of+the+rectangles+on+top+right.%0D%0A%0D%0AA+call+for+help%21%0D%0A%0D%0AIf+you+know+the+file+name%2C+or+have+a+copy+of+the+original+demo%2C+please+let+me+know%21+I+would+love+to+watch+it+again+after+so+many+years%21+Hopefully+it+will+work+with+DOSBox.+Please%21+%3A-%29&amp;amp;tags=javascript%2Cretro%2Cthree.js%2Cvga%2Cwebgl%2Cblog" type="text/html" />
	</item>
		<item>
		<title>animated_gif.js</title>
		<link>http://soledadpenades.com/2012/04/02/animated_gif-js/</link>
		<comments>http://soledadpenades.com/2012/04/02/animated_gif-js/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 07:18:13 +0000</pubDate>
		<dc:creator>sole</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silly stuff]]></category>
		<category><![CDATA[animated gif]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://soledadpenades.com/?p=3934</guid>
		<description><![CDATA[Past week I wanted to make an animated GIF &#8211; but didn&#8217;t want to use GIMP or ffmpeg for that. I wondered: can an animated GIF be made in the browser? Of course it can! There was a library (JSGIF) which was a port of the original ActionScript library, AS3GIF. I built a bit of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lab.soledadpenades.com/js/animated_gif/"><img src="/imgs/2012/animated_gif.png" alt="Animated GIF" /></a></p>
<p>Past week I wanted to make an animated GIF &#8211; but didn&#8217;t want to use GIMP or ffmpeg for that. I wondered: can an animated GIF be made in the browser? <strong>Of course it can!</strong> There was a library (<a href="https://github.com/antimatter15/jsgif">JSGIF</a>) which was a port of the original ActionScript library, <a href="http://code.google.com/p/as3gif/">AS3GIF</a>.</p>
<p>I built a bit of wrapping code around the library, and did some tests to see if the port worked, first by creating a canvas and painting random squares on it, and then using them as input frames and building the GIF with that. Secondly, I tried using images. It worked acceptably enough (the color quantizer could be better, but we&#8217;re not after photo-realistic animations, after all).</p>
<p>So I added the drag and drop + file api stuff, but there was still something missing&#8230; <strong>the look wasn&#8217;t 90s enough</strong>! It was all begging for a bit of outdated aesthetics, but done with CSS3 and HTML5. Hence, there are multicolour logos via CSS animations, eye-cancer phosphorescent pink that turns into X-Files green glow (via CSS animations too), an HTML5 &lt;footer&gt; element used just because, and even a modern, 21st century blink-kind effect thanks to more CSS animations. You can&#8217;t but love it. And those huge frames! They are done with an ingenious abuse of CSS borders, but that could be done with CSS five years ago already. Nothing new here, but all very funny in any case.</p>
<p>Note that even if I finished this yesterday &#8211;April&#8217;s Fools&#8211; it wasn&#8217;t originally intended to be an April&#8217;s Fools joke. Hopefully you can take it seriously, right?</p>
<p>Right!</p>
<p><small>PS I actually looked into making animated WebP&#8217;s but the library I found wasn&#8217;t fast enough so all the fun factor was lost :-(</p>
<p>Maybe in a couple of years, when WebP is retro already&#8230;</small></p>
 <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=3934&amp;md5=cfeffadb082760226e262c878a6b9457" title="Flattr" target="_blank"><img src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://soledadpenades.com/2012/04/02/animated_gif-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=8399&amp;amp;url=http%3A%2F%2Fsoledadpenades.com%2F2012%2F04%2F02%2Fanimated_gif-js%2F&amp;amp;language=en_GB&amp;amp;category=text&amp;amp;title=animated_gif.js&amp;amp;description=%0D%0A%0D%0APast+week+I+wanted+to+make+an+animated+GIF+-+but+didn%27t+want+to+use+GIMP+or+ffmpeg+for+that.+I+wondered%3A+can+an+animated+GIF+be+made+in+the+browser%3F+Of+course+it+can%21+There+was+a+library+%28JSGIF%29+which+was+a+port+of+the+original+ActionScript+library%2C+AS3GIF.%0D%0A%0D%0AI+built+a+bit+of+wrapping+code+around+the+library%2C+and+did+some+tests+to+see+if+the+port+worked%2C+first+by+creating+a+canvas+and+painting+random+squares+on+it%2C+and+then+using+them+as+input+frames+and+building+the+GIF+with+that.+Secondly%2C+I+tried+using+images.+It+worked+acceptably+enough+%28the+color+quantizer+could+be+better%2C+but+we%27re+not+after+photo-realistic+animations%2C+after+all%29.%0D%0A%0D%0ASo+I+added+the+drag+and+drop+%2B+file+api+stuff%2C+but+there+was+still+something+missing...+the+look+wasn%27t+90s+enough%21+It+was+all+begging+for+a+bit+of+outdated+aesthetics%2C+but+done+with+CSS3+and+HTML5.+Hence%2C+there+are+multicolour+logos+via+CSS+animations%2C+eye-cancer+phosphorescent+pink+that+turns+into+X-Files+green+glow+%28via+CSS+animations+too%29%2C+an+HTML5+%26lt%3Bfooter%26gt%3B+element+used+just+because%2C+and+even+a+modern%2C+21st+century+blink-kind+effect+thanks+to+more+CSS+animations.+You+can%27t+but+love+it.+And+those+huge+frames%21+They+are+done+with+an+ingenious+abuse+of+CSS+borders%2C+but+that+could+be+done+with+CSS+five+years+ago+already.+Nothing+new+here%2C+but+all+very+funny+in+any+case.%0D%0A%0D%0ANote+that+even+if+I+finished+this+yesterday+--April%27s+Fools--+it+wasn%27t+originally+intended+to+be+an+April%27s+Fools+joke.+Hopefully+you+can+take+it+seriously%2C+right%3F%0D%0A%0D%0ARight%21%0D%0A%0D%0APS+I+actually+looked+into+making+animated+WebP%27s+but+the+library+I+found+wasn%27t+fast+enough+so+all+the+fun+factor+was+lost+%3A-%28%0D%0A%0D%0AMaybe+in+a+couple+of+years%2C+when+WebP+is+retro+already...&amp;amp;tags=animated+gif%2Ccanvas%2Ccss3%2Chtml5%2Cjavascript%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>

