正月といえばフラクタルだそうですので、ちょうど現在パーフェクトJavaScriptで勉強していることもあり、JavaScriptとcanvasタグを使用しシェルピンスキーのギャスケットを描画してみました。
JavaScript、ほぼ初めて書いた…
ソースコードはこのページの下部に記載してありますよ。
change_patを書き換えていろいろな画像を出力しても面白いと思いますよ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$color = array( | |
'black' => 30, | |
'red' => 31, | |
'green' => 32, | |
'brown' => 33, | |
'blue' => 34, | |
'purple' => 35, | |
'cyan' => 36, | |
'grey' => 37, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expr $1 + 1 >/dev/null 2>&1 | |
if [ $? -ne 1 -a $? -ne 0 ]; then | |
echo "must be numeric" | |
exit | |
elif [ $1 -lt 0 ]; then | |
echo "must be more than 0" | |
exit | |
elif [ $1 -eq 1 -o $1 -eq 0 ]; then | |
echo 1; |
<?php
$a = array(0,1,2);
$a[5] = 5;
$a[4] = 4;
$a[3] = 3;
print_r($a);
foreach($a as $i=>$e){
echo "[" . $i . "]=". $e . " ";
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global require, console */ | |
/*↑上記のように記述しないと、「'require' was used before it was defined.」とか怒られる。さすがに阿呆らしい */ | |
var http = require('http'); | |
http.createServer(function (req, res) { | |
'use strict'; | |
/* ↑ これがないと「Missing 'use strict' statement.」。最近のブラウザってどれくらいstrictモードに対応しているんですか? */ | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
res.end('Hello World!'); | |
}).listen(1337); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WORK_DIR=$(dirname $0) | |
PULL_DIRS=$(ls $WORK_DIR) | |
for PULL_DIR in $PULL_DIRS | |
do | |
if [ -d $PULL_DIR ] | |
then | |
cd $PULL_DIR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ns = Array.new(99){|i| i+2} | |
result = Array.new(99){|i| i+2} | |
ns.each do |i| | |
result.map!{|h| h != '.' && h != i && h % i == 0 ? '.' : h } | |
p result | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 1 | |
b = 2 | |
(1..100).each do | |
puts a | |
c = a + b | |
a = b | |
b = c | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ns = Array.new(99){|i| i+2} | |
result = Array.new | |
while ns.length != 0 | |
prime = ns.shift | |
ns.delete_if{|x| x % prime == 0} | |
result.push prime | |
p ns | |
p result | |
puts |