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
| 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++) { |
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
| 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 |
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
| #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[]) { |
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
| #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"); |
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
| 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; | |
| } | |
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
| 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); |
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
| 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); | |
| } | |
| } |
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
| 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); |
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
| 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); |
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
| 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 |