Inkscape tips I wish I’d known years ago

"Twilo" workspace detail
“Twilo” workspace detail

As stated previously, I love Inkscape. I’ve used it professionally for 8 years or so now, and know my ways around it quite well. So I thought I’d share everything useful I can think of. I’ll try to keep it succinct, or at least single-paged. Onward.

Keyboard shortcuts

-are one of Inkscape’s best features.

  • For tools in the Toolbox you can usually hit the initial letter of the tool you need, like B for bezier, R for rectangle, E for ellipse, T for text. But the keys you’ll use most often are F1 for object select, F2 for object detail select, and CTRL (plus scroll up/down) to zoom in and out.
  • CTRL+SHIFT+another key bring up side menus; +F for fill menu, +T for text, +M for modify & transform, +E for export bitmap, +O for object properties, +D for document properties, +L for layers, +A for align & distribute.
  • PageUp/PageDown raise and lower the depth of an object. Home brings it to the front, End to the back.
  • SHIFT+click selects multiple objects. Click a selected object again to deselect.
  • SHIFT+click on a colour to set stroke colour.
  • ! negates the selection (select everything that isn’t, and vice versa).
  • Number keys 1-6 handle zoom types; 1 for actual size, 2 for double size, 3 to centre on selected objects, 4 to centre the whole drawing, 5 to centre the page and 6 to match the page width.
  • CTRL and + or – will unite or divide two overlaying selected objects. When dividing the topmost object’s shape is cut from the object underneath.
  • CTRL+G and CTRL+SHIFT+G groups and ungroups selected objects. Grouping puts all grouped objects on to the same depth.
  • # brings up the grid. There are two types, but new documents always begin on square. Change grid type from Document properties (CTRL+SHIFT+D), in the Grids tab. Snapping must also be on for grid snapping to work (far right-top icon).
  • | brings up guides. You won’t see anything unless you have guides on the page (drag from edge rulers into workspace to create a guide)..

User interface

  • In object mode (F1), drag from an open area to create a selection rectangle. Hold SHIFT to not select any object you happen to start dragging on. ALT+drag draws a line which selects any objects it touches.
  • Click an object once to select it. Note scale handles around edges. Click it again. Note how the handles change to rotate and shear mode.
  • Double click an object to enter detail mode. In this mode you can change roundedness of corners of rectangles, arc range of ellipses, position and scale of patterns and gradient fills, edit vertices of polygons etc. You can also change an object or selection’s centre of rotation and scaling. Look for the cross.
  • SHIFT and CTRL, on their own and at the same time, modify scaling and rotation by mouse.
  • The toolstrip directly above the workspace is context sensitive, so it’ll show actions relative to what’s currently selected.
  • Drag from either the horizontal or the vertical rulers into the workspace to create a guide.
  • Icons down the right are snap settings. Learn when to use the right type and you’ll live a bit longer.
  • “Affect” icons at top of screen change what parts of an object get scaled, from stroke thickness to pattern.
  • The Find menu is useful. CTRL+F then search by partial match of a fill or stroke style, object type, ID, content text or attribute. Another life extender.
  • Use the Align & distribute menu to centre your work on the page.

Process

  • If you draw a square, say 10x10px large, then add a stroke with a thickness of 2px, your square will now be 12x12px. If you now grid snap that square to another position with the “Snap to bounding box” option on, it’ll snap to the outside edge of the stroke, not to the edge of the square. Don’t spend 18 hours on a meticulous grid-snapped masterpiece only to then zoom in and realise that I am an idiot who will die alone.
  • If you lose focus of an object once it’s gone behind another, use detail mode (F2) and select it’s path.
  • To frame work perfectly before exporting a bitmap, draw a rectangle over it with half opacity, then adjust the rectangle to your liking. When done, make the rectangle fully transparent, then bring up the Export bitmap menu with CTRL+SHIFT+E, and save with “Selection” button on and “Hide all except selected” off. You can add a stroke to your rectangle to effect a frame around the bitmap.
  • Alternatively you can bring up Document properties with CTRL+SHIFT+D, choose “Resize page to content” then “Resize page to drawing or selection” while your rectangle is selected, before deleting it and using Export bitmap with “Page” button on.
  • If you’ve drawn/built something that overlaps the edges of the page, use “Guides Around Page” from the Edit menu.
  • You absolutely don’t have to use the page. I tend to scroll all the way to the right when I begin and build on copy after copy. Some logos drafts have a roughly A1 sized work area by the time I’m done, filled with hundreds of revisions.

 

More to come, as I think of them.

React

Learning Javascript: Part 2 – Variables, arrays and objects

After the first part of this series of tutorials, you should have an HTML file that looks like this:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="output">
</div>
<script type="text/javascript">
var output=document.getElementById("output");
output.innerHTML="Hello world";
output.innerHTML+=", goodbye sanity";
</script>
</body>
</html>

We’ll leave the output variable as it is, and use it to display results.

There are tons of comparisons that people use to describe variables. I myself was happy with saying they’re like a wall of post boxes in the foyer of a building, but that gives the impression that the variables themselves contain something, which they don’t; they actually just contain a pointer to the area of memory that holds something.

The difference is important. If we changed the above code to this

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="output">
</div>
<script type="text/javascript">
var output=document.getElementById("output");
var anotherOutput=document.getElementById("output");
output.innerHTML="Hello world";
anotherOutput.innerHTML+=", goodbye sanity";
</script>
</body>
</html>

The results would be exactly the same, because the variables “output” and “anotherOutput” both point to the same area of memory; the one that contains the HTML element with an ID of “output”.

You’ll find the concept of pointers-to-things throughout computerland. The world wide web uses URLs like chrisgodley.com as pointers to save human beings from having to remember IP addresses.

