Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (762)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (846)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  3D Stereogram  (Read 6216 times)
0 Members and 1 Guest are viewing this topic.
Offline Islidius

Senior Newbie


Medals: 1
Exp: 2 years



« Posted 2015-03-02 22:29:09 »

just messing around with Stereograms and realized how easy it is to do.
(if you dont know what this is here is a link:http://en.wikipedia.org/wiki/Autostereogram)

To see the hidden text focus your eyes behind the Screen. Try to move the focus nearer and wider until you can see the text.

what do you think of it? Can you imagine a game or a model preview with this method?

Here is an example:


Here is the generation code(maybe not the fastest solution):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
package pack;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

public class Main {
   
   BufferedImage img; // final Image
   BufferedImage pattern; // pattern Image
   BufferedImage depth; // depth field (inlcudes text)
   
   int standart = 140; // pattern tile width
   int tile = 100;
   
   Random r = new Random();

   public Main(){
      img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB); // init images
      depth = new BufferedImage(500,500,BufferedImage.TYPE_INT_RGB); // both need to have the same resolution
      pattern = new BufferedImage(standart,standart,BufferedImage.TYPE_INT_RGB);
     
      gen_pattern(); // generate pattern
     
      gen_background(); // store patter to background
     
      gen_foreground(); // gernerate the depth field
     
      gen_stereograph(); // apply the effect
     
      try {
         File output = new File("output.jpg"); // saving the file
         ImageIO.write(img,"jpg",output);
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
   
   public void gen_pattern(){ // a standart grayscale noise generator
      for(int i = 0;i<standart;i++){
         for(int j = 0;j<standart;j++){
            int f = r.nextInt(255);
            Color c3 = new Color(f,f,f);
            pattern.setRGB(i, j, c3.getRGB());
         }
      }
   }
   
   public void gen_background(){ // apply pattern to background but only first tile
      for(int i = 0;i<standart;i++){
         for(int j = 0;j<img.getHeight();j++){
            img.setRGB(i, j, pattern.getRGB(i%standart, j%standart));      
         }
      }
   }
   
   public void gen_foreground(){ // generate the depth field
      for(int i = 0;i<depth.getWidth();i++){
         for(int j = 0;j<depth.getHeight();j++){
            Color c1 = new Color(10,100,100);
            depth.setRGB(i, j, c1.getRGB()); // fill with background color
         }
      }
     
      Graphics2D g2d = depth.createGraphics();
      g2d.setColor(new Color(20,60,60));
      g2d.setFont(new Font("Serif",Font.BOLD,150)); // add the text
      g2d.drawString("JGO", 80, 250);
      g2d.dispose();
   }
   
   public void gen_stereograph(){ // the effect
      for(int i = 0;i<img.getWidth();i++){
         for(int j = 0;j<img.getHeight();j++){
            int de = new Color(depth.getRGB(i, j)).getRed(); // getting the depth from the depth image(stored im red component)
            if(i+tile < img.getWidth())img.setRGB(i+tile, j, img.getRGB(i, j)); // repetition of the background
            if(i+tile-de < img.getWidth())img.setRGB(i+tile-de, j, img.getRGB(i, j)); // real stereogram effect
         }
      }
     
   }
   
   public static void main(String[] args){
      new Main();
   }

}


Islidius

Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #1 - Posted 2015-03-02 22:38:58 »

cool. that works. ... incoming motion-sickness with 3d animations Smiley
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (351 views)
2018-06-10 19:43:48

EgonOlsen (352 views)
2018-06-10 19:43:44

EgonOlsen (292 views)
2018-06-10 19:43:20

DesertCoockie (526 views)
2018-05-13 18:23:11

nelsongames (843 views)
2018-04-24 18:15:36

nelsongames (830 views)
2018-04-24 18:14:32

ivj94 (1259 views)
2018-03-24 14:47:39

ivj94 (395 views)
2018-03-24 14:46:31

ivj94 (1066 views)
2018-03-24 14:43:53

Solater (413 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!