Archive for category Programming

Various 2D and 3D effects collection, 1996-1998, Pascal & Assembler

Various 2D and 3D effects collection, 1996-1998, Pascal & Assembler

, ,

No Comments

Flame effects, 1997, Pascal & Assembler

Various flame effect I coded in 1997 using Pascal and Assembler.

program weisnisch;
uses crt;
const points = 512;
type RGB = record
            r,g,b : byte;
           end;
     paltype = array[0..255] of RGB;
     punkt = record
              xphase,yphase,zphase : integer;
              addy,addx,addz : integer;
             end;

var vgmseg,vgmofs : word;
    vgmptr : pointer;

    xtab,ytab,ztab : array[0..255] of integer;
    sintab,costab : array[0..255] of integer;

    point : array[0..points] of punkt;

    bol : boolean;

    wz : integer;
procedure initmode13h; assembler;
asm
 mov ax,0013h
 int 10h
end;

procedure rettext; assembler;
asm
 mov ax,0003h
 int 10h
end;

procedure putpixel(x,y : integer; c : byte); assembler;
asm
 mov ax,vgmseg;
 mov es,ax
 mov ax,320
 mul y
 add ax,x
 mov di,ax
 mov cl,c
 mov es:[di],cl
end;

procedure waitcrt; assembler;
asm
  mov dx,3dah
 @wait1:
  in al,dx
  test al,08h
  jnz @wait1
 @wait2:
  in al,dx
  test al,08h
  jz @wait2
end;

procedure refresh; assembler;
asm
 push es
 push ds

 mov ax,0a000h;
 mov es,ax

 mov ds,vgmseg
 xor di,di
 xor si,si
 mov cx,8000h
 rep movsw

 pop ds
 pop es
end;

procedure clearvgm; assembler;
asm
 mov es,vgmseg
 xor di,di
 mov ax,0
 mov cx,8000h
 rep stosw
end;

procedure moveflammes; assembler;
asm
 mov es,vgmseg
 mov di,vgmofs
 mov si,vgmofs

 add di,0000
 add si,0320 {eine Zeile drunter}

 mov cx,63200
@flameloop1:
 xor ax,ax
 xor bx,bx

 mov al,es:[si+1]
 add bx,ax
 mov al,es:[si-1]
 add bx,ax
 mov al,es:[si+320]
 add bx,ax
 mov al,es:[si-320]
 add bx,ax
 mov al,es:[si-321]
 add bx,ax
 mov al,es:[si-319]
 add bx,ax
 mov al,es:[si]
 add bx,ax
 mov al,es:[si+319]
 add bx,ax

 shr bx,3
 or bl,bl
 jz @nodecrement
 dec bl
 @nodecrement:
 mov es:[si],bl

 inc si
 inc di

 dec cx
 jnz @flameloop1
end;

procedure setpal(pal : paltype);
var pc : byte;
begin
 port[$3c8]:=0;
 for pc := 0 to 255 do
  begin
   port[$3c9]:=pal[pc].r;
   port[$3c9]:=pal[pc].g;
   port[$3c9]:=pal[pc].b;
  end;
end;

procedure trans3(x,y,z : integer;var x2,y2 : integer);
begin
 if z = 0 then
   z := 1;

  y2 := (y * 128) div z + 100;
  x2 := (x * 128) div z + 160;
end;

procedure putpoints;
var a : word;
    x,y,z : integer;
    x2,y2 : integer;
begin
  for a := 0 to points do begin
   x := xtab[hi(point[a].xphase)];
   y := ytab[hi(point[a].yphase)];
   z := ztab[hi(point[a].zphase)];

   trans3(x,y,z+wz,x2,y2);
   putpixel(x2,y2,255);
 end;
end;

procedure calcpoints;
var a : word;
    x,y,z : integer;
begin
  for a := 0 to points do begin
   point[a].xphase := point[a].xphase + point[a].addx;
   point[a].yphase := point[a].yphase + point[a].addy;
   point[a].zphase := point[a].zphase + point[a].addz;
  end;

  x := point[0].addx;
  y := point[0].addy;
  z := point[0].addz;

  for a := 0 to points-1 do begin
   point[a].addx := point[a+1].addx;
   point[a].addy := point[a+1].addy;
   point[a].addz := point[a+1].addz;
  end;

  point[points].addx := x;
  point[points].addy := y;
  point[points].addz := z;

end;

procedure firelinehor(x1,x2,y : integer);
var k : integer;
begin
 for k := x1 to x2 do
  putpixel(k,y,random(255));
end;

procedure firelinevert(y1,y2,x : integer);
var k : integer;
begin
 for k := y1 to y2 do
  putpixel(x,k,random(255));
end;

procedure main;
var a,c : byte;
    i,f,addx : integer;
    pal : paltype;
begin

 fillchar(pal,768,0);
 for a := 1 to 32 do begin
  pal[a].r := (a-1)*2;
  pal[a].g := 0;
  pal[a].b := 0;
 end;
 for a := 32 to 64 do begin
  pal[a].r := 63;
  pal[a].g := (a-32)*2;
  pal[a].b := 0;
 end;
 for a := 64 to 96 do begin
  pal[a].r := 63;
  pal[a].g := 63;
  pal[a].b := (a-64)*2;
 end;
 for a := 96 to 255 do begin
  pal[a].r := 63;
  pal[a].g := 63;
  pal[a].b := 63;
 end;
 setpal(pal);

 for a := 0 to 255 do begin
  sintab[a] := round(sin(a / 40.58451) * 128);
  costab[a] := round(cos(a / 40.58451) * 128);
 end;

 for a := 0 to 255 do begin
  xtab[a] := sintab[a] div 2;
  ytab[a] := costab[a] div 2;
  ztab[a] := costab[a] div 2;
 end;
 addx := 0;
 wz := 150;

 for i := 0 to points do begin
  point[i].xphase := sintab[byte(i)] shl 8;
  point[i].yphase := costab[byte(i+100)] shl 8;
  point[i].zphase := i shl 8;
  point[i].addx := 400;
  point[i].addy := 900;
  point[i].addz := 500;
 end;

 bol := false;
 f := 4;
 repeat
   calcpoints;
   putpoints;
{
   firelinevert(80,120,100);
   firelinehor(100,120,80);
   firelinevert(80,120,120);
   firelinehor(100,120,100);

   firelinevert(80,120,130);
   firelinehor(130,150,80);
   firelinehor(130,150,120);

   firelinevert(80,120,160);
   firelinehor(160,180,80);
   firelinevert(80,120,180);

   firelinevert(80,120,190);
   firelinevert(80,120,210);
   firelinehor(190,210,80);
   firelinehor(190,210,120);

 }
   moveflammes;
   waitcrt;
   refresh;

 until keypressed;
 refresh;
 repeat until keypressed;
end;

begin

initmode13h;
getmem(vgmptr,64000);

vgmseg := seg(vgmptr^);
vgmofs := ofs(vgmptr^);

clearvgm;

main;

rettext;
freemem(vgmptr,64000);

{Coded 1997 by ACMD}

end.

, ,

1 Comment

Plasma effect, January 1997, Pascal & Assembler, 320×200, Mode 13h

Plasma effect I coded in 1997. Resurrected using DOSBox on my MacBook.

program plasma;
uses crt,palettes;
var vgmptr : pointer;
vgmseg : word;

sintab,
costab : array[0..255] of shortint;

procedure initmode13h; assembler;
asm
mov ax,0013h
int 10h
end;

procedure rettext; assembler;
asm
mov ax,0003h
int 10h
end;

procedure putpixel(x,y : integer; c : byte); assembler;
asm
mov ax,vgmseg;
mov es,ax
mov ax,320
mul y
add ax,x
mov di,ax
mov cl,c
mov al,es:[di]
or al,cl
mov es:[di],al
end;

procedure waitcrt; assembler;
asm
mov dx,3dah
@wait1:
in al,dx
test al,08h
jnz @wait1
@wait2:
in al,dx
test al,08h
jz @wait2
end;

procedure refresh; assembler;
asm
push es
push ds

mov ax,0a000h;
mov es,ax

mov ds,vgmseg
xor di,di
xor si,si
mov cx,8000h
rep movsw

pop ds
pop es
end;

procedure clearvgm; assembler;
asm
mov es,vgmseg
xor di,di
mov ax,0
mov cx,8000h
rep stosw
end;

function cosa(value : integer): shortint;
var erg : byte;
begin
asm
lea si,costab
mov ax,value
mov ah,0
add si,ax
mov al,ds:[si]
mov erg,al
end;
cosa := erg;
end;

function sina(value : integer): shortint;
var erg : byte;
begin
asm
lea si,sintab
mov ax,value
mov ah,0
add si,ax
mov al,ds:[si]
mov erg,al
end;
sina := erg;
end;

procedure main;
var c,a,x,y : integer;
cx,cy : byte;
e : byte;
offs : word;
sc,tc : byte;
zwcolor : shortint;
color : byte;

apal,pal,pal2 : paltype;
begin
for a := 0 to 255 do sintab[a] := round(sin(a / 40.743665)*64);
for a := 0 to 255 do costab[a] := round(cos(a / 40.743665)*64);

clearvgm;

fillchar(pal,768,0);
for e := 0 to 63 do begin
pal[e].r := 0;
pal[e].g := 0;
pal[e].b := e;
end;
for e := 0 to 63 do begin
pal[e+64].r := e;
pal[e+64].g := e;
pal[e+64].b := 63;
end;
pal[128].r := 63;
pal[128].g := 63;
pal[128].b := 63;

fillchar(pal2,768,0);
for a := 1 to 32 do begin
pal2[a].r := (a-1)*2;
pal2[a].g := 0;
pal2[a].b := 0;
end;
for a := 32 to 64 do begin
pal2[a].r := 63;
pal2[a].g := (a-32)*2;
pal2[a].b := 0;
end;
for a := 64 to 96 do begin
pal2[a].r := 63;
pal2[a].g := 63;
pal2[a].b := (a-64)*2;
end;
for a := 96 to 255 do begin
pal2[a].r := 63;
pal2[a].g := 63;
pal2[a].b := 63;
end;

setpal(pal);

e := 0;

repeat
clearvgm;
offs := 640;
asm;
mov es,vgmseg
end;
for y :=  1 to 100 do begin
for x :=  1 to 160 do begin

zwcolor := sina( y+sina(x-y)+e+e)+e+
cosa( x+sina(y+x)-e-e+sina(e));
asm
mov al,zwcolor
inc al
dec al
jns @noneg
neg al
mov zwcolor,al
@noneg:
end;
color := zwcolor;
asm
mov di,offs
mov al,color
mov ah,al

mov es:[di],al
mov es:[di+321],al

mov ax,word ptr es:[di]
add ax,word ptr es:[di+319]
add ax,word ptr es:[di-2]
add ax,word ptr es:[di-321]

shr ax,2
mov es:[di-1],al

mov ax,es:[di]
add ax,es:[di-319]
add ax,es:[di-321]
add ax,es:[di-321]
shr ax,2
mov es:[di-320],al

add offs,2

end;
end;
offs := offs + 320;
end;

inc(e,2);

delay(10);
waitcrt;
refresh;
until keypressed;
end;

begin

initmode13h;
getmem(vgmptr,64000);
vgmseg := seg(vgmptr^);

main;

freemem(vgmptr,64000);
rettext;

writeln('Coded January ''97 by ACMD');

end.

, ,

No Comments

Snowfall Effect

Digging through my archive i managed to resurrect some code i wrote when I was 15. This was written in Pascal and Assembler and ran on my i386 and later on a Pentium 100Mhz. To my utter delight DOSBox does a great job of running this old exe: Here’s the video capture on my modern laptop:

Here are some other effects i coded at the time:

Plasma effect

Flammes

Various 2D and 3D

The source for the version with the snowman appears to have been lost in time, but here’s an earlier version with a simple line as an obstacle for the snow.

Source code (oh man, this is awful. I know – no comments, bad style, cryptic variables – c’mon, i was 15 years old, ok ?)

