How to put a number box to set star
in
Programming Questions
•
3 years ago
Hi,
I want to set some code I found to make random stars, but I want to change it so I can control # of spikes and radius with number boxes,
but I havent understand how to accomplish this,
here is the code, Thank you:
I want to set some code I found to make random stars, but I want to change it so I can control # of spikes and radius with number boxes,
but I havent understand how to accomplish this,
here is the code, Thank you:
- // analizando programa star,
// donde llama a las classes?
Star star; //
import controlP5.*;
ControlP5 controlP5;
Textlabel myTextlabelA;
Textlabel myTextlabelB;
int a = 8;
public int numberboxValue = 10;
void setup() {
size(800,600);
//frameRate(30);
controlP5 = new ControlP5(this);
controlP5.setControlFont(new ControlFont(createFont("Georgia",20), 20));
myTextlabelA = controlP5.addTextlabel("label","ISHTAR",10,250);
myTextlabelA.setColorValue(0xffcccccc);
myTextlabelB = controlP5.addTextlabel("label","IX",20,-250);
//myTextlabelB = new Textlabel(this,"a single textlabel big stuff.",20,20,400,200);
controlP5.addNumberbox("numberboxValue",0,20,50,80,14);
smooth();
star = new Star();
}
void draw() {
//background(0);
//myTextlabelB.draw(this);
fadeToBlack();
star.draw();
}
// EMPIEXA kkkkkkkkkkkkkkkkkkkk
void fadeToBlack(){
// fade away
fill(0,0,0, 30);
noStroke();
translate(0,0); //centrar??
rect(0,0,width,height);
}
// ================================================================ separador para las clases?
class Star //class 1 notar la mayuscula,
{
// define variables, propiedades
float phase = 0;
float r1=0, r2=0;
int spikes=0;
Point[] points;
Star(){ //constructor, mismo nombre que la clase, no inizialisa pues no hay variables?
setProps(); //metodo?? cual funcion??
}
public void draw(){ //porque con nombre draw??
translate(width/2, height/2);
noStroke();
//strokeWeight(.5);
//stroke(255,255,255);
//noFill();
fill(255,255,255, 50);
// r1 = 200;
// r2 = 60;
// r1 = height * cos(phase);
//r2 = height/5 * cos(phase);
phase += .1;
//r1 = ((width/2) - mouseX) / 10;
calcPoly();
render();
if(frameCount % 60 == 0) setProps();
}
private void setProps(){
//spikes = int(random(174))+6;//getNumSpikes();
spikes = getto();
r1 = random(200)+50;
r2 = random(150);
int total = int(spikes*2);
points = new Point[ total ];
}
private void calcPoly(){
Point p;
float i=0, n = points.length;
float a = 360/n;
float cosa, sina;
for(i=0;i<n;i++){
points[int(i)] = new Point(0,0);
p = points[int(i)];
cosa = cos((a*i) * PI/180);
sina = sin((a*i) * PI/180);
if(i%2==0){
p.x = r1 * cosa;
p.y = r1 * sina;
}else{
p.x = r2 * cosa;
p.y = r2 * sina;
}
}
}
private void render(){
int i=0, n=points.length;
Point p1, p2;
pushMatrix();
beginShape(POLYGON);
// rotateY( ry );
for(i=0; i<n; i++){
if(i>0){
p1 = points[i-1];
p2 = points[i];
//line( p1.x, p1.y, p2.x, p2.y );
vertex( p1.x, p1.y );
vertex( p2.x, p2.y );
if(i==n-1) {
p1 = points[0];
//line( p1.x, p1.y, p2.x, p2.y );
}// end if
}// end if
}// end for
endShape();
popMatrix();
}
}
class Point { //class point
public float x, y; // propiedades
Point(float x, float y){ //constructor
this.x = x; // inializacion??
this.y = y;
}
}
int getto()
{
a = numberboxValue;
return a;
}