Javaに投稿されたコード一覧

Java シャネルのロゴ2

int DIAMETER = 70;
int STROKE_WIGHT = 12;
int Y = 100;

size(200, 200);

noFill();
smooth();
strokeWeight(STROKE_WIGHT);
strokeCap(SQUARE);

arc(120, Y, DIAMETER, DIAMETER, radians(30), radians(330));
arc(80, Y, DIAMETER, DIAMETER, radians(210), radians(360+150));

filter(BLUR, 6);

arc(120, Y, DIAMETER, DIAMETER, radians(30), radians(330));
arc(80, Y, DIAMETER, DIAMETER, radians(210), radians(360+150));

Java シャネルのロゴ

int DIAMETER = 70;
int STROKE_WIGHT = 12;
int Y = 100;

size(200,200);

noFill();
smooth();
strokeWeight(STROKE_WIGHT);
strokeCap(SQUARE);
arc(120,Y, DIAMETER, DIAMETER, radians(30),radians(330));
arc(80,Y, DIAMETER, DIAMETER, radians(210),radians(360+150));

Java 画象diff

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageDiff {

	// 入力ファイル
	public static final String INPUT1 = "data/input1.jpg";
	public static final String INPUT2 = "data/input2.jpg";

	// 出力ファイル
	public static final String OUTPUT = "data/output.jpg";

	// 操作用画象
	private static BufferedImage image1;
	private static BufferedImage image2;
	private static BufferedImage output;

	public static void main(String[] args) {
		loadImage();
		doProcess();
		saveImage();
	}

	/**
	 * 画象処理
	 */
	private static void doProcess() {
		int width = Math.max(image1.getWidth(), image2.getWidth());
		int height = Math.max(image1.getHeight(), image2.getHeight());
		output = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				int rgb1;
				if ((x <= image1.getWidth()) && (y <=image1.getHeight())) {
					rgb1 = image1.getRGB(x, y);
				} else {
					rgb1 = 0;
				}
				int rgb2;
				if ((x <= image2.getWidth()) && (y <=image2.getHeight())) {
					rgb2 = image2.getRGB(x, y);
				} else {
					rgb2 = 0;
				}
				int diff = rgb1 - rgb2;
				output.setRGB(x, y, diff);
			}
		}
	}

	/**
	 * 画像の読み込み
	 */
	private static void loadImage() {
		try {
			image1 = ImageIO.read(new File(INPUT1));
			image2 = ImageIO.read(new File(INPUT2));
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}

	}

	/**
	 * 画像書き込み
	 */
	private static void saveImage() {
		try {
			ImageIO.write(output, "jpg", new File(OUTPUT));
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}

Java クリップボード

import java.awt.datatransfer.*;
import java.awt.Toolkit;

void setup() {
  setClipboardString("abc");//クリップボードにテキストを設定
  println(getClipboardString());//クリップボードからテキストを取得
}

/**
 * クリップボードにテキストを設定します。
 * @param text 設定するテキスト
 */
void setClipboardString(String text) {
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  StringSelection stringSelection = new StringSelection(text);
  clipboard.setContents(stringSelection, stringSelection);
}

/**
 * クリップボードからテキストを取得します。
 * @return
 */
String getClipboardString() {
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  String str = "";
  try {
    str = (String)clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor);
  }
  catch(UnsupportedFlavorException e) {
    return null;//e.printStackTrace();
  }
  catch (IOException e) {
    return null;//e.printStackTrace();
  }
  return str;
}

Java キーイベントドリブン

void setup (){
  println("setup");
  noLoop();
}
void draw (){
  println("draw");
}
void keyPressed (){
  println("keyPressed");
  redraw();
}

Java 四則演算

public class Main {

	public static void main(String[] args) {
		Numeric a = new Numeric(1.0);
		Numeric b = new Numeric(2.0);
		Numeric c = new Numeric(6.0);
		Numeric d = new Numeric(3.0);
		Numeric e = new Numeric(2.0);

		Add add = new Add(a, b);
		Multi multi  = new Multi(add, c);
		Div div = new Div(multi, d);
		Sub sub = new Sub(div, e);

		Numeric result = (Numeric)sub.evaluation();
		System.out.println(result.getValue());
	}

}

Java ひと通りの演算子

/**
 * 加法演算子です。
 */
public class Add implements Node {

	private Node left;
	private Node right;

	public Add(Node left, Node right) {
		this.left = left;
		this.right = right;
	}

	@Override
	public Node evaluation() {
		left = left.evaluation();
		right = right.evaluation();

		double result = ((Numeric)left).getValue() + ((Numeric)right).getValue();
		return new Numeric(result);
	}

}

/**
 * 減算演算子です。
 */
public class Sub implements Node {

	private Node left;
	private Node right;

	public Sub(Node left, Node right) {
		this.left = left;
		this.right = right;
	}

	@Override
	public Node evaluation() {
		left = left.evaluation();
		right = right.evaluation();

		double result = ((Numeric)left).getValue() - ((Numeric)right).getValue();
		return new Numeric(result);
	}

}

/**
 * 乗算演算子です。
 */
public class Multi implements Node {

	private Node left;
	private Node right;

	public Multi(Node left, Node right) {
		this.left = left;
		this.right = right;
	}

	@Override
	public Node evaluation() {
		left = left.evaluation();
		right = right.evaluation();

		double result = ((Numeric)left).getValue() * ((Numeric)right).getValue();
		return new Numeric(result);
	}

}

/**
 * 除算演算子です。
 */
public class Div implements Node {

	private Node left;
	private Node right;

	public Div(Node left, Node right) {
		this.left = left;
		this.right = right;
	}

	@Override
	public Node evaluation() {
		left = left.evaluation();
		right = right.evaluation();

		double result = ((Numeric)left).getValue() / ((Numeric)right).getValue();
		return new Numeric(result);
	}

}

Java 加算演算子 改良

/**
 * 加算演算子です。
 */
public class Add implements Node {

	private Node left;
	private Node right;

	public Add(Node left, Node right) {
		this.left = left;
		this.right = right;
	}

	@Override
	public Node evaluation() {
		left = left.evaluation();
		right = right.evaluation();

		double result = ((Numeric)left).getValue() + ((Numeric)right).getValue();
		return new Numeric(result);
	}

}

Java 足し算できない

public class Main {

	public static void main(String[] args) {
		Numeric a = new Numeric(1.0);
		Numeric b = new Numeric(2.0);
		Numeric c = new Numeric(3.0);
		Add add1 = new Add(a, b);
		Add add2 = new Add(add1, c);  // ここでコンパイルエラー

		Numeric result = (Numeric)add1.evaluation();
		System.out.println(result.getValue());
	}

}

Java 足し算してみる その1

public class Main {

	public static void main(String[] args) {
		Numeric a = new Numeric(1.0);
		Numeric b = new Numeric(1.0);
		Add add = new Add(a, b);

		Numeric result = (Numeric)add.evaluation();
		System.out.println(result.getValue());
	}

}
Total Pages: 4 / 11« 先頭...2345610...最後 »

よく投稿されているコード

タグ

最近投稿されたコード