Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<Drawable>d=new ArrayList<Drawable>();
- void setup(){
- size(400,400);
- }
- void draw(){
- background(128);
- for(Drawable dd:d){
- dd.draw();
- }
- }
- void mousePressed(){
- int r=(int)random(2);
- if(r==0){
- d.add(new Card1(mouseX-25,mouseY-25));//四角サイズの半分引いてます
- }
- else{
- d.add(new Card2(mouseX,mouseY));//四角サイズの半分引いてます
- }
- }
- void mouseReleased(){
- }
- interface Drawable{
- void draw();
- }
- abstract class Base{
- int x,y, num ;
- color col;
- Base(int x,int y){
- this.x=x;
- this.y=y;
- num=(int)random(10);
- col=color((int)random(200)+55,(int)random(200)+55,(int)random(200)+55);
- }
- }
- class Card1 extends Base implements Drawable{
- Card1(int x,int y){
- super(x,y);
- }
- void draw(){
- fill(col);
- rect(x,y,50,50);
- fill(0);
- text(num,x+23,y+28);
- }
- }
- class Card2 extends Base implements Drawable{
- Card2(int x,int y){
- super(x,y);
- }
- void draw(){
- fill(col);
- ellipse(x,y,50,50);
- fill(0);
- text(num,x-2,y+3);
- }
- }
Add Comment
Please, Sign In to add comment