carbon-based lifeform. virgo supercluster
Click here for the HTML5 demo in Javacript
This is a visualization inspired by the article Mathematicians Discover Prime Conspiracy by Erica Klarreich on Quanta Magazine.
Previously I wrote Twin primes visualized over an Ulam Spiral in HTML5, I reused the code and added the coloring as:
Here is the result with each square with size 4 pixels:
Here is the same with each square of size 2 pixels:
And with 1 pixels:
As before, the source code (prime_conspiracy.html) is available at github.com/silveira/ulam.
Click here for the HTML5 demo in Javacript.
Two numbers p and q are twin primes if they are primes and |p – q | = 2.
The Ulam spiral, discovered by the mathematician Stanislaw Ulam in 1963, is a simple method to visualize prim numbers. Put the natural numbers in a spiral and draw only the ones which are primes.
In the visualization below, I’m drawing the prime numbers in two shades of green. Twin primes in light green and regular primes in dark green.
The “vortex effect” is created because every twin prime is followed by its twin two steps before in the spiral. Below the same image with the zoom in the center:
In the HTML5 demo in Javacriptthe spiral is draw dynamically in a image (warning: it can be a little bit computationally intensive for your machine). You can play with the source-code on Github, and change the parameters. If you are looking for a plain ulam spiral, here it is one.
Update (May 30, 2013): This post was featured on the Blog of Math Blogs.
Update (November 25, 2013): I created a standalone Github project for this code.
https://github.com/silveira/ulam
Code:
var canvas; var ctx; var background; var width = 300; var height = 200; var cloud; var cloud_x; function init() { canvas = document.getElementById("cloud_demo_canvas"); width = canvas.width; height = canvas.height; ctx = canvas.getContext("2d"); // init background background = new Image(); background.src = 'http://silveiraneto.net/wp-content/uploads/2011/06/forest.png'; // init cloud cloud = new Image(); cloud.src = 'http://silveiraneto.net/wp-content/uploads/2011/06/cloud.png'; cloud.onload = function(){ cloud_x = -cloud.width; }; return setInterval(main_loop, 10); } function update(){ cloud_x += 0.3; if (cloud_x > width ) { cloud_x = -cloud.width; } } function draw() { ctx.drawImage(background,0,0); ctx.drawImage(cloud, cloud_x, 0); } function main_loop() { draw(); update(); } init(); |
HTML code:
<canvas id="cloud_demo_canvas" width="640" height="480">Alternative text if browser don't support canvas.</canvas> |
Credits and notes:
A simple code to show the script engines installed in your system.
As it uses the JSR-223 you need at least java 6.
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineFactory; import java.util.List; public class ListEngines { public static void main(String[] args){ ScriptEngineManager manager = new ScriptEngineManager(); List <ScriptEngineFactory> engines = manager.getEngineFactories(); for(ScriptEngineFactory engine: engines){ String name = engine.getEngineName(); String lang = engine.getLanguageName(); String ver = engine.getLanguageVersion(); System.out.println(name+" "+lang+" "+ver); } } } |
$ java -version
java version “1.6.0_0”
OpenJDK Runtime Environment (build 1.6.0_0-b11)
OpenJDK Client VM (build 1.6.0_0-b11, mixed mode, sharing)
$ javac ListEngines.java
$ java ListEngines
Mozilla Rhino ECMAScript 1.6
For now I just have Rhino ECMAScript (JavaScript) engine accessible that comes with Java 6. I’m trying now to call Jython and JRuby code.
O Netbeans.org anunciou a disponibilidade do NetBeans IDE 6.5 Beta. Abaixo a tradução do anúncio:
O NetBeans IDE 6.5 introduz várias novas funcionalidades, incluindo uma IDE robusta para PHP, deputação de JavaScript para o Firefox e IE, e suporte a Groovy e Grails. Esse lançamento também inclui várias melhorias para o desenvolvimento em Java, Ruby e Rails, e C/C++. Dentre as melhorias no Java destacam-se: suporte nativo ao Hibernate, importação de projetos do Eclipse, e compilação no salvamento.
Links:
Outros destaques:
O NetBeans IDE 6.5 final está planejado para ser lançado em Outubro de 2008. Como sempre, é bem vindo e nós encorajamos seu feedback sobre sua experiência usando a IDE NetBeans. Visite nossas listas de email ou faça uma postagem no seu blog.