In our examples so far, our variable “output” points to an HTML element. To Javascript that’s just another type of Object. Let’s look at what other types of data a variable can hold.

In the code below you’ll meet code comments “//” for the first time too. Somewhat unsurprisingly, they let you add comments to code. Here we’re using them to label the different datatypes:

var a="some text"; // a String

var b=1; // an Integer (a number with no decimal places)

var c=1.2; // a Float (a number with decimal places)

var d=[1, 2, 4, 8, 16, 32]; // an Array (a list of things)

var e={name:"John", surname:"Doe"}; // an Object (a collection of named things)

var f=function(input1, input2){
   alert(input1+" "+input2);
}; // a Function (a program inside a program)

And that’s about it. But with these 6 types of data and enough coffee, Javascript can interpret and manipulate just about any type of real world data, from news articles on a web page to raw video streams, three dimensional vertices and raster graphics to audio frequencies.

One lesson learned when it comes to new programming projects is this; “Start with the data.”

That is, find out or figure out exactly how the raw data of the project looks first, then write code to do what you want with that data.

Let’s say you want to write a shopping system for your site. Before you start doing mockups of how it should look, sit down and plan the data for a typical item that you’re selling. You’ll probably end up with each item being represented by an Object that looks roughly like this:

var anItem={
   name: "Mango smoothie",
   price: 2.20,
   currency: "GBP",
   amount: 1.5,
   amountType: "litres",
   stock: 2417
};

That’s flat data. It’s only one level deep. Let’s take advantage of multiple level Objects by including the name and email of our mango smoothie supplier:

var anItem={
   name: "Mango smoothie",
   price: 2.20,
   currency: "GBP",
   amount: 1.5,
   amountType: "litres",
   stock: 2417,
   supplier:{
      name: "The Mango Smoothie Company",
      email: "john@themangosmoothiecompany.co.uk"
   }
};

Our data is now hierarchical. But it’s still only one item. What if we wanted to store a number of different items in a list?

The datatype equivalent of a list is an Array. We refer to items in an Array by specifying their position in it. myArray[1] would refer to the SECOND item in an Array; myArray[0] refers to the first. That’s just how computers count. You get used to it.

So, let’s see our items in an Array:

var listOfItems=[
   {
      name: "Mango smoothie",
      price: 2.20,
      currency: "GBP",
      amount: 1.5,
      amountType: "litres",
      stock: 2417,
      supplier:{
         name: "The Mango Smoothie Company",
         email: "john@themangosmoothiecompany.co.uk"
      }
   },
   {
      name: "Peach smoothie",
      price: 2.20,
      currency: "GBP",
      amount: 1.5,
      amountType: "litres",
      stock: 876,
      supplier:{
         name: "The Peach Smoothie Company",
         email: "rachael@thepeachsmoothiecompany.co.uk"
      }
   },
   {
      name: "Raspberry smoothie",
      price: 2.20,
      currency: "GBP",
      amount: 1.5,
      amountType: "litres",
      stock: 476,
      supplier:{
         name: "The Raspberry Smoothie Company",
         email: "frank@theraspberrysmoothiecompany.co.uk"
      }
   },
   {
      name: "Grape smoothie",
      price: 2.20,
      currency: "GBP",
      amount: 1.5,
      amountType: "litres",
      stock: 2983,
      supplier:{
         name: "The Grape Smoothie Company",
         email: "lisa@thegrapesmoothiecompany.co.uk"
      }
   }
];

A few things to note here; What would we be looking at if we asked Javascript to show us listOfItems[2]?

Raspberry smoothies, well done. What if we asked for listOfItems[2].name?

Okay, what about listOfItems[2].supplier.name?

You’re getting it.

So, items in Arrays and items in Objects can hold all the different types of Data that a standard Variable can; Including yet more Arrays and Objects. Through this mechanism we have multiple-level (hierarchical) data structures, and are able to make JS data represent almost any kind of real-world data.

Dot.notation

As you’ve probably gathered, using full-stops to denote steps through a hierarchy is incredibly useful. Javascript uses it everywhere, not only to address data but also functions.

Occasionally, you’ll need to address a name that has a space in it. Use of spaces IS okay within objects, but to create those items you’ll need quotes, and to address those items you’ll need square brackets and quotes:

var a=[
   {
      "a number":1677689,
      "and another number":879
   }
];
var b=a[0]["and another number"];
var output=document.getElementById("output");
output.innerHTML=b;

So to clarify the above code, variable a is an Array containing a single Object which has two Properties, “a number”, and “and another number”. Variable b contains the number 879, because we pointed it at the first item (0, remember) then a Property name. The final two lines print b into the HTML element with an ID of “output”.

You should recognise those last lines from part 1. Knowing what you do now about dot notation, you might notice a few interesting things about them:

  • “document” is just an object.
  • “getElementById” is a Property of that object; a function to retrieve HTML elements from the document, which are themselves Objects.
  • “innerHTML” is a Property of an HTML element Object, which contains the actual text to go on screen.

That’s it for part 2 of this JS tutorial. Have a play with the code we have, and stay tuned for part 3.

Click here for part 1

React

Doped Rochelle salt crystals under the microscope

Following a previous post about the awesome piezoelectric properties of Rochelle salt crystals, I wanted to make some doped crystals in an open container that would expose the surface to air, so it made sense to just grow some big doped crystals on wire and see what they look like.

Photo of Rochelle salt and copper sulphate crystals
Robobud

Under a microscope it’s easy to see why the doped crystal reacts to wind, with thousands of smaller crystals increasing the surface area, acting like whiskers to carry vibrations down into the mother crystal:

React