Advertisement
MrGonao

Untitled

Apr 14th, 2016
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. float[] position = new float[4];
  2. float[] temp = new float[4];
  3. float[] c = new float[4];
  4. int i,n;
  5. color colour;
  6. float aa,bb,cc,dd,twoab,twoac,twoad;
  7. float increment = 0.01;
  8. float xmin,xmax,ymin,ymax;
  9. float xsize,ysize,incrementx,incrementy;
  10. void setup(){
  11.  
  12. position[3] = 0;
  13. position[2] = 0;
  14. size(750,750);
  15. background(255);
  16. xmin=-2;
  17. xmax=2;
  18. ymin=-2;
  19. ymax=2;
  20. xsize=abs(xmin-xmax);
  21. ysize=abs(ymin-ymax);
  22. incrementx=xsize/width;
  23. incrementy=ysize/height;
  24. textSize(20);
  25. textAlign(CENTER,CENTER);
  26.  
  27. }
  28. void draw(){
  29. julia();
  30.  
  31. text (c[0] + "\n" + c[1] +"\n" + c[2] + "\n" + c[3],375,75);
  32. move();
  33. stroke(255);
  34. line(0,375,750,375);
  35. line(375,0,375,750);
  36. }
  37.  
  38. void julia(){
  39. loadPixels();
  40.  
  41. position[1] = ymin;
  42. for (int j = 0; j < height; j ++) {
  43.  
  44. position[0] = xmin;
  45. for (int i = 0; i < width; i ++) {
  46. funtion(position);
  47.  
  48.  
  49. if (n <= 10) {
  50. colour = color(map(n,0,10,0,255),0,0);
  51. }
  52. if (10< n && n<= 20){
  53. colour = color(255,map(n,10,20,0,255),0);
  54. }
  55. if (20<n && n<=30){
  56. colour = color(map(n,20,30,255,0),255,0);
  57. }
  58. if (30 < n && n<=40){
  59. colour = color(0,255,map(n,30,40,0,255));
  60. }
  61. if ( 40 < n && n<=50){
  62. colour = color(0,map(n,40,50,255,0),255);
  63. }
  64. if ( 50<n && n<=60){
  65. colour = color(map(n,50,60,0,255),0,255);
  66. }
  67. if ( n>60){
  68. colour = color(255,map(n,60,100,0,255),255);
  69. }
  70. pixels[i+j*width] = colour;
  71.  
  72. position[0] += incrementx;
  73. }
  74. position[1]+= incrementy;
  75. }
  76. updatePixels();
  77. stroke(255);
  78.  
  79. }
  80.  
  81. int funtion(float[] a){
  82.  
  83. temp[0] = a[0];
  84. temp[1] = a[1];
  85. temp[2] = a[2];
  86. temp[3] = a[3];
  87. n = 0;
  88.  
  89. while (n < 100) {
  90. aa=temp[0]*temp[0];
  91. bb=temp[1]*temp[1];
  92. cc=temp[2]*temp[2];
  93. dd=temp[3]*temp[3];
  94. twoab=2*temp[0]*temp[1];
  95. twoac=2*temp[0]*temp[2];
  96. twoad=2*temp[0]*temp[3];
  97. temp[0] = aa - bb - cc - dd + c[0];
  98. temp[1] = twoab + c[1];
  99. temp[2] = twoac + c[2];
  100. temp[3] = twoad + c[3];
  101.  
  102. if(aa + bb + cc + dd > 16.0) {
  103. break;
  104. }
  105. n ++;
  106. }
  107. return n;
  108. }
  109.  
  110.  
  111. void move(){
  112. if (mousePressed==true){
  113. if (mouseY<50){
  114. if (mouseX<375){
  115. c[0]+=map(mouseX,0,375,0.1,0);
  116.  
  117. }
  118. if (mouseX>375){
  119. c[0]-=map(mouseX,750,375,0.1,0);;
  120. }
  121. }
  122. if (mouseY>700){
  123. if (mouseX<375){
  124. c[1]+=map(mouseX,0,375,0.1,0);;
  125. }
  126. if (mouseX>375){
  127. c[1]-=map(mouseX,750,375,0.1,0);;
  128. }
  129. }
  130. if (mouseX<50){
  131. if (mouseY<375){
  132. c[2]+=map(mouseY,0,375,0.1,0);;
  133. }
  134. if (mouseY>375){
  135. c[2]-=map(mouseY,750,375,0.1,0);;
  136. }
  137. }
  138. if (mouseX>700){
  139. if (mouseY<375){
  140. c[3]+=map(mouseY,0,375,0.1,0);;
  141. }
  142. if (mouseY>375){
  143. c[3]-=map(mouseY,750,375,0.1,0);;
  144. }
  145. }
  146. }
  147. if(keyPressed==true){
  148. if( key=='a'){
  149. position[2]+=0.01;
  150. }
  151. if (key=='d'){
  152. position[2]-=0.01;
  153. }
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement