## nds line-demo

Since my first demo for the Nintendo DS used the bresenham circle algorith, i had to write another starring its famouse brother - the bresenhaml line-algorithm. Which is a bit trickier than it seems when you first look at it. it took me 4 tries to make it work in all quadrants.

For those of you who don't own a nds i included a screenshot this time made using a emulator. imagine the upper part of the screenshot beeing displayed on the upper screen of the DS.

``````#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void setPixel( int x, int y, int color ) {
VRAM_A[x + y * 256] = color;
}

void line( int x1, int y1, int x2, int y2, int c ) {
bool swap = abs( y2 - y1 ) > abs ( x2 - x1 );
int x1t =  swap ? y1 : x1;
int y1t =  swap ? x1 : y1;
int x2t =  swap ? y2 : x2;
int y2t =  swap ? x2 : y2;

int xs =  x1t < x2t ? x1t : x2t;
int ys =  x1t < x2t ? y1t : y2t;
int xt =  x1t < x2t ? x2t : x1t;
int yt =  x1t < x2t ? y2t : y1t;

int dx = xt - xs;
int dy = abs(yt - ys);

int dT = 2 * ( dy - dx );
int dS = 2 * dy;
int d = 2 * dy - dx;
int x = xs;
int y = ys;

if ( swap )  {
setPixel( y, x, c );
} else {
setPixel( x, y, c );
}

while ( x < xt ) {
x++;
if ( d < 0 ) {
d = d + dS;
} else {
if ( ys < yt ) {
y++;
} else {
y--;
}
d = d + dT;
}
if ( swap )  {
setPixel( y, x, c );
} else {
setPixel( x, y, c );
}
}
}

int main(void) {
touchPosition touch;
// set lower screen to FB
videoSetMode(MODE_FB0);
vramSetBankA(VRAM_A_LCD);

// set upper stcreen to textmode
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
vramSetBankC(VRAM_C_SUB_BG);
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(31,31,31);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

iprintf("coded by guru
``````

");

``````    // make sure main screen is on bottom
lcdMainOnBottom();

while(1) {
scanKeys();

if(keysHeld() & KEY_TOUCH) {
line( 128, 96, touch.px, touch.py, RGB15(
31 * abs(touch.px - 128) / 128,
31 * abs(touch.py-96) / 96,
0
));
}

// clear screen if key A is pressed
if (keysHeld() & KEY_A) {
for ( int y = 0; y < 192; y ++ ) {
for ( int x = 0; x < 256; x ++ ) {
setPixel( x, y, 0);
}
}
}
}
return 0;
}
``````

## Neonworms

I made another usless little processing-sketch. This time staring some neonworms

## javafx sdk on linux

I wanted to give the java fx sdk preview a try and got a bit confused, because there where no downloads for linux.

so i downloaded the macos version without netbeans (the zip file - not the dmg), unpacked it and set some environment variables (JAVAFX_HOME and JFX_HOME pointing to wherever you unpacked the zip file) - and TADA! A working javafx environment even under linux

if you write the code from below into a file called Hello.fx and compile it using

``````javafxc -d . Hello.fx
``````

and run it using

``````javafx Hello
``````

This should result in something like this

``````import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;
import javafx.scene.text.*;
import javafx.scene.effect.*;
import javafx.scene.effect.light.*;

import javafx.ext.swing.*;

SwingFrame {
title: "Hallo Welt"
width: 310
height: 98
content: Canvas {
content: Group {
content: [
Rectangle {
x: 10
y: 10
width: 280
height: 50
arcWidth: 15
arcHeight: 15
fill: Color.web("#C0C0C0")
effect: Lighting {
light: DistantLight {
azimuth: 225
}
}
},
Text {
x: 150
y: 40
content: "Hello World!"
font: Font {
name: "Serif"
size: 20
style: FontStyle.BOLD
}
fill: Color.WHITE
horizontalAlignment: HorizontalAlignment.CENTER
}
]
}
}
visible: true
}
``````

## Voting trend visualisation

After every election, there is a poll resulting in a voter trend analysis. i always liked the graphs they made from the data on tv. This time i desided to make my own voter trend visualisation in processing.

i didn't know if i would be permitted to use actual data, so i used random() to generate it.

i wanted to test the "noLoop()" function from processing, so i did a digital version of them

## Shine a light

here is another little processing-sketch. this one is dedicated to everybody who wants to shine a litte light

## rotating box in openframeworks

I tried to write something simmilar to my neonbox-demo in openframeworks. At first a have been a bit puzzled because there is no rotate command.

Then i remembered that openframeworks uses OpenGL for drawing so glRotatef and glTranslatef can be used for rotating the image

``````    ...
int ang = 0;

void testApp::setup(){
ofSetVerticalSync( true );
ofSetFrameRate( 25 );
}

void testApp::draw(){
int width = ofGetWidth() / 2;
int height = ofGetHeight() / 2;

ofBackground( 0,0,0 );
glPushMatrix();
glTranslatef( width, height, 0 );
glRotatef( ang , 0, 0, 1);

ang++;
if (ang == 360) {
ang = 0;
}

ofFill();
ofSetColor( 255 * ( 1 + sin( ang * 2 * PI / 360 )) / 2,
255 * ( 1 + sin( PI + ang * 2 * PI / 360 )) / 2, 0 );

ofRect(  -300,  -50, 100, 100 );
ofRect(  -100,  -100, 200, 200 );
ofRect(  200,  -50, 100, 100 );

glPopMatrix();
}
...
``````

This time i also made a little screenshot for those who don't have openframeworks installed (yet :-) )

## Zoom'n'Pan Demo

A colleague asked me how zoom and pan could be implemented in processing. So i wrote a small "zoom'n'pan"-demo

## typo on debian

Yesterday i have installed typo on a debian box. First i installed ruby, rails, mongrel, rake and gem - and when i wanted to install typo it told me that it didnt like my rails version :-/

so i installed rails 2.0.2 and then typo. After installing the blog, and configuring apache (i haaaaaaate mod_proxy rewrites in apache - i cant tell you how much!) typo thrwe some exceptions every time i wanted to write an article.

hrmpf

after googleling for some time, i found out that rails 2.0.2 isnt working with ruby 1.8.7. Instructions how to downgrade ruby can be found here and instructions how to keep debian from upgrading it again can be found here