SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-03-07 12:52:53

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

[solved] I am trying to make a random comic generator with conky

Screenshot_07_03_2015_12_50_14.jpg
Green frame = 4 small pictures in a row. Orange frame = place for text.

The concept:
To have 4 pictures (240x140) in a row randomly picked and displayed by conky with every start.
What I have so far:
~/comic/char/ directory with transparent .png files with characters and other stuff all of them 240x140. I have 4 characters there. Every character has is own name format: a1.png, a2.png... b1.png, b2.png,... c1.png, c2.png..., d1.png, d2.png...
~/comic/*.txt files for every character with a prepared code for conkycomic.rc of all their .png files. So for example for the b character i have a file b.txt which looks like this:

${image /fullpath/comic/char/b1.png -p 0,0 -s 240x140}
${image /fullpath/comic/char/b2.png -p 0,0 -s 240x140}
${image /fullpath/comic/char/b3.png -p 0,0 -s 240x140}

~/comic/conkycomic.rc

As I can't to code I took a long way around to the goal:
1. Pick one random line (path) from every ~/comic/*.txt file and put all 4 of them in /comic/another_file.txt
2. Take the content of another_file.txt and put in random order in conkycomic.rc after TEXT.

Now comes my problems. The code after TEXT needs to be in the same line. And whatever I do it always makes one per line, so the pictures are dispalyed in a column. Next, what I haven't approached yet, is the -p 0,0 part for every file. As the pictures are supposed to be in a single line, I have to use padding for every one of them like so: -p 0,0 foe the first picture, -p 240,0 for the second one, -p 480,0 for the third one and -p 720,0 for the last one. Otherwise they will be in the same spot and look like a single picture. I have no idea how do do it smile

My first idea was to add random lines above the pictures (in the place where the orange frame is) also as random lines from txt files. But I decided not to add the lines. Some ~/comic/char/*.png files won't contain characters but buildings or plants instead to make comics more interesting or to avoid having all the characters in every comic every time. And I have no idea how to exclude a line if there is no living character under it.

Eventually I decided to write here and ask for help. I know it can be done in more efficient way, with no using any temporary another-file.txts and all.

Last but not least. The characters are not mine. I borrowed them from a blog to decorate my desktop. They can be found here http://okropnepotwory.blogspot.com/ Sorry it is in Polish so you can't really enjoy it sad

And I was thinking. Such a comic could be a nice addition for BunsenLabs to display hints of the day or quotes from the forums. Even a weather forecast. Someone would have to design cute little characters and release them uder proper license.


edit: I took a break and an idea came. I can merge the 4 random pictures into a single one and then put it in conky. I'll take a look at it later though.

Last edited by Zoidberg (2015-03-08 13:08:50)

Offline

Be excellent to each other!

#2 2015-03-07 15:17:37

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

Lining the images up is easy
1. Above TEXT use these lines

minimum_size 940 140  # w|h
maximum_width 940

border_inner_margin 0
border_outer_margin 0
TEXT

below TEXT use this (with your /path_to/image.png):

TEXT
${image /media/5/Conky/images/red+x.png -p 0,0 -s 240x140}\
${image /media/5/Conky/images/blue+x.png -p 240,0 -s 240x140}\
${image /media/5/Conky/images/yellow+x.png -p 480,0 -s 240x140}\
${image /media/5/Conky/images/green+x.png -p 720,0 -s 240x140}

cartoon_conky.jpg

The \ at the end of a line tells the next line to continue "the display" on the same line.
Images are different they "always" display at "-p 0,0" (upper-left corner) unless you position them.

cartoon_conky2.jpg
Here's some test being displayed.

NOTE: -p uses a comma and -s uses an "x"

More to come ... need to test.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#3 2015-03-07 15:41:26

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

The borders in the screenshot were added with GIMP for help better to describe the idea.
The "-p 0,0" is a nightmare for me. I will have to use sed for it (more to learn). And I have to look up everything in Google. With trials and errors I make tiny steps forward.

I installed imagemagic. It has useful tools as convert or pnmcat, pnmtopng and pngtopnm, and probably many more. I wasn't able to make a working oneliner yet (like for example: ls | shuf | convert to get merged.png ready to be inserted in conky).

Offline

#4 2015-03-07 15:57:46

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

Borders can be added right in conky:

###  Borders Section  ########################################################
draw_borders yes
# Stippled borders?
#stippled_borders 5
# border margins
border_inner_margin 0
border_outer_margin 0
# border width
border_width 2
# graph borders
draw_graph_borders yes #no
#default_graph_size 15 40
#####################################################  End Borders Secton  ###

·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5 2015-03-07 16:13:39

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

Zoidberg wrote:

And I was thinking. Such a comic could be a nice addition for BunsenLabs to display hints of the day or quotes from the forums. Even a weather forecast. Someone would have to design cute little characters and release them uder proper license.

Foe weather we have a few scripts options already.  See "Our Conkys"  in my signature #'s 2,3,4,5,6,8 and11, and I do believe there is a quote of the day conky here some place.

But I like your thinking!  cool


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#6 2015-03-07 16:35:45

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

Zoidberg wrote:

The "-p 0,0" is a nightmare for me.

"- p 0,0" is not a lot different than:

gap_x 
gap_y

-p 0,0 is the upper/left corner of the conky window.  Think of it this way "-p H,V"
H = Horizontal  V = Vertical (H = pozioma V = pionowa)

So "-p 240,0" moves the image 240 pixels to the right and "-p -5,0" moves the image to the left 5 pixels - sometimes needed if there is a blank transparent space around the image you want to eliminate

And  "-p 0,140" would move the image 140 pixels down the left edge of the conky window,

A real example I have is this:

${image /media/5/Conky/images/BunsenLabs_Light.png -p 55,37 -s 100x100}

The image is moved 55 pixels to the right of the left edge and  down 37 pixels from the top.
2015_03_07_13_32_19_222x196_Sector11.jpg


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#7 2015-03-07 16:43:12

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

I don't need borders in conky. I know I can add them. When I have a ready simple script or config file I can modify it to my needs. Mut making something from scratch is beyond my abilities.

Now I have a simple code to make a horizontal comic strip

convert file1 file2 file3 file4 +append output.png

Now you can imagine how noobish in bash I am as I can't figure out how to make a simple

cd ~/comic/char && ls | shuf -n 4 something-something output.png

LOL

edit:
Yes, I know how p 0,0 works. Bot how to replace second 0,0 with 240,0, third 0,0 with 480,0 etc.?

Last edited by Zoidberg (2015-03-07 16:46:07)

Offline

#8 2015-03-07 16:46:18

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

OK, doing true random picks I can't help you with, that would require a script of some type and that is beyond my know-how.  But you can get different images showing at different times using ${if_match}, here I using it with the "time minute" command.

Example: four sets:  a1,2,3 & 4,  b1,2,3 & 4,  c1,2,3 & 4,  d1,2,3 & 4, (I don't have those, but I do have colours to test with)

TEXT
 Minutes  ${time %M}
${if_match ${time %M}<15}${image /media/5/Conky/images/red+x.png -p 0,0 -s 240x140}\
${image /media/5/Conky/images/blue+x.png -p 240,0 -s 240x140}\
${image /media/5/Conky/images/yellow+x.png -p 480,0 -s 240x140}\
${image /media/5/Conky/images/green+x.png -p 720,0 -s 240x140}\
${else}${if_match ${time %M}<30}${image /media/5/Conky/images/green+x.png -p 0,0 -s 240x140}\
${image /media/5/Conky/images/red+x.png -p 240,0 -s 240x140}\
${image /media/5/Conky/images/yellow+x.png -p 480,0 -s 240x140}\
${image /media/5/Conky/images/blue+x.png -p 720,0 -s 240x140}\
${else}${if_match ${time %M}<45}${image /media/5/Conky/images/green+x.png -p 0,0 -s 240x140}\
${image /media/5/Conky/images/red+x.png -p 240,0 -s 240x140}\
${image /media/5/Conky/images/blue+x.png -p 480,0 -s 240x140}\
${image /media/5/Conky/images/yellow+x.png -p 720,0 -s 240x140}\
${else}${image /media/5/Conky/images/yellow+x.png -p 0,0 -s 240x140}\
${image /media/5/Conky/images/red+x.png -p 240,0 -s 240x140}\
${image /media/5/Conky/images/blue+x.png -p 480,0 -s 240x140}\
${image /media/5/Conky/images/green+x.png -p 720,0 -s 240x140}\
${endif}${endif}${endif}

And it ran long enough to get a full cycle:
2015_03_07_12_44_21_1920x1080_Sector11.jpg


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#9 2015-03-07 17:31:53

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

Zoidberg wrote:

I don't need borders in conky. I know I can add them. When I have a ready simple script or config file I can modify it to my needs. Mut making something from scratch is beyond my abilities.

Now I have a simple code to make a horizontal comic strip

convert file1 file2 file3 file4 +append output.png

Now you can imagine how noobish in bash I am as I can't figure out how to make a simple

cd ~/comic/char && ls | shuf -n 4 something-something output.png

LOL

edit:
Yes, I know how p 0,0 works. Bot how to replace second 0,0 with 240,0, third 0,0 with 480,0 etc.?

Sorry, I saw this:

I have to use padding for every one of them like so: -p 0,0 foe the first picture, -p 240,0 for the second one, -p 480,0 for the third one and -p 720,0 for the last one. Otherwise they will be in the same spot and look like a single picture. I have no idea how do do it

and this:

The "-p 0,0" is a nightmare for me.

and though the wrong thing.  Sorry.

Why replace them?  Now you lost me again
Why not leave them as four separate images?  smile

${image /media/5/Conky/images/a1.png -p 0,0 -s 240x140}\
${image /media/5/Conky/images/a2.png -p 240,0 -s 240x140}\
${image /media/5/Conky/images/a3.png -p 480,0 -s 240x140}\
${image /media/5/Conky/images/a4.png -p 720,0 -s 240x140}\

Yea, I'm lost with bash for the most part as well.

What is the idea of this:

ls | shuf -n 4 [i]something-something output.png[/i]

it is the something-something output.png I'm lost with.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#10 2015-03-07 17:52:03

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

About replacing -p 0,0
I use shuf -n 4 to take 4 random lines from a text file containing linest like this one

${image /media/5/Conky/images/a1.png -p 0,0 -s 240x140}

All of them have -p 0,0. And I put them in conkyrc. This way all 4 images would occupy the same spot. I need to replace the values of images 2, 3 and 4 with correct padding. For programmers it is trivial. For me it is not.
That is why I am trying to find a simpler way. I am trying use convert. First pick up 4 random images and convert them into a single image (convert 1.png 2.png 3.png 4.png +append output.png) to put in conkyrc. But I also want to avoid copying the 4 random images, as it is unnecessary job.
I can pick 4 random images streaming output from ls command

ls | shuf -n 4

But I have no idea how (hocus-pocus something-something) to stream the data further to convert command to get the single image.

It would be much better to do it without converting images. It is much more data than a single (but horribly complex) script.

Edit:
Big step forward big_smile So far I got this:

#!/bin/bash
cd /home/user/comic/char
rm tmp/*
cp conkytemplate ../conkycomic
ls *.png | shuf -n 4 >> tmp/med.txt
cp `cat tmp/med.txt` tmp/
convert `ls tmp/*.png` +append tmp/out.png
fi

med.txt is a mediator file to keep the random output from shuf. conkytemplate is a template, easier for me to copy than to remove all after TEXT in conkycomic config file.
Next step is to paste the out.png file in conkycomic and run it.

Please, don't laugh from my meager coding skills.

--
edit:
I managed to make it! big_smile:D:D
Not the most optimal maybe, but it works. The script picks 4 random pictures (from separate folders) and glues them together in random order to make a comic strip to be displayed with conky. No random dialogues yet (and probably won't be).
Tomorrow I'll post it here with more explanations.
Sector11, thanks for your support!

Last edited by Zoidberg (2015-03-07 22:47:40)

Offline

#11 2015-03-07 23:11:36

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

1.  I would never laugh at someone trying to do something I can't do.
     ... been there done that and asked a million questions to prove it.   smile
2. Your "meagre coding skills" are superior to mine.  wink

Looking forward to tomorrow.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#12 2015-03-08 13:05:37

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

As I promised. The Random Comic Strip Generator
Here is the download: https://dl.dropboxusercontent.com/u/602 … mic.tar.gz
Unpack the folder to your home directory. To work it needs imagemagick installed. Then just run startcomic.sh

This is the script that does the job:

#!/bin/bash
cd ~/comic/char
rm tmp/*
ls _a/ | shuf -n 1 >> tmp/med.txt
ls _b/ | shuf -n 1 >> tmp/med.txt
ls _c/ | shuf -n 1 >> tmp/med.txt
ls _random/ | shuf -n 1 >> tmp/med.txt
sed -i -e 's/^/_*\//' tmp/med.txt
cat tmp/med.txt | shuf -n 4 >> tmp/med2.txt
convert `cat tmp/med2.txt` +append tmp/out.png 
sleep 3
conky2 -q -c ~/comic/conkycomic.rc
fi

conky2 is only a symlink. Everything about it is included in README.txt

Here is a couple of mock-ups of my Xubuntu desktop. The colored backgrounds will be added as changing wallpapers eventually.
Screenshot_08_03_2015_13_23_57.jpg
Screenshot_08_03_2015_13_21_44.jpg

And here how the actual comic looks like (on my Crunchbang desktop). As I have no rights to the  vikings characters, I had to make my own doodles to include in the package.
http://imgur.com/a/or8R9

Th comic has no dialogues. I may try to add them, but probably won't publish the code.

Edit: For those who already downloaded:
Edit conkycomic.rc find line 24

#update_interval 2

and change it to

update_interval 600

The commented line was causing to many updates and cpu usage. I already fixed it in the package.

Last edited by Zoidberg (2015-03-08 13:32:50)

Offline

#13 2015-03-08 14:50:58

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,643

Re: [solved] I am trying to make a random comic generator with conky

This looks great, about bash;
http://mywiki.wooledge.org/ParsingLs < don't use ls in your scripts,
you can do things like : "cd ~/comic/char && rm tmp/*",  < 2nd command will run only if the 1st one was ok
you have a "fi" without opening "if" and so on.
http://www.shellcheck.net/ < quite useful shell script checker
edit: Also people on freenode/#bash are just great.

Last edited by brontosaurusrex (2015-03-08 15:46:22)

Offline

#14 2015-03-08 16:43:11

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

Thanks for the links, brontosaurusrex.
This is the most complex script I ever made. Took me ages. I was trying various things as a blind man. I know the code is far from ideal. I tried using cmd < and some other stuff, but the syntax is so confusing (all that tiny bits like:  ' " . [ } $ < ). I have no experience at all. The only time I was taught how to use command line was at school about 1994, and it was DOS.
I used _ in folder names to avoid sorting. ls seemed to be a good idea however I quickly found it has its limtations. The sed part was from Google as well as convert, `cat foo` and other things that didn't make it to the final version.

I have no skills to write the script properly. As far as the current one doesn't do any damage, I am happy ^^ It does what I want it to do.

Last edited by Zoidberg (2015-03-08 16:43:46)

Offline

#15 2015-03-08 17:28:25

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

NICE.  once heck of a learning experience too.  I must play with it.  big_smile


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#16 2015-03-08 18:26:11

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: [solved] I am trying to make a random comic generator with conky

Very nice - I like it.  See it here

BTW I did some tweaking.  Top line in conkycomic.rc:

# pkill -xf "conky -c $HOME/comic/conkycomic.rc" &

last 3 lines in startcomic.sh

sleep 3
conky -c $HOME/comic/conkycomic.rc
fi

No need for a sym-link:

pkill -xf "conky -c $HOME/comic/conkycomic.rc" &

will kill the comic conky leaving all other conkys running.  wink


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#17 2015-03-08 18:45:47

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [solved] I am trying to make a random comic generator with conky

If there's no "if", why is there a final "fi"? tongue


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#18 2015-03-08 19:59:09

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

Duh!  big_smile  I updated the package. Changed fi to done and updated conky config with:

update_interval 5
imlib_cache_flush_interval 900

Offline

#19 2015-03-09 12:54:58

Zoidberg
Member
Registered: 2015-02-05
Posts: 32

Re: [solved] I am trying to make a random comic generator with conky

I gave it another try. This time with find. But I couldn't to figure out what I was doing wrong. So I searched Google yet again and found a piece of code that did almost exactly what I needed!
Here is the result:

#!/bin/bash
cd ~/comic/char
for dir in ./*/; do
    find "$dir" -maxdepth 1 -type f -iname "*.png" | shuf -n1
done > tmp/med.txt
cat tmp/med.txt | shuf -n 4 > tmp/med2.txt
convert `cat tmp/med2.txt` +append out.png && conky2 -c ~/comic/conkycomic.rc &

I also got rid of the rm line as > overwrites existing files, and removed the sleep part by using && instead, so it works faster now.
To use the code with the comic you need to do 3 things:
1. Replace everything in startcomic.sh with the code above
2. Delete ~/comic/char/tmp/out.png
3. Edit conkycomic.rc and change:

TEXT
${image ~/comic/char/tmp/out.png -p 0,0 -s 960x140}

to

TEXT
${image ~/comic/char/out.png -p 0,0 -s 960x140}

Or just download version 2 https://dl.dropboxusercontent.com/u/602 … ic2.tar.gz where all the changes have been made for you.

Last edited by Zoidberg (2015-03-09 13:59:16)

Offline

#20 2015-03-09 19:01:21

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: [solved] I am trying to make a random comic generator with conky

Zoidberg wrote:
cat tmp/med.txt | shuf -n 4 > tmp/med2.txt

The `shuf` command works on files so you can leave that poor cat alone:

shuf -n4 tmp/med.txt > tmp/med2.txt

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo