Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. import java.awt.Component;
  2. import java.awt.FontMetrics;
  3. import java.awt.Graphics;
  4.  
  5. import java.util.Random; import java.applet.Applet;
  6. import java.awt.image.*; import java.awt.*;
  7.  
  8. public final class morboy extends java.applet.Applet implements Runnable
  9. {
  10. final int GC_Count=30; final int X_Size=256,Y_Size=256;
  11. IndexColorModel PAL; byte CPal[]=new byte[256]; int XY_Size,MX,MY;
  12. int Paint_Area[]; Thread Framer; int SinX[],SinY[]; int FlowY=0;
  13. int Radial_X[], Radial_Y[]; Random rand; double Angle; int Numbo;
  14.  
  15.  
  16.  
  17. public String getAppletInfo() {
  18. return "Info?";
  19. }
  20. public void start() { Framer=new Thread(this); Framer.start(); }
  21. public void stop() { Framer.stop(); Framer=null; }
  22. public boolean imageUpdate(Image Img, int f, int x,
  23. int y, int w, int h) {return true;}
  24.  
  25.  
  26.  
  27.  
  28. public void paint(Graphics g) {
  29. g.drawImage(createImage(new MemoryImageSource(
  30. X_Size,Y_Size,PAL,Paint_Area,0,X_Size)
  31. ),0,0,X_Size,Y_Size,this);
  32. }
  33. public boolean mouseEnter(Event e, int x, int y) {
  34. IamAlive(); MX=x; MY=y; return true;}
  35. public boolean mouseExit(Event e, int x, int y) {
  36. showStatus("You have exited the Applet"); MX=MY=128; return true;}
  37. public boolean mouseMove(Event e, int x, int y) {
  38. MX=x; MY=y; return true;}
  39. public boolean mouseDown(Event e, int x, int y) {
  40. Numbo++; IamAlive(); RecalculateRadials(); return true;}
  41.  
  42.  
  43.  
  44.  
  45. public void init() { rand=new Random();
  46. for (int i=0;i<=127;i++) CPal[i]=(byte)(i*2);
  47. for (int i=128;i<=255;i++) CPal[i]=(byte)((255-i)*2);
  48. PAL=new IndexColorModel(8,256,CPal,CPal,CPal);
  49. XY_Size=X_Size*Y_Size; Paint_Area=new int[XY_Size];
  50. Radial_X=new int[XY_Size*4]; Radial_Y=new int[XY_Size*4];
  51. SinX=new int[X_Size]; SinY=new int[Y_Size];
  52. for (int i=0;i<X_Size;i++)
  53. {
  54. SinX[i]=(int)( (Math.sin(Math.PI*i*4/X_Size)+1) *63);
  55. }
  56. for (int i=0;i<Y_Size;i++)
  57. {
  58. SinY[i]=(int)( (Math.sin(Math.PI*i*2/Y_Size)+1) *127);
  59. }
  60. MX=MY=128;
  61. RecalculateAngle();
  62. Numbo=1;
  63. RecalculateRadials();
  64. }
  65.  
  66.  
  67.  
  68. public void run() {
  69. int Loop; while (true) {
  70.  
  71.  
  72. DrawPlasma1();
  73. paint(getGraphics());
  74.  
  75. System.gc();
  76.  
  77. }
  78. }
  79.  
  80.  
  81.  
  82. void RecalculateAngle() {
  83. Angle=(double)(Math.abs(rand.nextInt()) % 20)/2+0.5; // SetUp angler
  84. }
  85.  
  86. void RecalculateRadials() {
  87. double aa=(X_Size)*Angle/2/Math.PI;
  88. int x = 0,p=0, r=0;
  89.  
  90. for (int y=0; y< 256; y++)
  91. {
  92. for(x=0;x<256;x++)
  93. {
  94. r=Math.min((int)Math.sqrt(x*x+y*y),Y_Size);
  95.  
  96.  
  97.  
  98. double a= (x==0)?Math.PI/2:Math.atan((double)y/(double)x);
  99. p=(Y_Size+y)*2*X_Size+(X_Size+x); Radial_Y[p]=r;
  100. Radial_X[p]=(int)(a*aa) % X_Size; // 90 -> 0 [4]
  101. p=(Y_Size-y)*2*X_Size+(X_Size+x); Radial_Y[p]=r;
  102. Radial_X[p]=(int)((2*Math.PI-a)*aa) % X_Size; // 270 -> 360 [1]
  103. p=(Y_Size-y)*2*X_Size+(X_Size-x); Radial_Y[p]=r; // 270 -> 180 [2]
  104. Radial_X[p]=(int)((Math.PI+a)*aa) % X_Size;
  105. p=(Y_Size+y)*2*X_Size+(X_Size-x); Radial_Y[p]=r;
  106. Radial_X[p]=(int)((Math.PI-a)*aa) % X_Size; // 90 -> 180 [3]
  107. }
  108. }
  109. }
  110.  
  111. void DrawPlasma1() { int xx,yy,x,p=0,pp;
  112. pp=(~MX & 0xFF)+((~MY & 0xFF) << 9);
  113. for (x=0;x<256;x++)
  114. for (int y=0;y<256; y++)
  115. {
  116. xx=Radial_X[pp]; yy=Radial_Y[pp++];
  117. Paint_Area[p++]=SinX[(xx+SinX[(xx+SinY[y]) & 0xFF]+SinY[(yy+SinX[(xx+FlowY) & 0xFF])& 0xFF]+FlowY) & 0xFF];
  118. }pp+=0x100;
  119. }
  120. void DrawPlasma6() { int xx,yy,x,p=0,pp;
  121. pp=(~MX & 0xFF)+((~MY & 0xFF) << 9);
  122. for (x=0;x<256;x++)
  123. for (int y=0;y<256; y++)
  124. {
  125. xx=Radial_X[pp]; yy=Radial_Y[pp++];
  126. Paint_Area[p++]=SinX[(xx+SinX[(SinX[(SinX[xx]+SinY[y]+FlowY) & 0xFF]+SinY[(SinX[xx]+yy) & 0xFF]) &0xFF]+SinY[(yy+SinX[(SinX[xx]+FlowY) &0xFF]) &0xFF]+FlowY) & 0xFF];
  127. }
  128. pp+=0x100;
  129. }
  130. void DrawPlasma() { int xx,yy,x,y,p=0,pp;
  131. pp=(~MX & 0xFF)+((~MY & 0xFF) << 9);
  132. for (x=0;x<256; x++)
  133. for (y=0;y<256;y++) {
  134. xx=Radial_X[pp]; yy=Radial_Y[pp++];
  135. Paint_Area[p++]=SinY[(yy+SinY[yy & 0xFF]+SinX[(xx+SinY[(yy+FlowY) & 0xFF]) & 0xFF] +FlowY) & 0xFF];
  136. } pp+=0x100; }
  137.  
  138. void IamAlive() {
  139. showStatus("You have entered the applet");
  140. }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement