Guest User

Untitled

a guest
Apr 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. ArrayList<Drawable>d=new ArrayList<Drawable>();
  2. void setup(){
  3. size(400,400);
  4. }
  5. void draw(){
  6. background(128);
  7. for(Drawable dd:d){
  8. dd.draw();
  9. }
  10. }
  11. void mousePressed(){
  12. int r=(int)random(2);
  13. if(r==0){
  14. d.add(new Card1(mouseX-25,mouseY-25));//四角サイズの半分引いてます
  15. }
  16. else{
  17. d.add(new Card2(mouseX,mouseY));//四角サイズの半分引いてます
  18. }
  19. }
  20.  
  21. void mouseReleased(){
  22.  
  23. }
  24. interface Drawable{
  25. void draw();
  26. }
  27. abstract class Base{
  28. int x,y, num ;
  29. color col;
  30. Base(int x,int y){
  31. this.x=x;
  32. this.y=y;
  33. num=(int)random(10);
  34. col=color((int)random(200)+55,(int)random(200)+55,(int)random(200)+55);
  35. }
  36. }
  37. class Card1 extends Base implements Drawable{
  38.  
  39. Card1(int x,int y){
  40. super(x,y);
  41. }
  42. void draw(){
  43. fill(col);
  44. rect(x,y,50,50);
  45. fill(0);
  46. text(num,x+23,y+28);
  47. }
  48. }
  49. class Card2 extends Base implements Drawable{
  50.  
  51. Card2(int x,int y){
  52. super(x,y);
  53. }
  54. void draw(){
  55. fill(col);
  56. ellipse(x,y,50,50);
  57. fill(0);
  58. text(num,x-2,y+3);
  59. }
  60. }
Add Comment
Please, Sign In to add comment