Created
February 19, 2014 18:59
-
-
Save gunungloli666/9099103 to your computer and use it in GitHub Desktop.
This file contains 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
package fjr.image; | |
import java.io.File; | |
import javafx.application.Application; | |
import javafx.scene.Group; | |
import javafx.scene.Scene; | |
import javafx.scene.canvas.Canvas; | |
import javafx.scene.canvas.GraphicsContext; | |
import javafx.scene.image.Image; | |
import javafx.scene.image.PixelReader; | |
import javafx.scene.paint.Color; | |
import javafx.scene.text.Font; | |
import javafx.stage.Stage; | |
public class TestHuruf extends Application { | |
int step = 7; | |
int stepY = 7; | |
double depth = 56; | |
double width = 0; | |
double height = 0; | |
double canvasWidth = 800; | |
double canvasHeight = 600; | |
static int[] value = { 0, 1 }; | |
String[] m = {"M", "O", "H", "A", "M", "M", "A", "D","", "F", "A", "J", "A", "R", ""}; | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
Group root = getEsembel(); | |
primaryStage.setScene(new Scene(root)); | |
primaryStage.setTitle("TUT WURI HANDAYANI"); | |
primaryStage.show(); | |
} | |
public Group getEsembel() { | |
Group root = new Group(); | |
Image image = new Image(new File("E:/testpoi/bob-sepia.jpg").toURI() | |
.toString()); | |
width = image.getWidth(); | |
height = image.getHeight(); | |
PixelReader pixel = image.getPixelReader(); | |
Canvas canvas = new Canvas(canvasWidth, canvasHeight); | |
GraphicsContext gc = canvas.getGraphicsContext2D(); | |
gc.setStroke(Color.BLACK); | |
double x = 10, y = 0; | |
double stepXImage = width/ 130; | |
double stepYImage = height /72; | |
int xx =0; | |
int yy = 0; | |
canvas.setStyle("-fx-foreground-color: #333333;"); // ini g bisa... | |
gc.setFont(new Font(8)); | |
int indexString = 0; | |
while(x < canvasHeight - 20){ // ini nanti ada 72 loop | |
xx = 0 ; | |
indexString = 0; | |
while(y < canvasWidth - 20){ // ini nanti ada 130 loop | |
if(indexString>=m.length) | |
indexString = 0; | |
Color color = pixel.getColor(xx, yy); // ambil nilai warna dari image... | |
gc.setStroke(color); // setting warna huruf berdasarkan nilai warna image... | |
gc.strokeText( m[indexString++], y , x); // pasang huruf ke indexString pada koordinat y dan x | |
int aa = (int)(Math.random() * value.length ); | |
// gc.strokeText( Integer.toString(value[aa]), y , x); | |
// gc.strokeText( "M", y , x); | |
y+=6 ; // ini buat step text-nya... arah horizontal... | |
xx += ((int) stepXImage); // ini buat step byte image-nya arah horizontal | |
} | |
y = 0; | |
x+= 8; // ini buat step text-nya... arah vertical... | |
yy+= ((int) stepYImage); // ini buat step byte image-nya... arah vertical.... | |
} | |
root.setTranslateX(10); | |
root.setTranslateY(10); | |
root.getChildren().add(canvas); | |
return root; | |
} | |
public static void main(String[] args){ | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment