faking 3D ripples

Wednesday, 29 April 2026 12:16 pm
miriam_e: from my drawing MoonGirl (Default)
[personal profile] miriam_e
Fiddling around more with old algorithms instead of packing up. Yes, I'm an idiot.

This is a cute way of faking 3D. First it plots this wave, with each line shifted down by two scanlines and right by one pixel. That draws an isometric image, but I fake perspective by gradually widening each line at its right edge. And I fake hidden line removal by drawing each line as a solid made up of vertical black lines, each topped with a white pixel.

#! /bin/awk -f

# ripple
#
# Miriam
# Wednesday 2026-04-29 08:45:20 am
#
# fake a 3D view of a ripple
#

BEGIN{
    # Read canvas size (close it if getline needed again)
    "echo \"size\" | candraw" | getline
    wide = $1
    high = $2

    print "clear"

    xl=10                       # drawn left edge
    xr=390                      # drawn right edge
    xoffset=200 ; yoffset=300   # ripple offset
    ystart=100                  # top of image
    yend=300                    # last scan

    for (y=1 ; y<yend ; y+=2){  # leave gap between lines to fake shade
        xr++                    # fake perspective on right edge

        for (x=xl ; x<xr ; x++){
            xa=x-xoffset ; ya=2*y-yoffset
            c=sqrt(xa*xa+ya*ya)+1
            a=c*0.06+0.6                          # frequency
            m=sin(a+a/6)/a/sqrt(a)*100            # amplitude
            xp=x+y/2 ; y1=y+ystart+15 ; y2=y-m+ystart
            if (xp>0 && xp<wide && y1<high){
                print "line " xp, y1 " (black) - " xp, y2
                print "pset " xp, y2 " (white)"
            }
        }
    }
}

And since awk doesn't have any graphics commands I send the output of the awk program to my candraw bridge program which connects to my graphics server.
./ripple.awk | candraw

Profile

miriam_e: from my drawing MoonGirl (Default)
miriam_e

May 2026

S M T W T F S
      12
3456789
10111213141516
17181920212223
24252627282930
31      

Style Credit

Expand Cut Tags

No cut tags
Page generated Saturday, 2 May 2026 07:32 pm
Powered by Dreamwidth Studios