Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. PFont myFont; // this variable holds a font
  2. PGraphics myPGraphic; // the variable holds a graphic
  3. color myPGraphicTypeColor = color(0);
  4. PImage myImage;
  5.  
  6. String myText = "FUN";
  7. int myUnit = 10;
  8. // This is a list of all of the individual dots you create
  9. ArrayList<MyDotClass> myDotClassList;
  10.  
  11. float myEasingFast = 0.05;
  12.  
  13. // this runs once at the begining
  14. void setup() {
  15. size(960, 540);
  16. noStroke();
  17. colorMode(HSB);
  18. //myImage = loadImage("myGraphic.jpg");
  19.  
  20. myDotClassList = new ArrayList<MyDotClass>(); // Initialize the arraylist
  21.  
  22. myFont = createFont("SourceCodePro-Regular", 400);
  23. myPGraphic = createGraphics(width, height);
  24. myPGraphic.beginDraw();
  25. //myPGraphic.fill(0);
  26. //myPGraphic.rect(0, 0, width/2, height);
  27. //myPGraphic.fill(255);
  28. //myPGraphic.rect(width/2, 0, width/2, height);
  29. myPGraphic.textFont(myFont);
  30. myPGraphic.textAlign(CENTER, CENTER);
  31. myPGraphic.fill(myPGraphicTypeColor);
  32. myPGraphic.text(myText, width*.5, height*.5-50);
  33. myPGraphic.endDraw();
  34.  
  35.  
  36.  
  37.  
  38.  
  39. for (int y = 0; y < height; y+=myUnit) {
  40. for (int x = 0; x < width; x+=myUnit) {
  41.  
  42. color myCheckColor = myPGraphic.get(x, y);
  43. if (myCheckColor == myPGraphicTypeColor) {
  44. //ellipse(x, y, 5, 5);
  45. myDotClassList.add(new MyDotClass(x, y)); // add an instance of our class to the ArrayList
  46. }
  47. }
  48. }
  49. }
  50.  
  51. //this runs forever
  52. void draw() {
  53. fill(0, 0, 0);
  54. rect(0, 0, width, height);
  55. //image(myPGraphic, 0, 0);
  56. //image(myImage,0,0);
  57.  
  58. //int randomX = int(random(width));
  59. //int randomY = int(random(height));
  60. //color myCheckColor = myPGraphic.get(randomX, randomY);
  61. ////print(myCheckColor);
  62.  
  63. //if (myPGraphic.get(randomX, randomY) == myPGraphicTypeColor) {
  64. // fill(0, 255, 0);
  65. // ellipse(randomX, randomY, 50, 50);
  66. //} else {
  67. // fill(255, 0, 0);
  68. // ellipse(randomX, randomY, 50, 50);
  69. //}
  70.  
  71. for (MyDotClass myClassInstance : myDotClassList) {
  72. //if (!mousePressed) myClassInstance.myGoUpAndDown();
  73. //if (mousePressed) myClassInstance.myGoHome();
  74. myClassInstance.myUpdate();
  75. myClassInstance.myDisplay();
  76. }
  77. }
  78.  
  79. //void mousePressed() {
  80. //}
  81.  
  82.  
  83. class MyDotClass {
  84. float myX, myY;
  85. float myXOrigin, myYOrigin;
  86. float myXDistance, myYDistance;
  87. float mySin;
  88.  
  89. // constructor
  90. MyDotClass(float myXTemp, float myYTemp) {
  91. myXOrigin = myX = myXTemp;
  92. myYOrigin = myY = myYTemp;
  93. mySin = random(-.5, .5);
  94. }
  95.  
  96. void myUpdate() {
  97. }
  98.  
  99. void myDisplay() {
  100. //fill(255);
  101. int myHue = int(map(myY,0,height,150,0));
  102.  
  103.  
  104. fill(myHue,255,255);
  105. ellipse(myX, myY, 5, 5);
  106. }
  107.  
  108. void myGoUpAndDown() {
  109. myY+=mySin;
  110. }
  111.  
  112. void myGoHome() {
  113. myXDistance = myXOrigin - myX;
  114. myX += myXDistance * myEasingFast;
  115.  
  116. myYDistance = myYOrigin - myY;
  117. myY += myYDistance * myEasingFast;
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement