<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>programming on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/programming/</link>
    <description>Recent content in programming on S Anand</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 04 Mar 2021 02:56:15 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/programming/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title></title>
      <link>https://www.s-anand.net/blog/programming-minecraft-with-websockets-linkedin/</link>
      <pubDate>Thu, 04 Mar 2021 02:56:15 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/programming-minecraft-with-websockets-linkedin/</guid>
      <description>&lt;p&gt;Unofficial Guide to Programming Minecraft with Websockets.&lt;/p&gt;
&lt;p&gt;My daughter got me hooked on Minecraft. (If you see me staring intently at you during a Zoom call, I&amp;rsquo;m probably fighting a mob.)&lt;/p&gt;
&lt;p&gt;As it turns out, Minecraft is pretty programmable. You can send it messages using websockets that can place blocks, create mobs, get information, and more.&lt;/p&gt;
&lt;p&gt;None of this is officially documented, though. So I spent a few weeks reverse-engineering this and put together a guide to programming Minecraft.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://youtu.be/bjanNXXwQbo&#34;&gt;https://youtu.be/bjanNXXwQbo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the full article with source code and examples:
&lt;a href=&#34;http://www.s-anand.net/blog/programming-minecraft-with-websockets/&#34;&gt;http://www.s-anand.net/blog/programming-minecraft-with-websockets/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;May you live in exciting worlds!&lt;/p&gt;
&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;https://i.ytimg.com/vi/bjanNXXwQbo/mqdefault.jpg&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.linkedin.com/feed/update/urn%3Ali%3Ashare%3A6773073563034509312&#34;&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Colour spaces</title>
      <link>https://www.s-anand.net/blog/colour-spaces/</link>
      <pubDate>Mon, 27 Aug 2012 14:04:23 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/colour-spaces/</guid>
      <description>&lt;p&gt;In reality, a colour is a combination of light waves with frequencies between 400-700THz, just like sound is a combination of sound waves with frequencies from 20-20000Hz. Just like mixing various pure notes produces a new sound, mixing various pure colours (like from a rainbow) produces new colours (like white, which isn’t on the rainbow.)&lt;/p&gt;
