프로세싱 그림판 |
|||||
---|---|---|---|---|---|
작성자 | 김린회 | 등록일 | 17.08.19 | 조회수 | 52 |
int mode=0; int sw=0, x, y, sw1=0, a=3, ms=0, ms1=0, b=0; float gs=0, x1, y1, root; void setup() { background(255); size(800, 800); } void A(){ if(mouseX>=0 && mouseX<=100 && mouseY>=0 && mouseY<=100 && mousePressed){ mode=1; } fill(0,0,0); if(mode==1){ fill(255,0,0); } strokeWeight(3); stroke(255,255,0); rect(0,0,100,100); textSize(32); fill(255, 255, 255); text("POINT", 3, 60); } void B(){ if(mouseX>=100 && mouseX<=200 && mouseY>=0 && mouseY<=100 && mousePressed){ mode=2; } fill(0,0,0); if(mode==2){ fill(255,0,0); } strokeWeight(3); stroke(255,255,0); rect(100,0,100,100); textSize(32); fill(255, 255, 255); text("LINE", 115, 60); } void C(){ if(mouseX>200 && mouseX<=300 && mouseY>=0 && mouseY<=100 && mousePressed){ fill(255,255,255); stroke(255,255,255); rect(0,100,800,700); } fill(0,0,0); strokeWeight(3); stroke(255,255,0); rect(200,0,100,100); textSize(32); fill(255, 255, 255); text("CLEAR", 203, 60); } void D(){ if(mouseX>=300 && mouseX<=400 && mouseY>=0 && mouseY<=100 && mousePressed){ mode=3; } fill(0,0,0); if(mode==3){ fill(255,0,0); } strokeWeight(3); stroke(255,255,0); rect(300,0,100,100); textSize(32); fill(255, 255, 255); text("spray", 303, 60); } void E(){ if(mouseX>=400 && mouseX<=500 && mouseY>=0 && mouseY<=100 && mousePressed){ mode=4; } fill(0,0,0); if(mode==4){ fill(255,0,0); } strokeWeight(3); stroke(255,255,0); rect(400,0,100,100); textSize(32); fill(255, 255, 255); text("rect", 415, 60); } void F(){ if(mouseX>500 && mouseX<600 && mouseY>=0 && mouseY<=100 && mousePressed){ mode=5; } fill(0,0,0); if(mode==5){ fill(255,0,0); } strokeWeight(3); stroke(255,255,0); rect(500,0,100,100); textSize(32); fill(255, 255, 255); text("circle", 500, 60); } void G(){ if(mouseX>600 && mouseX<700 && mouseY>=0 && mouseY<=100 && mousePressed && ms==0){ ms=1; } if(ms==1 && !mousePressed){ ms=0; a=a+2; if(a==21){ a=3; } } fill(0,0,0); strokeWeight(3); stroke(255,255,0); rect(600,0,100,100); textSize(32); fill(255, 255, 255); text(a, 640, 60); } void H(){ if(mouseX>700 && mouseX<800 && mouseY>=0 && mouseY<=100 && mousePressed && ms1==0){ ms1=1; } if(ms1==1 && !mousePressed){ ms1=0; ++b; } if(b==0){ fill(0,0,0); } else if(b==1){ fill(255,0,0); } else if(b==2){ fill(0,255,0); } else if(b==3){ fill(0,0,255); } else if(b==4){ fill(255,255,0); } else if(b==5){ fill(255,0,255); } else if(b==6){ fill(0,255,255); } else if(b==7){ fill(255,255,255); } else if(b==8){ b=0; } strokeWeight(3); stroke(255,255,0); rect(700,0,100,100); } void draw(){ A(); B(); C(); D(); E(); F(); G(); H(); if(b==0){ fill(0,0,0); stroke(0,0,0); } else if(b==1){ fill(255,0,0); stroke(255,0,0); } else if(b==2){ fill(0,255,0); stroke(0,255,0); } else if(b==3){ fill(0,0,255); stroke(0,0,255); } else if(b==4){ fill(255,255,0); stroke(255,255,0); } else if(b==5){ fill(255,0,255); stroke(255,0,255); } else if(b==6){ fill(0,255,255); stroke(0,255,255); } else if(b==7){ fill(255,255,255); stroke(255,255,255); } else if(b==8){ b=0; } if(key=='a'){ sw1=1; } else if(key=='s'){ sw1=0; } if(!(mouseX>=0 && mouseX<=800 && mouseY>=0 && mouseY<=100)){ if(mode==1 && mousePressed){ strokeWeight(a); line(pmouseX, pmouseY, mouseX, mouseY); } else if(mode==2 && mousePressed && sw==0){ sw=1; x=mouseX; y=mouseY; } else if(mode==2 && !mousePressed && sw==1){ sw=0; strokeWeight(a); line(x,y,mouseX,mouseY); } else if(mode==3 && mousePressed){ while(gs<=15 && mousePressed){ x1=random(-800,800); y1=random(-800,800); if(dist(mouseX,mouseY,mouseX+x1,mouseY+y1)<=a){ ++gs; strokeWeight(1); point(mouseX+x1,mouseY+y1); } } gs=0; } else if(mode==4 && mousePressed && sw==0){ sw=1; x=mouseX; y=mouseY; } else if(mode==4 && !mousePressed && sw==1&& sw1==1){ sw=0; rectMode(CORNER); root = sqrt(dist(x,y,mouseX,mouseY)*dist(x,y,mouseX,mouseY)/2); rect(x,y,root,root); } else if(mode==4 && !mousePressed && sw==1 && sw1==0){ sw=0; rectMode(CORNER); rect(x,y,mouseX-x,mouseY-y); } else if(mode==5 && mousePressed && sw==0){ sw=1; x=mouseX; y=mouseY; } else if(mode==5 && !mousePressed && sw==1 && sw1==0){ sw=0; ellipseMode(CORNER); ellipse(x,y,mouseX-x,mouseY-y); } else if(mode==5 && !mousePressed && sw==1 && sw1==1){ sw=0; ellipseMode(CORNER); if(mouseX-x>mouseY-y){ ellipse(x,y,mouseY-y,mouseY-y); } else{ ellipse(x,y,mouseX-x,mouseX-x); } } } }
|
이전글 | 사제동행 활동일 |
---|---|
다음글 | 원주율 구하기 |