## Unix Terminal Coding

All Tags Eugene Tryfonides is the creator of this place .

Tiny Helicopters Can’t Out-Hover Hummingbirds

The spinning blades of micro-helicopters are about as efficient at hovering as the average hummingbird, which have had more than 42 million years of natural selection to hone their energetically efficient flight.

That said, hummingbird wings can still generate lift more efficiently than the best micro-helicopter blades, according to a new analysis led by David Lentink, an assistant professor of mechanical engineering at Stanford University. The findings could lead to more powerful, bird-inspired robotic vehicles.”

— 6 hours ago with 57 notes

Given the starting positions, velocities, and masses of three objects interacting via gravity, the classical three-body problem involves determining the motions of the three particles throughout time.

What’s cool about the three-body system is that it’s impossible to solve for the motions of the objects exactly. That is, we can’t write down an equation that describes the system. Instead of finding an exact solution, we solve the system numerically, which amounts to finding an accurate approximation.

The three-body problem is an example of a chaotic system, meaning that even a slight change in the starting conditions drastically changes the time-evolution of the system.

The GIF above shows a planar (i.e., two-dimensional) three-body system.

Mathematica code:

```G = 1; time = 30;
mA = 1; xA0 = 0; yA0 = 0; vxA0 = 0; vyA0 = 0;
mB = 1; xB0 = 1; yB0 = 0; vxB0 = 0; vyB0 = 0;
mC = 1; xC0 = 0; yC0 = 0.8; vxC0 = 0; vyC0 = 0;
soln1 = NDSolve[
{mA*Derivative[2][xA][t] ==
-((G*mA*mB*(xA[t] - xB[t]))/((xA[t] - xB[t])^2 +
(yA[t] - yB[t])^2)^(3/2)) -
(G*mA*mC*(xA[t] - xC[t]))/((xA[t] - xC[t])^2 +
(yA[t] - yC[t])^2)^(3/2),
mA*Derivative[2][yA][t] ==
-((G*mA*mB*(yA[t] - yB[t]))/((xA[t] - xB[t])^2 +
(yA[t] - yB[t])^2)^(3/2)) -
(G*mA*mC*(yA[t] - yC[t]))/((xA[t] - xC[t])^2 +
(yA[t] - yC[t])^2)^(3/2),
mB*Derivative[2][xB][t] ==
-((G*mB*mC*(xB[t] - xC[t]))/((xB[t] - xC[t])^2 +
(yB[t] - yC[t])^2)^(3/2)) -
(G*mB*mA*(xB[t] - xA[t]))/((xB[t] - xA[t])^2 +
(yB[t] - yA[t])^2)^(3/2),
mB*Derivative[2][yB][t] ==
-((G*mB*mC*(yB[t] - yC[t]))/((xB[t] - xC[t])^2 +
(yB[t] - yC[t])^2)^(3/2)) -
(G*mB*mA*(yB[t] - yA[t]))/((xB[t] - xA[t])^2 +
(yB[t] - yA[t])^2)^(3/2),
mC*Derivative[2][xC][t] ==
-((G*mC*mA*(xC[t] - xA[t]))/((xC[t] - xA[t])^2 +
(yC[t] - yA[t])^2)^(3/2)) -
(G*mC*mB*(xC[t] - xB[t]))/((xC[t] - xB[t])^2 +
(yC[t] - yB[t])^2)^(3/2),
mC*Derivative[2][yC][t] ==
-((G*mC*mA*(yC[t] - yA[t]))/((xC[t] - xA[t])^2 +
(yC[t] - yA[t])^2)^(3/2)) -
(G*mC*mB*(yC[t] - yB[t]))/((xC[t] - xB[t])^2 +
(yC[t] - yB[t])^2)^(3/2),
xA[0] == xA0, yA[0] == yA0,
Derivative[1][xA][0] == vxA0, Derivative[1][yA][0] == vyA0,
xB[0] == xB0, yB[0] == yB0,
Derivative[1][xB][0] == vxB0, Derivative[1][yB][0] == vyB0,
xC[0] == xC0, yC[0] == yC0,
Derivative[1][xC][0] == vxC0, Derivative[1][yC][0] == vyC0
},
{xA, yA, xB, yB, xC, yC},{t, 0, time}, MaxSteps -> 100000]
x1[t_] := Evaluate[xA[t] /. soln1[[1,1]]]
y1[t_] := Evaluate[yA[t] /. soln1[[1,2]]]
x2[t_] := Evaluate[xB[t] /. soln1[[1,3]]]
y2[t_] := Evaluate[yB[t] /. soln1[[1,4]]]
x3[t_] := Evaluate[xC[t] /. soln1[[1,5]]]
y3[t_] := Evaluate[yC[t] /. soln1[[1,6]]]
Manipulate[Show[
{ParametricPlot[
{{x1[t], y1[t]}, {x2[t], y2[t]}, {x3[t], y3[t]}},
{t, tmax - 0.5, tmax},
Axes -> False, PlotRange -> {{-0.55, 1.45},
{-0.55, 1.08}}, PlotStyle -> {Red, Green, Blue},
GridLines -> {Table[0.25*x + 0.07, {x, -100, 100}],
Table[0.25*y + 0.01, {y, -100, 100}]},
GridLinesStyle -> Directive[LightGray]]},
{Graphics[{Opacity[0.7], EdgeForm[Directive[Black]], Red,
Disk[{x1[tmax], y1[tmax]}, 0.03], Green,
Disk[{x2[tmax], y2[tmax]}, 0.03], Blue,
Disk[{x3[tmax], y3[tmax]}, 0.03]}]}, ImageSize -> 600],
{tmax, 6.05, 16.05}]```

(via derwents)

— 1 week ago with 132 notes

#mathematics  #code  #pure

# MIT Finger Device Reads to the Blind in Real Time

Scientists at the Massachusetts Institute of Technology are developing an audio reading device to be worn on the index finger of people whose vision is impaired, giving them affordable and immediate access to printed words.

The so-called FingerReader, a prototype produced by a 3-D printer, fits like a ring on the user’s finger, equipped with a small camera that scans text. A synthesized voice reads words aloud, quickly translating books, restaurant menus and other needed materials for daily living, especially away from home or office.”

— 3 weeks ago with 3955 notes

goodbye

i thought this was a fuckin skate 3 glitch gif at first

nyoom

(Source: relentless-soul)

— 3 weeks ago with 137218 notes

(via Typeface on Behance)

The typeface was created with Processing and Geomerative library.

(via fyprocessing)

— 1 month ago with 141 notes

#processing
@myen International Lisp Conference 2014 →
— 1 month ago

#aug  #lisp  #2014  #emacs

Triangles in flux II

(slight variation of the previous one; code here)

(via fyprocessing)

— 1 month ago with 314 notes

#processing
@myen #ln Sculpting Sound with SuperCollider » Linux Magazine →
— 1 month ago

#sc  #supercollider

Sometimes, I see an image, and it inspires me. Two nights ago was one of those times. This was one of those images. I have no idea who the original creator of that image was, but I’d like to thank that person for making it. Anyway, it gave me some ideas. So I coded this quick little sketch in processing to produce a pair of masks for me - one mask would be the original Alpha, and for the other, I would use the Luma.

How and why does one make use of two masks from one image? Well, I used them in the compositing breakdown below, and for the output below as well:

More in this set to come.

This image is one in a set named “Yin Yang Masking

(via fyprocessing)

— 1 month ago with 50 notes

How to Produce 640×480 Color VGA Video From an 8-Bit Arduino! - Don't Quit Your Day Job... →

# How to Produce 640×480 Color VGA Video From an 8-Bit Arduino!

Let me set this up for you: most 8-bit AVRs in the wild (I happened to use an Arduino Nano for this project) are running at 16 MHz.  That’s 16,000,000 calculations per second… a very respectable number for most embedded applications.

The VGA industry standard, which is pretty much the default case “we-can-always-fallback-to-this” video standard (640 pixels wide by 480 pixels tall by 60 frames per second), requires pixels to be clocked out at 25.175 MHz:

25,175,000 > 16,000,000.

And that was just one of the barriers to pulling off this silly project.  And, yes, with the hack I told you about last time (Please see my notes below), more is possible without overclocking the Arduino – roughly 800 or so pixels wide in 4 bit color should be doable with a 16MHz part, and, probably 1024 pixels in 4 bit color are in reach for 20 MHz clocked parts.  (If you’re willing to drop to 2 or 1 bit color and spend a ton on ICs that can handle even faster clocks, you can hit HD resolutions – but I think you’ll run into financial constraints before you max out on the technical side)

Let’s begin.

Or, if you want to skip the details:

## What Was the Goal?

I’m not sure what the current resolution record on a stock clocked Arduino is, but with tight coding you can achieve around 512 pixels wide on a 20 Mhz or ~400 pixels wide on a 16 MHz part.  That math is simple: (20/25.175 * 640) or (16/25.175) * 640, if you can clock out your pixels at one pixel per clock.

My goal was to produce ‘full screen’ video from an Arduino using one of the early-gen display technologies (in America – so NTSC or VGA, sorry SCART and PAL).  Color too.

Even though people have hacked color NTSC video out of Arduinos, they generally have only done so by changing the clock to (usually) 14.31818 MHz crystals.  Television compatibility is great, but laziness won out and I targeted VGA and its simple, discrete outputs for red, green, and blue… and keeping my stock 16 MHz clock.

As a challenge to myself, I wanted to keep the clock under the maximum figures quoted by AVR (20 MHz at 5.5 volts).  Overclocking is fine for the consumer on a cheap part, but it wouldn’t be worth it to assume all risks in a commercial product by exceeding manufacturer specifications… if that’s your final destination.

So, my requirements were set:

• Full width video, (>= 640 pixels wide) from an Arduino
• Color
• Use only parts I have on hand
• No reprogrammable logic (FPGA/CPLD/GAL/PAL/PLA/Whatever else is out there)

## What Was Your Parts List?  Can I Have a Schematic?

Of course!

I did it with 6 ICs, 10 resistors, one VGA port and a bunch of jumper wire.  Substitutions are fine, just keep the propagation delay of the parts under 32 ns so you can latch in time (if you do my clock hack, probably 20ns due to the weird duty cycle) or so.  The first four are for the clock circuit I discussed last week.

• HD74LS04P – Not Gate.  Used as Delay
• HD74LS08P – And Gate.  XOR half
• HD74LS32P – Or Gate.  XOR other half
• SN74F10N [≈ One kilogram-force, nominal weight of a 1 kg object at sea level on Earth] – Fast 3 Input Nand Gates.  Clean up the ugly clock from the hacked XOR, also used as Inverter
• DM74LS244N – 3 State Buffer/Line Driver/Line Receiver.  Control which pixel of the two is on the output bus.
• SN74LS373N – 8 D Type Latches. Our digital sampler/output to resistors and sync.
• VGA Port – See Nick Gammon’s site for how to wire this.
• Resistors ~68 Ohm.  Sync signals.
• Resistors ~470 Ohm. R/G/B signals.
###### A Note/Disclaimer:  I make no warranty that this is Moderately correct, and that I even transposed it correctly from my working copy.  I may have transposed this incorrectly, so don’t even trust the picture 100%.  I won’t be held responsible if you break any equipment using this circuit!  Before you turn this on, check myconnections are accurate, your connections are correct and you understand what’s happening.

Click to Zoom

(Note: try not to use my clock multiplier circuit if you build this.  It’s better to start with a 32 MHz oscillator and divide the clock by 2 to drive the Arduino than to use my hack.  Plus, that would cut your IC count down by 2-3.)

## How Did You Achieve 640×480?

Click to Zoom

At this point I’d like to thank three folks in particular for inspiring this project.  Nick Gammon is the first – his VGA library was the start point for this successful project, and this demo requires his Timing library.  His timers greatly simplified the interrupt writing necessary for this project.  His wiring diagrams and initial code-base were also invaluable to sanity checking my early prototypes.

Second, thanks are owed to Henning Karlsen, who had great 16×16 fonts available for easy use in Microcontroller projects.  Please checkout his projects, especially his UTFT related projects where he has a ton of resources for serial displays.  My message generator uses one of his fonts.

Third, to Linus Akesson (a.k.a. lft) who bitbanged vga color video out of a similar part back in 2008.  (His site, here).  Inspirational!

