![]() |
#16 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
![]() 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. ![]() P.S. I still have an APL option ROM for my old Centronix printer. Of course, PRINTING an APL program was generally a waste of time, because APL was considered (even by those who used it) to be a "write-only" language. ![]() EDIT: I *do* use in-line comments in places where it aids readability. Also, I reverted to "-a" and "-o" for compound conditionals in rippleweave 1.0a in its first post (but not the .gz file yet), for K3 compatibility. ![]() EDIT 2: Because this reply wrapped to a new page in this thread, I wish to mention that we are discussing the "rippleweave" script that generates 3D function plot images like this: P.S. Thanks PoP for the animated GIF shown above (and on the first post)! ![]() ![]() Last edited by geekmaster; 03-19-2012 at 02:44 PM. |
|
![]() |
![]() |
![]() |
#17 |
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Feb 2012
Device: Kindle Touch
|
I tried this out and it looked really neat, thanks for posting it :3
|
![]() |
![]() |
![]() |
#18 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
When I get back, I hope to see the following games running in #!/bin/sh using scripts from this thread as a guide:
Spoiler:
![]() Last edited by geekmaster; 03-20-2012 at 10:55 PM. Reason: severe typophrenia |
![]() |
![]() |
![]() |
#19 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
|
a simple 3d modeling tool for the kindle?
|
![]() |
![]() |
![]() |
#20 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
The whole point is to show that you can do a lot more than people think with whatever tools you have available.
You are only limited by your imagination. Shell scripts are used in kindle debricking and jailbreaks (RUNME.sh), and for beginners who may not know what to type at a command line, shell scripts can provide a GUI. Shell scripts do not need a native compiler, or a cross compiler. Although we could have used lua or awk, those are not installed on many embedded devices, but they all have /bin/sh. And despite multiple claims on the net that you cannot process binary files with sh, you can see from my scripts that you can. I read binary event data in touchpaint, and I output binary data to the framebuffer in the other scripts. An additional thing is that I show how to do math functions using shell scripts. Of course, these programs can be translated to C for more speed, but /bin/sh makes a fine "language" for quick prototyping. |
![]() |
![]() |
![]() |
#21 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
|
you know, kt comes with /bin/bash built-in
|
![]() |
![]() |
![]() |
#22 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
As I understand this implementation of busybox, bash is just a synonym for sh, so scripts can include either shell on the shebang line without failure.
Now, the reason I chose to do this in shell script is BECAUSE it is the WORST POSSIBLE tool for the job, but also has UNIVERSAL availability on ALL busybox distros. Things like awk and lua are not in all distros, but sh is (and even bash is not always there). I did this to show that anything is possible and you do not need to be limited by your tools if you master them. So this will work on a bricked kindle as long as you have ssh from main or diags (on the k4 they have different busybox versions with different built-in commands). Now that I have shown that you can do anything you want with /bin/sh (but with a speed penalty), I plan to add a few finishing touches (touchscreen button support and onscreen keyboards for k4 and touch), then move to the other extreme of C with optimized assembler code for the inner loops (graphics blitting and custom decompression). But when I have time. I have many things demanding my time in big ways right now... Anyway, even with the worst of tools, you can do useful and interesting things, if you set your mind to it. Computers are so fast compared to what I grew up with, that even crude and slow tools such as /bin/sh are MUCH faster than hand-crafted assembler language was back in the day. The limiting factor on graphics is that eips does full screen updates (which are just as slow called from C with ioctl() as they are here). The way to speed up graphics is to do partial screen updates. I am not sure how to do that with eips (if even possible). ![]() Last edited by geekmaster; 03-20-2012 at 03:59 PM. |
![]() |
![]() |
![]() |
#23 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17
Karma: 2600
Join Date: Mar 2012
Device: Kindle 3
|
Pixel based, kindle 3 game of life.
Spoiler:
(Hope I haven't violated to many of your style constrains.) Last edited by kaminkatze; 03-20-2012 at 04:55 PM. |
![]() |
![]() |
![]() |
#24 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
I especially like how you are caching the framebuffer on ramdisk. I considered storing random access data in a file on /tmp to use as a large array. Shell arrays do not seem to work in my busybox version, so I was planning to fake it with "dd". ![]() Some minor tips: 1) Inside $(( )) expressions, vars do not need $ except when numeric parms $1 $2, etc. You can see in my examples. I see that you left the $ off in some cases, but kept it in others. 2) I originally had a setpixel function, but testing showed that it was quite a bit faster on my 5.0.0 firmware to put the "dd" inline, and wrapping a single line dd call in a function actually consumes more screen space. But it *does* make it more readable though, and in your case it allows you to pipe it to other commands, so it may well be worth the speed trade-off here if simple to understand code is the goal (which is what I aim for in tutorials like this thread). 3) I do not know if you noticed, but when you have multiple inline variable assignments (with no ';'), you cannot use a value earlier in the same line. This is why I sometimes do "; local " in the middle of a line. The "local" statements prevent a function from changing values that belong to its parent. This does not seem to do anything other than clear the screen on my K3 with firmware 3.3, and I do not have time to study your code in any detail right now. Are there any special requirements to run this? P.S. "Hope I don't have" should be "Hope I haven't", and I bumped your karma to 2600 for the great hack. ![]() Last edited by geekmaster; 03-20-2012 at 07:22 PM. |
|
![]() |
![]() |
![]() |
#25 | |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17
Karma: 2600
Join Date: Mar 2012
Device: Kindle 3
|
Quote:
You should see the glider in the top left corner. At the moment only a 8x8 pixel field is updated. Change the last line to "loop 100" so it runs more iterations. |
|
![]() |
![]() |
![]() |
#26 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
![]() I was planning to try a different approach when I get around to supporting the K3. There are two options. The easiest is to ASSUME that the kindle has 300 byte-wide pixels per line, with values "dd if=$DZ of=$DF ..." or "echo -e '\xff'|dd of=$DF ...". Another option I thought of was to use a 600-byte wide /tmp/buffer (to hold a scan line for both touch/k4 8-bit pixels or the k3/dx 4-bit pixels) and then for the k3/dx draw 4 different pixel pair bytes to the framebuffer based on the values (\x00 \xf0 \x0f \xff). Either of my methods should be faster than yours. Also, updating the screen too fast will make the eink drivers not even bother to update the display, which could need a "usleep 80000" call added after the eips '' call. ![]() Last edited by geekmaster; 03-20-2012 at 08:09 PM. Reason: severe typophrenia http://justinharder.la/stills/item/typophrenia/ |
|
![]() |
![]() |
![]() |
#27 | |
curly᷂͓̫̙᷊̥̮̾ͯͤͭͬͦͨ ʎʌɹnɔ
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,016
Karma: 50506927
Join Date: Dec 2010
Location: ♁ ᴺ₄₅°₃₀' ᵂ₇₃°₃₇' ±₆₀"
Device: K3₃.₄.₃ PW3&4₅.₁₃.₃
|
Quote:
![]() 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 |
|
![]() |
![]() |
![]() |
#28 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
![]() ![]() tangle ![]() Here is a little "something" for the K3 I whipped up, inspired by the K3 graphical exploits of PoP and kaminkatze: ...tangle: Spoiler:
....FAQ: Spoiler:
![]() Last edited by geekmaster; 03-21-2012 at 02:41 PM. Reason: severe typophrenia |
![]() |
![]() |
![]() |
#29 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
|
![]() |
![]() |
![]() |
#30 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Scripting with epub-meta | averyml | Calibre | 20 | 11-17-2016 10:13 AM |
Bunny + Scripting + Calibre = here | tBunnyMan | Introduce Yourself | 4 | 02-06-2012 12:16 AM |
Possible scripting engine for Sigil | Valloric | Sigil | 48 | 10-17-2009 09:58 AM |
Any NetNewsWire Scripting Pros out there? | adinb | Sony Reader | 0 | 02-25-2007 01:44 AM |