Quote:
Originally Posted by geekmaster
...
The K3 also needs to be adjusted for 300 byte wide lines and the opposite color. This script has $MX $MY $HX and $HY vars to adjust, but you probably need to adjust other scale factors in the "draw3d" function as well. 
...
|

done:
Code:
#!/bin/sh
######################################
# rippleweave - algorithmic art script
# version 1.0a by geekmaster
######################################
#===========================
# initvar - init global vars
#---------------------------
initvar() {
DN=/dev/null DF=/dev/fb0 MX=599 MY=799 HX=300 HY=400
set $(eips -i|grep line_length); VX=$4
FP=1000 # fixed-point scale factor
FH=500 # FP/2 (for rounding)
PI=3142 # PI (scaled)
P2=6283 # 2*PI (scaled)
PN=-3142 # -PI (scaled)
KQ=2 # K3 pixels per byte
}
#==================================
# line - Bresenham's line algorithm
# usage: line x0 y0 x y
#----------------------------------
line() {
local x0=$(($1/$KQ)) y0=$2 x=$(($3/$KQ)) y=$4; local dx dy sx sy e e2 xw xp=$x0
if [[ $x -gt $x0 ]];then dx=$((x-x0));sx=1; else dx=$((x0-x));sx=-1;fi
if [[ $y -gt $y0 ]];then dy=$((y0-y));sy=1; else dy=$((y-y0));sy=-1;fi
e=$((dx+dy)); echo -en "\xff${b#?}" | dd of=$DF bs=1 count=1 seek=$((y*VX+x)) 2>$DN
while [[ $x0 -ne $x -o $y0 -ne $y ]];do
xw=$((x0-xp)); [[ $xw -lt 0 ]]&& xw=$((-xw))
echo -en "\xff${b#?}" | dd of=$DF bs=1 count=1 seek=$((y0*VX+x0)) 2>$DN
e2=$((e+e))
if [[ $e2 -gt $dy ]];then e=$((e+dy));x0=$((x0+sx));fi
if [[ $e2 -lt $dx ]];then
xp=$x0;e=$((e+dx));y0=$((y0+sy))
fi
done;
}
#=================================
# line3d - draw 3D line to (x,y,z)
# usage: line3d x0 y0 x y z cx cy
# x,y:-50..50 z:-150..150
# cy,cy:center graph coords
# x0,y0:old graph coords
# STDOUT: xg yg (new graph coords)
#---------------------------------
line3d() {
local x0=$1 y0=$2 x=$3 y=$4 z=$5 cx=$6 cy=$7; local xg yg
xg=$((cx+x*6+(y*2))); yg=$(((cy-y*4+x*2)-z))
[[ $x0 -ge 0 -a $y0 -ge 0 ]]&& line $y0 $x0 $yg $xg
echo $xg $yg
}
#==================================
# sin - Taylor series sine function
# usage: sin x (-PI..PI)
# STDOUT: sin(x) (0..1K)
# O(5) @ +-90 deg, O(7) @ +-180 deg
# 1K fixed-point scale factor
#----------------------------------
sin() {
local x=$1
while [[ $x -gt $PI ]];do x=$((x-$P2));done
while [[ $x -lt $PN ]];do x=$((x+$P2));done
local a=$x xs=$(((x*x+FH)/FP))
local xn=$(((x*xs+FH)/FP)) fn=6 # O(3)
a=$((a-(xn+fn/2)/fn)) xn=$(((xn*xs+FH)/FP)) fn=$((fn*20)) # O(5)
a=$((a+(xn+fn/2)/fn)) xn=$(((xn*xs+FH)/FP)) fn=$((fn*42)) # O(7)
a=$((a-(xn+fn/2)/fn)); echo $(((a+FP+1)/2))
}
#==============================
# mexhat - mexican hat function
# usage: mexhat x y (-50..50)
# STDOUT: mexhat (*1K)
#------------------------------
mexhat() {
local x=$1 y=$2; local yf yx xf xs rs s
yf=$((y*FP/13)); ys=$(((yf*yf+FH)/FP))
xf=$((x*FP/13)); xs=$(((xf*xf+FH)/FP))
rs=$((xs+ys)); s=$(sin $rs)
if [[ $rs -gt $((FP*8/10)) ]];then echo $((s*FP/rs))
else echo $((FP*18/10-rs));fi
}
#================================
# rippleweave - 3d function plot
# mexhat 8-way symmetry graph
# (800x600 landscape mode)
#---------------------------------
rippleweave() {
local cx=$HY cy=$HX y1 y2 y3 y4 y5 y6 y7 y8
line 0 0 $MX 0; line $MX 0 $MX $MY; line $MX $MY 0 $MY; line 0 $MY 0 0
for y in $(seq 0 2 50);do
y1=-1 y2=-1 y3=-1 y4=-1 y5=-1 y6=-1 y7=-1 y8=-1
for x in $(seq 0 2 50);do
f=$(mexhat $((x-50)) $((y-50))); fg=$((-150*f/FP))
set $(line3d $x1 $y1 $((x-50)) $((y-50)) $fg $cx $cy); x1=$1 y1=$2
set $(line3d $x2 $y2 $((x-50)) $((50-y)) $fg $cx $cy); x2=$1 y2=$2
set $(line3d $x3 $y3 $((50-x)) $((50-y)) $fg $cx $cy); x3=$1 y3=$2
set $(line3d $x4 $y4 $((50-x)) $((y-50)) $fg $cx $cy); x4=$1 y4=$2
set $(line3d $x5 $y5 $((y-50)) $((x-50)) $fg $cx $cy); x5=$1 y5=$2
set $(line3d $x6 $y6 $((y-50)) $((50-x)) $fg $cx $cy); x6=$1 y6=$2
set $(line3d $x7 $y7 $((50-y)) $((50-x)) $fg $cx $cy); x7=$1 y7=$2
set $(line3d $x8 $y8 $((50-y)) $((x-50)) $fg $cx $cy); x8=$1 y8=$2
eips '' # update display (removed from line function for speed)
done
done
}
# lipc-set-prop com.lab126.powerd preventScreenSaver 1
# killall -stop Xorg cvm # pause framework
eips -c
initvar # init global vars
rippleweave # 3d function plot
dd if=/dev/fb0 bs=1K count=512 of=/mnt/us/rippleweave.raw
# killall -cont cvm Xorg # resume framework
# lipc-set-prop com.lab126.powerd preventScreenSaver 0