As for my project?  At the most basic level, I treated the 8-bit microcontroller hobbyists love to love as a 4 bit microcontroller by dividing its output into two logical parts.  For this demo, I had two sets of Reds, Greens and Blues, laid out like you see on the right somewhere (the Microcontroller is an Atmel ATMega 328p on an Arduino Nano board).

Pin D7: Red 1
Pin D6: Green 1
Pin D5: Blue 1
Pin D4: Red 2
Pin D3: HSync
Pin D2: Green 2
Pin D1 (Tx): N/C
Pin D0 (Rx): Blue 2

… that’s all Port D.

Once I had the 32 MHz clock I discussed in my last post, the project came together quickly: the 32 MHz clock goes to the Latch Enable Pin (11) of the LS373.  Enable gets tied to ground (always on), in effect latching to the 373 outputs to whatever value happens to be presented every 32 ns.

The 244N uses the stock 16 MHz clock, plus the clock 180 degrees out of phase with itself connected to the two enables.  When one clock is high, the other is low, so only one pixel is allowed through to the 373N… and thus presenting ~810 samples to the monitor for every 640 pixel horizontal (and viewable) cycle.  Yes, that’s 640+ samples, completing my goal so I can sleep well at night.

## Could You Simplify the Circuit?

If you give up color fidelity/the latch, you can use the clock and an inverted clock into the enables on the DM74LS244N – 2 chips.

As for real answers, some folks will be bothered by the mild amount of chip inflation on the board.  Setting aside the fact that you could achieve a 32MHz clock with an external crystal, and divide it to a 16MHz clock for the Arduino (thus eliminating 3 ICs) I’ve thought about it a bit, and I can’t come up with a way to clock out more than one pixel per clock without some active component assistance.

The “simplest way to simplify” would be to get rid of the latch and the buffer and go to a transistor only setup.  I tried to do this with common NPNs and PNPs –2222s and 3904s  and 3906s -  but they just didn’t have the switching speed necessary.  I don’t have any higher speed transistors, but I’d love if someone tried to dothis with something faster.  I’m thinking:

2 transistors per bus for R/G/B, one active high and one active low, then the 470 ohm resistors into the VGA port.

If you pull that off you can kill the clock circuit completely since we’ll be clocking at 32 MHz a second – low clock AND high clock assuming your transistors are fast enough.

As for doing it with all passive components?  Perhaps by introducing some well timed delays with some fancy math and carefully selected components?  I doubt it; my guess is you’ll attenuate the signal too much for it to be useful to the monitor/TV; I believe some silicon/silicon equivalent will need to be in there.  So, myguess is the minimum circuit is 6-8 transistors (PNP/NPNs) and some resistors.

Please someone try to prove that wrong, though!  It would make my year to see someone improve this design!

## What Problems Did You/Do You Face?

Simple – samples, samples everywhere.  We’re talking errors on top of errors.  First off, you’ve got the ugly clock with the fluctuating duty cycle which is a consequence of the hack from last article.  That’s not the main problem though.

The biggest issue is the fact that we’re now clocking at 32 MHz into a standard calling for 25.175 MHz.  While that wasn’t a problem when folks were producing less pixels than 640 – you were guaranteed to have at least one of your pixels sampled – at 32 MHz you actually lose data.  It’s also far enough off that you get weird artifacts like you can see in this demo picture with my Nano displaying of the name of an Painfully Ordinary blog you should subscribe to (and showing off 640 pixels per line and its beautiful 8 color palette!):

The error is huge: 32 / 25.175 =~ 27% error rate!  It’s safe to say there’s an issue every 3-4 pixels: the monitor will sample while the latch is changing, or catch it during propagation delay (low to high or high to low isn’t instantly 5v or 0v) and render a color darker than we intended.  Take note: there shouldn’t be vertical linesin the solid color horizontal bars in my video.

The third factor is technological – the monitor samples our jittery 32MHz hacked clock at 25.175 MHz to try to get 640×480.  The monitor itself?  1920×1080.  For this particular monitor, that’s not an issue because I can get it to display double pixels at 1280×960 and letterbox the sides (and leave a sliver at the bottom – see the demo) of the screen.  But still, of course, blowing up pixels means you’re also zooming in on the problems we just discussed while the monitor is trying to smooth out the area between pixels.  So, yes, errors on top of errors.

## How Could You Improve It?

First, and simply, the clock.  Most Unexceptional would be to clock the Arduino at 12.5875 MHz using a divide by 2 (use a counter) after a 25.175MHz oscillator.  Second Most Unexceptional, is to target a higher clock rate.  That could be either with VESA ‘non-standard standards’ or with other accepted timings (which aren’tquite 640×480@60 – that’s the gold standard).  640×480@73 fps, for example, needs a 31.5 MHz clock – that’s only a 1.59% error.  Quite the cleanup from 27%.  You can also use VESA timings targeted at 32 MHz – YMMV, and you’ll have to read the specs on your target monitor.

Second, a fourth bit of color for each pixel (remember, we divided our 8 bit processor into 2 – we’re wasting a bit).  It’s a nonstandard palette, but RGBI is doable.  You just need to move the one sync pin.

Third, external memory.  The only practical use of the code as is?  A digital signage display, or a silly hack for a personal web site (wait a second…).  There isn’t enough on-board RAM to store discrete pixel information for 640×480, you only get one clock per two pixels already, and self-modifying code on a Harvard Architecture uC which can only run from flash is… not smart.

## How Can I Use It?

Sorry I buried this – I really wanted everyone to understand the challenges first.  Usage is simple:

1. Burn the CKOUT fuse on your AVR microcontroller – you need to Google how to do this; I did it on a Mac by modifying “boards.txt” and choosing “Burn Bootloader” in the Arduino IDE.  This puts the 16 MHz clock on pin D8 for the Nano.
2. Next, grab Nick Gammon’s Timer libraries.
3. Third, download our code which runs the demo for the below video from here:Full640x480Video (zip)
4. Wire up the schematic – make sure to find a way to get a doubled clock.  We suggest a PLL or using a higher clock to begin with then dividing it for the Arduino to use.  You can always do something like my clock doubler circuit, but please, please do it a better way.

Want to edit the text to something meaningful to you?

We made a script to make it easy to change the message displayed.  Click here to try it out – you just need to copy/paste the output into the fontLines16.h and fontLines16_2.h file and overwrite whatever is there to see the message transition.  (On a side note, that’s Javascript compiling C which you’ll copy & paste into the Arduino IDE running on Java which compiles to AVR assembler.  Hard to wrap my head around it!)

Oh, of course, you do this at your own risk.  I won’t be held responsible for any trouble you get into trying to reproduce this project, especially with whatever expensive (or cheap) equipment you expose this too.  This is on you; please understand what is wired to what and why; I can’t guarantee my schematics are 100% accurate.  If there is a conflict, please refer to the picture of the circuit board, if it helps (that one works – well, at least on all the monitors in my house), but even then you should work through it on your own before trusting a random guy on the internet.

Since you’ve been waiting patiently, finally, let’s show the demo.  We show off all 8 colors – each in rows 10px high,  a ’14 color’ video rainbow made by mixing pixels, then (ugly, see: 27% timing error) some writing, then 10 lines of clocking out 640 pixels of red/white mixed followed by blue/white mixed.

## The Demo!

And if video isn’t your thing, you don’t want to build it and you don’t believe me that it is doing at least 640 pixels (don’t feel bad, my wife didn’t believe me at first, either), here’s a full screen capture off my SLR.

Each band is 8 colors – black, white, red, green, blue, yellow, cyan and purple.  Remember, each pixel by definition can only hold one color – I explicitly draw a new color in each pixel.  So pick a color (say, red – that one is easy to see), count it, then multiply by 8:

Full crop of color bars from an Arduino (Click for full width)

If you still don’t believe me (you must be fun at parties!), pop up the AVR 8-bit instruction listing.  Search for the ‘OUT’ instruction.  Note that it is a one clock instruction (16 MHz).  Note that we treat each ‘OUT’ as 2 pixels using our external hardware (2x16MHz = 32 MHz, which is more than 25.175), so if you look at the assembly generated by our code it looks like a whole bunch of this:

•   // PORTD = B01010100; <— 010 Green on one pixel, 110 Yellow on the one next to it
4c2:    9b b9           out    0x0b, r25    ; 11