Hello everyone, I am new with the Processing language. I am trying to make processing animation with infinite zoom of image mosaic. I saw a discussion about this in the discourse processing foundation titled as “2001 A Space Odyssey” and got inspired from there to try this.
Here is a link to that discussion :
So far, I have only been able to create a program that takes about 120 dummy images and makes a mosaic of one main image and I scaled it by using the scale() function. But as the scaling gets bigger the dummy images seem to become very vague. I tried to resolve that by updating my setup function by creating a new function called update_setup() so that each time I scale up my sketch it makes the dummy images dimensions bigger proportional to the scaling value and then calls update_setup() to set everything fresh for the upcoming frame .But it was taking too long to execute so I had to terminate the program.
So ,I am asking for suggestions about this idea .
1.How can I scale up my sketch without losing the sharpness of each dummy image and then make the dummy image a mosaic of the other images?.
2.Should I make a different class which will create a mosaic image object ?
3.How to make it recursive?
Thanks in advance.
Here is my code
` 1. //the array with other images or the bulidnig blocks of the main image
* PImage[] temp=new PImage[110];
* //the main image
2. PImage mainimg,template;
3. int a=2;
4. int w,h,s;
5. float r=0,scl=0,scl1=0;
* //this array stores the average brightness of each image of the images[] array
6. float[] brightness=new float[temp.length];
7. float[] colour=new float[temp.length];
8. //this array stores the differect of brightness between each pixel of the main image and each image of the images[] array
9. float[] check=new float[brightness.length];
10. File[] files=listFiles(sketchPath("Abrar"));
11. void setup()
12. {
* size(780,900,P2D);
13. smooth();
* File[] files=listFiles(sketchPath("Abrar"));
14. //printArray(files);
15. //fullScreen();
16. w=width/a;
17. h=height/a;
18. mainimg=loadImage("20191012_114209.jpg");
19. template=createImage(w,h,RGB);
20. template.copy(mainimg,0,0,mainimg.width,mainimg.height,0,0,w,h);
* //this section loads a image in the images[] array and makes a copy of it and stores it in the temp[] array
21. //thes section also determines the average brightness/color of each image and stores the value in the brightness[] array
22. for(int i=0;i<temp.length;i++)
23. {
24. String filename=files[i].toString();
25. PImage big=loadImage(filename);
26. temp[i]=createImage(a,a,RGB);
27. temp[i].copy(big,0,0,big.width,big.height,0,0,a,a);
28. //brightness[i]=bright(temp[i]);
29. colour[i]=bright(temp[i]);
30. //println(brightness[i]);
31. }
32. }
* void draw()
33. {
34. background(0);
35. //pushMatrix();
36. translate(width/2,height/2+100);
37. scale(scl);
38. scl=scl+.1;
39. //a=a+10;
40. //update_setup(a);
41. translate(-width/2,-height/2-100);
42. //popMatrix();
* for(int y=0;y<h;y++)
43. {
44. for(int x=0;x<w;x++)
45. {
46. int index=x+y*w;
47. int indicator=0;
48. //determining the brightness of each pixel of the main image
49. //float b1=brightness(template.pixels[index]);
50. color c=template.pixels[index];
51. for(int i=0;i<brightness.length;i++)
52. {
53. //check[i]=abs(brightness[i]-b1);
54. check[i]=abs(colour[i]-c);
* }
55. //displaying the most suitable image to the pixels index in terms of brightness
56. indicator=minimum(check);
* pushMatrix();
57. translate(x*a,y*a);
* image(temp[indicator],0,0,a,a);
58. popMatrix();
* }
59. }
* }
* //determining average brightness/color of each image
60. float bright(PImage pic)
61. {
62. float b=0,c=0;
* for(int i=0;i<a;i++)
63. {
64. for(int j=0;j<a;j++)
65. {
66. int index=i+j*a;
67. //b=b+ brightness(pic.pixels[index]);
68. c=c+color(pic.pixels[index]);
69. }
70. }
71. return c/(a*a);
72. }
* //determing which temp image's average brightness is closest to the main image's that pixel's brightness
73. // or finding the most suitable image to the pixels index in terms of brightness
74. int minimum(float[] a)
75. {
76. float min=a[0];
77. int d=0;
78. for(int i=0;i<check.length;i++)
79. {
80. if(check[i]<min)
81. {
82. min=check[i];
83. d=i;
84. }
85. }
86. //println("the minimim is ",min,d);
87. return d;//dth image of the temp arry has the closest average brightness
88. }
* //saving the image as a jpg file when key 's' is pressed
89. void keyPressed()
90. {
91. if(key=='s')
92. save("new"+s+".jpg");
93. }
* ///UPDATE_SETUP
94. void update_setup(int a)
95. {
96. File[] files=listFiles(sketchPath("Abrar"));
97. //printArray(files);
98. //fullScreen();
99. w=width/a;
100. h=height/a;
101. //mainimg=loadImage("20191012_114209.jpg");
102. //template=createImage(w,h,RGB);
103. //template.copy(mainimg,0,0,mainimg.width,mainimg.height,0,0,w,h);
* //this section loads a image in the images[] array and makes a copy of it and stores it in the temp[] array
104. //thes section also determines the average brightness/color of each image and stores the value in the brightness[] array
105. for(int i=0;i<temp.length;i++)
106. {
107. String filename=files[i].toString();
108. PImage big=loadImage(filename);
109. temp[i]=createImage(a,a,RGB);
110. temp[i].copy(big,0,0,big.width,big.height,0,0,a,a);
111. //brightness[i]=bright(temp[i]);
112. colour[i]=bright(temp[i]);
113. //println(brightness[i]);
114. }
115. }
* File[] listFiles(String dir) {
116. File file = new File(dir);
117. if (file.isDirectory()) {
118. File[] files = file.listFiles();
119. return files;
120. } else {
121. // If it's not a directory
122. return null;
123. }
124. }`