Performance issues with color picker
in
Programming Questions
•
1 year ago
Hi!
I'm new to processing and im trying to code a simple drawing thingy. But its color picker is working very slow.
Here's the code;
- int k=0,pre_k=0,pickx,picky,picka;
- boolean k_kontrol=true;
- int ch=0,cs=0,cb=0; // secili olan renk
- int kalinlik=10;
- void setup(){
- smooth();
- colorMode(HSB,250);
- size(900,600);
- strokeWeight(2);
- line(300,0,300,600);
- ciz_renkpick(255+10,5,25,250);
- }
- void draw(){
- ciz_renkkare(5,5,250);
- renkpick_kontrol(255+10,5,25,250);
- renksec(5,5,250);
- ciz();
- //gecici
- noStroke();
- fill(ch,cs,cb);
- ellipse(600,300,100,100);
- //gecici
- }
- void ciz_renkkare(int cizx,int cizy,int a){
- colorMode(HSB,a);
- if(pre_k!=k){
- k_kontrol=true;
- }
- if(k_kontrol==true){
- for(int i=1;i<a;i++){
- for(int j=1;j<a;j++){
- stroke(k,i,a-j);
- point(i+cizx,j+cizy);
- k_kontrol=false;
- pre_k=k;
- }
- }
- }
- }
- void ciz_renkpick(int cizx,int cizy,int a,int b){
- colorMode(HSB,b);
- for(int i=1;i<a;i++){
- for(int j=1;j<b;j++){
- stroke(j,b,b);
- point(i+cizx,j+cizy);
- }
- }
- }
- void renkpick_kontrol(int cizx,int cizy,int a,int b){
- if(mousePressed==true && cizx+a>mouseX && mouseX>cizx && cizy+b>mouseY && mouseY>cizy){
- k=mouseY-cizy;
- }
- }
- void renksec(int cizx,int cizy,int a){
- int i,j;
- if(mousePressed==true && cizx+a>mouseX && mouseX>cizx && cizy+a>mouseY && mouseY>cizy){
- i=mouseX-cizx;
- j=mouseY-cizy;
- ch=k;
- cs=i;
- cb=a-j;
- }
- }
- void ciz(){
- if(mousePressed==true && 900>pmouseX && pmouseX>300 && 600>pmouseY && pmouseY>0
- && 900>mouseX && mouseX>300 && 600>mouseY && mouseY>0){
- fill(ch,cs,cb);
- stroke(ch,cs,cb);
- strokeWeight(kalinlik);
- line(pmouseX,pmouseY,mouseX,mouseY);
- }
- }
It was super-slow before i changed it a little bit. Now the square doesnt update unless the "k" variable has changed. Still its updating very slow. Can you help me out?
Also im turkish so some of the stuff is written in turkish. Here's some of the meaning of the words;
kalinlik=thickness
ciz=draw/render
kare=square
kontrol=control
renk=color
gecici=temporary
secili olan renk=current color
Thanks a lot in advance!
1