program schneeeffect;
uses crt;
type SCHNEE = record x,y: integer; end;
var a : integer;
    snow : array[0..250] of SCHNEE;
    xcolor : byte;
    r,d,l : boolean;
    addsub : integer;
    range : byte;
    flag : byte;
    zzz : integer;

    procedure initmode13h;assembler;
  asm
   mov ah,0
   mov al,13h
   int 10h
  end;

  procedure rettext; assembler;
  asm
   mov ah,0
   mov al,3h
   int 10h
  end;

  procedure putpixel(x,y : integer;color : byte);assembler;
  asm
   mov ax,0A000h
   mov es,ax
   mov ax,y
   mov dx,320
   mul dx
   mov bx,x
   add bx,ax
   mov al,color
   mov byte ptr es:[bx],al
  end;

  procedure getpixel(x,y : integer;var color : byte);
  var pointcol : byte;
  begin
  asm
   mov ax,0A000h
   mov es,ax
   mov ax,y
   mov dx,320
   mul dx
   mov bx,x
   add bx,ax
   mov al,byte ptr es:[bx]
   mov pointcol,al
  end;
  color := pointcol;
  end;

  procedure waitcrt; assembler;
  asm
    mov dx,3dah
    @wait1:
    in al,dx
    test al,08h
    jnz @wait1
    @wait2:
    in al,dx
    test al,08h
    jz @wait2
  end;

begin

 initmode13h;

 for a:=1 to 250 do begin
  snow[a].x := random(320);
  snow[a].y := random(190);
 end;

 for a := 100 to 150 do begin
  putpixel(a,a,31);
  putpixel(a,a+1,31);
 end;
 repeat
   for a:=1 to 250 do putpixel(snow[a].x,
                               snow[a].y,
                               15);
   delay(10);
   waitcrt;
   for a:=1 to 250 do putpixel(snow[a].x,
                               snow[a].y,0);
   for a:=1 to 250 do
   begin
    addsub := random(3) -1;

    getpixel(snow[a].x+1,snow[a].y+1,xcolor);
    if xcolor>15 then r:=true else r:=false;
    getpixel(snow[a].x-1,snow[a].y+1,xcolor);
    if xcolor>15 then l:=true else l := false;
   getpixel(snow[a].x,snow[a].y+1,xcolor);
    if xcolor>15 then d := true else d := false;

   if (r) and (addsub= 1) then addsub := 0;
   if (l) and (addsub=-1) then addsub := 0;

   if (d) and (addsub=0) then
    begin
     if not r then addsub := 1;
     if not l then addsub := -1;
     if r and l and d then addsub := 10;
    end;
   if snow[a].y >= 198 then addsub:=10;
   if addsub<>10 then begin
    snow[a].x := snow[a].x + addsub;
    inc(snow[a].y);
   end else
    begin
     putpixel(snow[a].x,snow[a].y,31);
     snow[a].x := random(320);
     snow[a].y := 0;
    end;
  end;
 until keypressed;
 rettext;

end.

, ,

2 Comments

Alternate States of Proteins Revealed by Detailed Energy Landscape Mapping

After about 2 years of work, millions of CPU hours donated by volunteers from around the globe on Rosetta@HOME and a fruitful collaboration with Daniel Keedy and Jane and David Richardson at Duke University our paper on energy landscapes is finally out! Thank you to everyone who helped and especially to Daniel Keedy @ Duke and all who have donated computing time!

Alternate States of Proteins Revealed by Detailed Energy Landscape Mapping

Michael D. Tyka, Daniel A. Keedy, Ingemar André, Frank DiMaio, Yifan Song, David C. Richardson, Jane S. Richardson and David Baker

contributed equally

What conformations do protein molecules populate in solution? Crystallography provides a high-resolution description of protein structure in the crystal environment, while NMR describes structure in solution but using less data. NMR structures display more variability, but is this because crystal contacts are absent or because of fewer data constraints? Here we report unexpected insight into this issue obtained through analysis of detailed protein energy landscapes generated by large-scale, native-enhanced sampling of conformational space with Rosetta@home for 111 protein domains. In the absence of tightly associating binding partners or ligands, the lowest-energy Rosetta models were nearly all < 2.5 Å CαRMSD from the experimental structure; this result demonstrates that structure prediction accuracy for globular proteins is limited mainly by the ability to sample close to the native structure. While the lowest-energy models are similar to deposited structures, they are not identical; the largest deviations are most often in regions involved in ligand, quaternary, or crystal contacts. For ligand binding proteins, the low energy models may resemble the apo structures, and for oligomeric proteins, the monomeric assembly intermediates. The deviations between the low energy models and crystal structures largely disappear when landscapes are computed in the context of the crystal lattice or multimer. The computed low-energy ensembles, with tight crystal-structure-like packing in the core, but more NMR-structure-like variability in loops, may in some cases resemble the native state ensembles of proteins better than individual crystal or NMR structures, and can suggest experimentally testable hypotheses relating alternative states and structural heterogeneity to function.

imglarge

[Fulltext]

, ,

2 Comments

GuitarHero vs Games with Real Instruments

For some time now i’ve been interested and have been thinking about learning and video games. When i first played guitarhero a long time ago it was clear to me that, especially with the drum kit, i was actually learning useful hand-foot coordination skills which would pply directly to playing a real drum kit. Unfortunately the guitar was entirely ridiculous (5 button controller) and had nothing to do at all with playing a real guitar except your general body posture. Surely i thought the next step is to have people actually play a guitar. Or a piano for that matter. Why hasn’t anyone made a game like that ? I started playing around with MIDI and OpenGL and made a very rudimentary piano hero kind of game.

midihero

But, of course, people have thought of this stuff well before me.

The oldest incarnation of such a thing i found was “Keyboard Mania”, a game developed by Konami in 2000 as an Arcade game.  A simple 24-key piano keyboard input device, notes fall from the top, you have to hit them as they reach the bottom.

A much modern version, less of a game and more of a tutor, was until recently called PianoHero (Until Harmonix sent the developer a cease and desist letter) and is now called Synthesia. This is a well written, slick looking program that can be fed with and MIDI file and is totally fun! It was OpenSource until recently but is still free which is fabulous.

Similarily for guitar, people are trying to make gaming software controlled by the actual instrument.The problem here of course is much harder since rather then having a clean stream of input MIDI notes, you have to interpret an audio stream and discern which notes were played. THis is difficult because the the same note can be played in different locations on the guitar especially when multiple notes are played together such as when playing chords.

However, next year a product called Guitar Rising is expected to come out. They seem to have done a pretty good job! These guys have even filed a patent application (pending), quite a broad patent actually which as far as i can tell would include the above piano programs.

A free version of exactly the same concept though is called LittleBigStar or soon to be known as Offbeat, apparently.

Dhani Harrison, the son of Beatle George Harrison, very recently remarked that he’s  “working on Rock Band 3 and making the controllers more real so people can actually learn how to play music while playing the game.” He claims: “Give me a couple years, it’s going to happen.” Clearly it’s already happened. But what’s maybe more interesting is that if you read comments and forums about the statement, people are of two minds about that. Many people express a sentiment along the lines of “if i wanted to learn an instrument i’d do it – but i just wanna jam along to my favourite tunes with my friends not having to learn anything complicated”. This is something to think about: Its all good ‘n great to make games or software to teach humans do things more efficiently then was possible before, but they have to want to.

, ,

No Comments

Fruitycubes Screensaver/Effect

The other day i was playing around with OpenGL and started looking at some Demos for Macs (http://mac.scene.org/). I used to be very interested in the scene when i was about 15 but didn’t end up doing a career in computer science and found other things to be obsessed about so stopped actively following the development in Demo programming. Occasionally I’d pop over to scene.org and download a couple of the latest demos to see what was possible. Anyway, so I’ve been playing a little with OpenGL again in the last few weeks, mainly for other projects, but watching a few of the Demos available for macs i got inspired to write a graphical, real time effect, something I haven’t done for at least 12 years. The timing was good because we had a massive party at our house that weekend and so I ended up projecting this on the ceiling for everyone’s enjoyment.

Here’s the result:

http://www.miketyka.com/data/fruitycubes.tgz

(MacOS X Executable, free for non-commercial use)

, ,

No Comments