&lt;p&gt;Our eyes aren’t like our ears, though. They have 3 sensors that are triggered differently by different frequencies. The sensors roughly peak around red, green and blue. Roughly.&lt;/p&gt;
&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;http://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Cones_SMJ2_E.svg/300px-Cones_SMJ2_E.svg.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;It turns out that it’s possible to recreate &lt;strong&gt;most&lt;/strong&gt; (not all) colours using a combination of just red, green and blue by mimicking these three sensors to the right level. That’s why TVs and monitors have red, blue and green cells, and we represent colours using &lt;a href=&#34;http://en.wikipedia.org/wiki/Web_colors#Hex_triplet&#34;&gt;hex triplets&lt;/a&gt; for RRGGBB – like #00ff00 (green).&lt;/p&gt;
&lt;p&gt;There are a number of problems with this from a computational perspective. Conceptually, we think of (R, G, B) as a 3-dimensional cube. That’d mean that 100% red is about as bright as 100% green or blue. Unfortunately, green is a lot brighter than red, which is a lot brighter than blue. Our 3 sensors are not equally sensitive.&lt;/p&gt;
&lt;p&gt;You’d also think that a colour that’s numerically mid-way between 2 colours should &lt;strong&gt;appear&lt;/strong&gt; to be mid-way. Far from it.&lt;/p&gt;
&lt;p&gt;This means that if you’re picking colours using the RGB model, you’re using something very far from the intuitive human way of perceiving colours.&lt;/p&gt;
&lt;p&gt;Which is all very nice, but I’m usually in a rush. So what do I do?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I go to the Microsoft Office &lt;a href=&#34;http://office.microsoft.com/en-us/infopath-help/apply-a-color-scheme-HP001230316.aspx?CTT=1&#34;&gt;colour themes&lt;/a&gt; and use a colour picker to pick one. (I &lt;a href=&#34;https://github.com/sanand0/less/blob/master/color_themes.less&#34;&gt;extracted them&lt;/a&gt; to make life easier.) These are generally good on the eye.&lt;/li&gt;
&lt;li&gt;Failing that, I pick something from &lt;a href=&#34;http://kuler.adobe.com/&#34;&gt;http://kuler.adobe.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Or I go to &lt;a href=&#34;http://colorbrewer2.org/&#34;&gt;http://colorbrewer2.org/&lt;/a&gt; and pick a set of colours&lt;/li&gt;
&lt;li&gt;If I absolutely have to do things programmatically, I use the &lt;a href=&#34;http://tristen.ca/hcl-picker/&#34;&gt;HCL&lt;/a&gt; &lt;a href=&#34;http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/&#34;&gt;colour scheme&lt;/a&gt;. The good part is it’s perceptually uniform. The bad part is: not every interpolation is a valid colour.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://isomorphismes.tumblr.com&#34;&gt;isomorphismes&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;13 Mar 2013 5:20 pm&lt;/em&gt;:
What colours can&amp;rsquo;t be created by convex combinations of {R, G, B}? I mean within the visible spectrum.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>R scatterplots</title>
      <link>https://www.s-anand.net/blog/r-scatterplots/</link>
      <pubDate>Sun, 19 Sep 2010 21:38:02 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/r-scatterplots/</guid>
      <description>&lt;p&gt;I was browsing through &lt;a href=&#34;http://books.google.co.uk/books?id=zxNglqU1FKgC&#34;&gt;Beautiful Data&lt;/a&gt;, and stumbled upon this gem of a visualisation.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/rscatterplots.webp&#34;&gt;&lt;img alt=&#34;r-scatterplots&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/rscatterplots.webp&#34; title=&#34;r-scatterplots&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is the default plot R provides when supplied with a table of data. A beautiful use of small multiples. Each box is a scatterplot of a pair of variables. The diagonal is used to label the rows. It shows for every pair of variables their correlation and spread – at a glance.&lt;/p&gt;
&lt;p&gt;Whenever I get any new piece of data, this is going to be the very first thing I do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;plot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    <item>
      <title>Great essays</title>
      <link>https://www.s-anand.net/blog/great-essays/</link>
      <pubDate>Wed, 30 Aug 2006 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/great-essays/</guid>
      <description>&lt;p&gt;Great essays by&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://www.jnd.org/dn.pubs.html&#34;&gt;Dan Norman&lt;/a&gt; on design&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.paulgraham.com/articles.html&#34;&gt;Paul Graham&lt;/a&gt; on life and programming&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.edwardtufte.com/bboard/q-and-a?topic_id=1&#34;&gt;Edward Tufte&lt;/a&gt; on visualisation&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    <item>
      <title>What programmers do</title>
      <link>https://www.s-anand.net/blog/what-programmers-do/</link>
      <pubDate>Tue, 04 Apr 2006 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/what-programmers-do/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://lazutkin.com/blog/2006/apr/2/what-programmers-do/&#34;&gt;What programmers do&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Microsoft interview question</title>
      <link>https://www.s-anand.net/blog/microsoft-interview-question/</link>
      <pubDate>Mon, 15 Jan 2001 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/microsoft-interview-question/</guid>
      <description>&lt;p&gt;&amp;ldquo;Write a one-line C expression to determine if a number is a power of 2&amp;rdquo;. Microsoft is famous for &lt;a href=&#34;http://www-scf.usc.edu/~bondalap/ais/msqs.html&#34;&gt;asking such questions&lt;/a&gt; to their programmers. Or you might want to find out what the assembly code&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CWD
XOR AX, DX
SUB AX, DX
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;does. &lt;a href=&#34;http://www.ece.utexas.edu/~satti/brainteasers.html&#34;&gt;Satish&amp;rsquo;s site&lt;/a&gt; has the answer, but not the question. More questions: &lt;a href=&#34;http://www.acetheinterview.com/qanda/algorithms.html&#34;&gt;1&lt;/a&gt; &lt;a href=&#34;http://www.eecs.uic.edu/~skishenc/technical/technical4.htm&#34;&gt;2&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
