Skip to content

Instantly share code, notes, and snippets.

@dribnet
Forked from FaultedStar/.block
Last active June 7, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dribnet/3fa11e9afe4c8fee721cb2df36d7d88a to your computer and use it in GitHub Desktop.
Save dribnet/3fa11e9afe4c8fee721cb2df36d7d88a to your computer and use it in GitHub Desktop.
vibrator smartgrid (novelty filter)
license: mit
downloads
resized
colorgrid
smartgrid
customgrid
// note: this file is poorly named - it can generally be ignored.
// helper functions below for supporting blocks/purview
function saveBlocksImages(doZoom) {
if(doZoom == null) {
doZoom = false;
}
// generate 960x500 preview.jpg of entire canvas
// TODO: should this be recycled?
var offscreenCanvas = document.createElement('canvas');
offscreenCanvas.width = 960;
offscreenCanvas.height = 500;
var context = offscreenCanvas.getContext('2d');
// background is flat white
context.fillStyle="#FFFFFF";
context.fillRect(0, 0, 960, 500);
context.drawImage(this.canvas, 0, 0, 960, 500);
// save to browser
var downloadMime = 'image/octet-stream';
var imageData = offscreenCanvas.toDataURL('image/jpeg');
imageData = imageData.replace('image/jpeg', downloadMime);
p5.prototype.downloadFile(imageData, 'preview.jpg', 'jpg');
// generate 230x120 thumbnail.png centered on mouse
offscreenCanvas.width = 230;
offscreenCanvas.height = 120;
// background is flat white
context = offscreenCanvas.getContext('2d');
context.fillStyle="#FFFFFF";
context.fillRect(0, 0, 230, 120);
if(doZoom) {
// pixelDensity does the right thing on retina displays
var pd = this._pixelDensity;
var sx = pd * mouseX - pd * 230/2;
var sy = pd * mouseY - pd * 120/2;
var sw = pd * 230;
var sh = pd * 120;
// bounds checking - just displace if necessary
if (sx < 0) {
sx = 0;
}
if (sx > this.canvas.width - sw) {
sx = this.canvas.width - sw;
}
if (sy < 0) {
sy = 0;
}
if (sy > this.canvas.height - sh) {
sy = this.canvas.height - sh;
}
// save to browser
context.drawImage(this.canvas, sx, sy, sw, sh, 0, 0, 230, 120);
}
else {
// now scaledown
var full_width = this.canvas.width;
var full_height = this.canvas.height;
context.drawImage(this.canvas, 0, 0, full_width, full_height, 0, 0, 230, 120);
}
imageData = offscreenCanvas.toDataURL('image/png');
imageData = imageData.replace('image/png', downloadMime);
p5.prototype.downloadFile(imageData, 'thumbnail.png', 'png');
}

Vibrators

Vibrators smartgrid

A quick reshuffle of Sabrina Verhage‏'s Vibrators dataset as an experiment in increasing novelty by removing redundant elements. In this version 165 of the 1371 entries were removed as being too similar to their nearest neighbors.

#!/bin/bash
# show commands and stop if there is an error
set -ex
# make the directory if it is not there
mkdir -p downloads
# clean the directory if there are old results
rm -f downloads/*
# get 5 pages
for PAGE in {1..3}
do
# this is an example with a group
URL='https://www.flickr.com/groups/hdr/pool/page'$PAGE
# this is an example with tags
# URL='https://www.flickr.com/photos/tags/'$SEARCH_STRING'/page'$PAGE
echo "about to fetch URL: " $URL
sleep 3
# fetch the images
wget --adjust-extension \
--random-wait \
--limit-rate=100k \
--span-hosts \
--convert-links \
--backup-converted \
--no-directories \
--timestamping \
--page-requisites \
--directory-prefix=downloads \
--execute robots=off \
--accept=.jpg \
$URL
# other unused arguments
# --recursive \
# --level 1 \
# --domains en.wikipedia.org \
done
#!/bin/bash
if [ ! -d "/usr/local/anaconda/extras" ]; then
# Control will enter here if DIRECTORY doesn't exist.
echo "smartgrid program not found"
echo "please first install using directions on blackboard"
exit 1
fi
# show commands and stop if there is an error
set -ex
HOME="/usr/local/anaconda/extras/home"
export PATH="/usr/local/anaconda/bin:$PATH"
python /usr/local/anaconda/extras/smartgrid.py \
--tile 12x6 \
--input-glob 'resized/*' \
--left-image 'resized/29516311783_87657c243a.jpg' \
--right-image 'resized/33488098312_91556220b5_z.jpg' \
--output-path customgrid
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment