Skip to content

Instantly share code, notes, and snippets.

View sasaki-shigeo's full-sized avatar

SASAKI Shigeo sasaki-shigeo

View GitHub Profile
@sasaki-shigeo
sasaki-shigeo / SelectionSort.java
Created October 18, 2017 10:32
Selection Sort Program in Java
public class SelectionSort {
static int[] data = { 5, 3, 8, 2, 9, 4, 1 };
public static void main(String[] args) {
selection_sort(data);
System.out.println(java.util.Arrays.toString(data));
}
static void selection_sort(int[] data) {
for (int k = 1; k < data.length; k++) {
data = [2, 9, 4, 8, 5, 6, 1]
def selection_sort(data, comp):
for k in range(1, len(data)):
for i in range(0, k):
if comp(data[i], data[k]) > 0:
temp = data[i]
data[i] = data[k]
data[k] = temp
@sasaki-shigeo
sasaki-shigeo / sel_sort.c
Last active October 25, 2017 03:40
Selection sort program in C
#include <stdlib.h>
#include <stdio.h>
typedef int T;
T data[] = { 2, 9, 4, 8, 5, 6, 1 };
const int N = sizeof(data)/sizeof(T);
void ssort(int (* comp)(int, int), int a[]) {
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *fp;
if (argc < 2) {
fp = stdin;
}
else {
fp = fopen(argv[1], "r");
color trunkcolor = #663300;
color leafcolor = #00AA00;
class Crystal {
float x, y, phi;
Crystal(float x0, float y0, float phi0) {
x = x0; y = y0; phi = phi0;
}
@sasaki-shigeo
sasaki-shigeo / SkyAndCloud.pde
Last active December 15, 2019 22:51
A demonstration of the Perlin noise: the sky and cloud. / パーリンノイズのデモ:空と雲
void setup() {
size(500, 500);
colorMode(HSB, 360, 1.0, 1.0);
}
void draw() {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
stroke(210, noise(i / 60.0, j / 60.0, frameCount / 60.0), 1.0);
point(i, j);
@sasaki-shigeo
sasaki-shigeo / rainbow-and-sky.pde
Last active January 16, 2022 17:33
A sample code in Processing: a (translucent) rainbow in the sky / Processing で Perlin noise を使った雲と半透明な虹
size(800, 400);
colorMode(HSB, 360.0, 1.0, 1.0, 1.0);
// The sky by the perlin noise
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
stroke(210, noise(0.005 * i, 0.005 * j), 1.0);
point(i, j);
}
}
@sasaki-shigeo
sasaki-shigeo / DigitalClock.pde
Created January 6, 2019 08:01
Digital Clock in Processing / デジタル時計
void setup() {
size(500, 100);
PFont font = createFont("Monospaced", 90);
textFont(font);
}
void draw() {
background(#AAAAAA);
fill(#000000);
text(String.format("%2d:%02d:%02d", hour(), minute(), second()), 40, 80);
@sasaki-shigeo
sasaki-shigeo / FontSample.pde
Created January 6, 2019 08:04
Display Processing Font Sample / フォントの表示
size(500, 300);
PFont serif = createFont("Serif", 43);
PFont sansserif = createFont("SansSerif", 43);
PFont monospaced = createFont("Monospaced", 43);
fill(#000000); noFill();
stroke(#ff0000);
textFont(serif); text("Serif", 50, 80);
textFont(sansserif); text("SansSerif", 50, 180);
textFont(monospaced); text("Uniformed Width", 50, 280);
@sasaki-shigeo
sasaki-shigeo / ValueOfColor.pde
Last active January 6, 2019 08:10
The color type in Processing is exactly binary integer.
color transparent = color(0, 0, 0, 0);
color opaque = color(0, 0, 0, 255);
println(transparent); // 0
println(opaque); // 0xff000000
println(#000000 - opaque); // 0
println(#0000ff - opaque); // 0xff
println(#ffffff - opaque); // 0xffffff