Questions about code that involves curveVertex

Hi guys!

I need some help here. I got a code sent to me by my teacher, so that i could “evolve” on it, but my problem is that i don’t understand the code and what the different factors and statements do??

I commented on the things that i know, but the rest i really dont know, can you help me? :slight_smile:

import processing.pdf.*;

//declaring the float and boolean
float k=0;
float s = 1;
float rate = 1;
float factor = 50; //radius of the circle
float r1 = 5.0;
float r2 = 5.0;

/*the "d" defines how much */
float d1 = 5*factor + r1;
float d2 = 8*factor + r1;
float d3 = 5*factor + r1;
float d4 = 8*factor + r1;
float d5 = 8*factor + r1;
float d6 = 8*factor + r1;

float r = 6;
float g = 0;
float b = 0;
float angle = 0.0 ;
boolean begin = false;

/*setting up the canvas (size and background color), 
stroke, framerate and that the drawing should have center in the middle */
void setup() {
  size(1200, 1200);
  background(28, 1, 73); //background color dark purple blue
  stroke(0, 150, 0, 70);
  shapeMode(CENTER); //the shape should have the center as the reference point
  beginRecord(PDF, "processing2.pdf");
  r1 = d1;
  r2 = d2;

void draw() {
  translate(mouseX, mouseY); //defining that the shape should follow the mouse
  if (r == 255) r = 10; //definition of the colors on the red scale
  if (g == 30) g = 20; //definition of the colors on the green scale
  if (b == 130) b = 70; //definition of the colors on the blue scale
  stroke(r, g, b);

/*Defining the circles and how much it should deviate from its original form*/
  curveVertex(d1*cos(PI/3), d1*sin(PI/3));
  curveVertex(d1*cos(PI/3), d1*sin(PI/3));
  curveVertex(r2*cos(PI/3+PI/6), r2*sin(PI/3+PI/6));
  curveVertex(d2*cos(2*PI/3), d2*sin(2*PI/3));
  curveVertex(r2*cos(2*PI/3+PI/6), r2*sin(2*PI/3+PI/6));
  curveVertex(d3*cos(PI), d3*sin(PI));
  curveVertex(r2*cos(PI+PI/6), r2*sin(PI+PI/6));
  curveVertex(d4*cos(4*PI/3), d4*sin(4*PI/3));
  curveVertex(r2*cos(4*PI/3+PI/6), r2*sin(4*PI/3+PI/6));
  curveVertex(d5*cos(5*PI/3), d5*sin(5*PI/3));
  curveVertex(r2*cos(5*PI/3+PI/6), r2*sin(5*PI/3+PI/6));
  curveVertex(d6*cos(2*PI), d6*sin(2*PI));
  curveVertex(r2*cos(PI/6), r2*sin(PI/6));
  curveVertex(d1*cos(PI/3), d1*sin(PI/3)); //afslutning
  curveVertex(r2*cos(PI/3+PI/6), r2*sin(PI/3+PI/6)); //afslutning
  angle += 0.005;
  if ( k == rate) {
    d1 = d1 + random(-s, s);
    d2 = d2 + random(-s, s);
    d3 = d3 + random(-s, s);
    d4 = d4 + random(-s, s);
    d5 = d5 + random(-s, s);
    d6 = d6 + random(-s, s);
    r1 = d1;
    r2 = d2;
    k = 0;


//keypress s to save as PDF
void keyPressed() { 
  if (key == 's') { //whens "s" is pressed, the PDF is saved
1 Like

ok, the code is running here and and nice,
until you use the mouse, then it is more like headache

but where is the question?
with this code you might have been given some
description what you should do with it?

I don’t know how to answer this question, because I don’t know what you don’t know.

For example, you didn’t comment “r++” – did you not understand that? Did you look up “++” in the reference?

Can you focus on something you don’t know, and ask a specific question about it? Please pick something specific, try to look it up first, then ask a question – and we would be happy to help.