View Single Post
Old 03-16-2012, 05:51 PM   #12
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773670
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Arrow rippleweave 1.0



rippleweave

Surprise! I have been busy lately. Here is a little gem I whipped up to keep this thread alive. I am actually quite surprised how little interest there seems to be in this stuff, considering how well eink displays work for algorithmic graphic art. How about some feedback so I do not feel so all alone here...

I find it rather interesting to watch the artwork while it is being created, which reveals the inside of the 3D shape as layers are drawn on the display. Like the midpoint circle algorithm used in the spoxbrane script, this script also "multitasks" by exploiting the 8-way symmetry of the "pseudo-mexhat" function being plotted.

Although the Taylor series sine function used here could be made a bit faster by limiting it to an O(5) series half-cycle instead of an O(7) series full-cycle, it would require mirroring the half-cycle (similar to the full-cycle looping now used, but with added reflection). I opted to keep the code as simple as possible by leaving out this potential speed optimization.

rippleweave 1.0a:
Spoiler:
PHP Code:
#!/bin/sh
######################################
# rippleweave - algorithmic art script
# version 1.0a           by geekmaster
# Copyright (C) 2012 geekmaster
# MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
######################################

#===========================
# initvar - init global vars
#---------------------------
initvar() {
  
DZ=/dev/zero 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)
}

#==================================
# line - Bresenham's line algorithm
# usage: line x0 y0 x y
#----------------------------------
line() {
  
local x0=$1 y0=$2 x=$3 y=$4local 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)); dd if=$DZ 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))
    
dd if=$DZ 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=$7local xg yg
  xg
=$((cx+x*6+(y*2))); yg=$(((cy-y*4+x*2)-z))
  [[ 
$x0 -ge 0 && $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=# 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=$2local 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 $MYline $MX $MY 0 $MYline 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 --f
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 

The "rippleweave" script (click "Show" in above Spoiler tag) takes less than 3 minutes to run to completion on my touch (booted from main).

It is completely safe (other than consuming your time while you watch it run). As you can see in the code above, it ONLY writes to /dev/fb0 (the eink framebuffer device).

This script disables screensaver mode using the method provided by thomass, but also pauses the framework to prevent framework status messages from polluting the artwork. The framework is resumed and screensaver mode reenabled after a completed screenshot image is saved to "rippleweave.raw" on the USB drive.

You can convert the raw screenshot image to an 800x600 8-bit grayscale PNG file with IrfanView for Windows, or the Gimp or other favorite app in linux.

Here is a full-size 800x600 (landscape mode) converted screenshot from this rippleweave script:
Spoiler:

Here are some reduced-size screenshots taken while the function was being plotted on the eink screen:




Feel free to modify this script to generate different "algorithmic art" pictures, and post those here too.

Enjoy!

Q1) What's "rippleweave"?
A1) Ripple Weave Socks: http://mimoknits.typepad.com/photos/...lue_socks.html

Q2) What function is plotted on those socks anyway?
A2) Umm... Good question!

Q3) What's a "mexhat" function?
A3) The most common "mexhat" function is the Ricker Wavelet, but rippleweave uses a variation of a simpler sinusoidal wavelet function (also sometimes called a mexhat function).

You can download rippleweave.gz (v1.0) below:
Attached Files
File Type: gz rippleweave.gz (1.6 KB, 559 views)

Last edited by geekmaster; 03-31-2012 at 12:26 PM. Reason: fix typos
geekmaster is offline   Reply With Quote