How to make an array of points to replace my spiral in the same position?

edited April 2016 in Questions about Code
void setup() {
size(320, 320);
smooth();
background(255);
strokeWeight(0);   // Thicker

  drawFibonnaciTiles(500);
}

   void drawFibonnaciTiles(int iterations)
{
 int r = 2;      // red range 0 - 255
 int g = 10;     // green range 0 - 255
 int b = 25;     // blue range 0 - 255
 stroke(1, 255);
 int posx = 81;
 int posy = 125;
 int fibprev = -1;
 int fibnew = 0;
  for (int fib = 15; fib < iterations;) {   
      for (int a = 0; a < 4; a++) {
      fibnew = fib + fibprev;
  fibprev = fib;
  fib = fibnew;
       r = r + 0;
       g = g + 10;
       b = b + 1;
       fill(random(255), random(255), random(255));
       strokeWeight(1);   // Thin
   rect(posx, posy, fib, fib);
  // triangle( posx+2, posy+2, posx-2, posy+2, fibnew, posy-2);
    if (a == 0) {
      strokeWeight(2);   // Thicker
      arc(posx + fib, posy + fib, fib*2, fib*2, PI, TWO_PI-PI/2);
      posx = posx + fib;
      } else if (a == 1) {
          strokeWeight(2);   // Thicker
          arc(posx, posy + fib, fib*2, fib*2, TWO_PI-PI/2, TWO_PI);
          posx = posx - fibprev;
          posy = posy + fib;
          } else if (a == 2) {
             strokeWeight(2);   // Thicker
             arc(posx, posy, fib*2, fib*2, 0, PI/2);
             posx = posx - fib - fibprev;
             posy = posy - fibprev;
             } else if (a == 3) {
               strokeWeight(2);   // Thicker   
               arc(posx + fib, posy, fib*2, fib*2, PI/2, PI);
               posy = posy - fib - fibprev;
             }
         }
      }

  // Clock Border

rectMode(CENTER);
noFill();
strokeWeight(20);
rect(width/2, height/2, 320, 320);
// save("fibonacci_6");  // save a tif file
}

Hello guys, so this is my code, the title says everything, i want to replace my spiral with points but i don't know how to do that, please help me i m begging you.

Tagged:

Answers

  • G_DG_D
    edited April 2016

    Could try something like this (adapted from https://timwolverson.wordpress.com/2014/02/08/plot-a-fibonacci-spiral-in-excel/)

    float a = 0.01;
    float b = 0.00534679805621781608330843237138;
    
    for(int index=0; index <2000; index+=5){
    float x=a*cos(radians(index))*exp(b*index);
    float y=a*sin(radians(index))*exp(b*index);
    x*=50; //scaling
    y*=50;
    point(x+width/2,y+height/2);
    }
    
  • And in your other post you were asking about how to save those points into an array. It may just be easiest to use x/y coordinates into a PVector and save into an arraylist - see https://forum.processing.org/one/topic/how-to-use-arraylist.html. Or just read up on some of the tutorials and examples at processing.org (appreciate you are new to this, but if you are serious about actually learning processing, you'll do better in the long run if you start looking at examples and trying to make things, rather than asking others to solve all your problems).

  • Sorry if my actions seemed like that, but its the opposite, i created a new post because what i said i wasn't very explicite and you said something that it was exactly what i wanted but i said it wrong, so i created a new post, i m serious about processing and i just couldn't figure it out so i' m sorry about my actions but it really wasn't my intention. And thank you

  • edited April 2016
    float hora, min, seg;
    int dia, mes, ano;
    
    float [] x, y;
    
    void setup() {
    
      size(320, 320);
    
      x = new float [60];
      y = new float [60];
      calcCoordSpiral();
    
      smooth();
    }
    
    void draw() {
    
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(88.1, 147.2, 14.2, 14.2);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(88.1, 133.1, 14.2, 14.2);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(110, 140.3, 28.4, 28.4);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(103, 176.2, 42.6, 42.6);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(45.5, 161.5, 71, 71);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(67.5, 69.2, 113.6, 113.6);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(217.2, 105, 184.6, 184.6);
      popMatrix();
    
      pushMatrix();
      translate(0, -1);
      stroke(0);
      strokeWeight(1);
      fill(255);
      rect(160, 347, 298.2, 298.2);
      popMatrix(); 
    
      texto(); 
      time(); // Draws the time
    
      fill (0, 255, 0, 150);
      rect (x[int(hora)], y[int(hora)], 24, 24);
    
      fill (0, 0, 255, 150);
      rect (x[int(min)], y[int(min)], 16, 16);
    
      fill (255, 0, 0, 150);
      rect (x[int(seg)], y[int(seg)], 8, 8);
    
    
    
       // numeros relógio digital
       fill (0);
       textSize(25);
       text (nf(int(hora), 2) + ":" + 
        nf(int(min), 2) + ":" + 
        nf(int(seg), 2), width/2-20, height/2);
    
      // Dia, Mês e Ano
    
      pushMatrix();
      translate(-16, 20);
      String s = String.valueOf(dia);
      textSize(12);
      text(s, width/2, height/2);
      s = String.valueOf(mes);
      text(s, width/2+20, height/2); 
      s = String.valueOf(ano);
      text(s, width/2+40, height/2);
    
       popMatrix();
    
       // Clock Border
    
       rectMode(CENTER);
       noFill();
       stroke(0);
       strokeWeight(20);
       rect(width/2, height/2, 320, 320);
    }
    
    void time () {  // Void for the time
    
      seg = second();
      min = minute();
      hora = hour(); 
      if (hora>24) hora-=24;
    
      dia = day();
      mes = month();
      ano = year();
    
    
       noStroke();
       //stroke(255, 0, 0); // retirar o stroke para não aparecer os pontos
      for (int i=0; i<60; i++) 
       {
        point (x[i], y[i]);
      }
    }
    
    void calcCoordSpiral()
    {
      int SpiralCenterX = width/2;
      int SpiralCenterY = height/2;
      float SpiralWidth = width/2-20; // largura igual a metade do ecrã menos 20 pixels de rebordo
    
      float angule = 0;
      int i = 0;
    
          for (float radians = SpiralWidth; radians >= 0.5; radians-=1.16) // calcula exactamente 120 pontos, os radianos têm de ser radianos >= 0.5 para os circulos não desaparecerem aos 56.
      {
            float posDotSpiralX = SpiralCenterX + cos(angule) * -radians;
            float posDotSpiralY = SpiralCenterY + sin(angule) * -radians;
    
        angule += radians(6);
    
    if (int (radians) < SpiralWidth && int (radians) % 2 == 0) {
    
      x[i] = posDotSpiralX;
      y[i] = posDotSpiralY;
    
      i++;
    }
    

    } }

    this is the code that i made till far, without asking anything, searched a theory that i really liked about Fibonacci and made a watchface based on that theory.

  • Hopefully wasn't being rude. Just trying to say that sometimes you learn more with a bit of reading and trial and error, rather than just getting a complete answer. Looks like you are making good progress. if you wanted to see the spiral, you could add something like:

    void drawSpiral() {
      beginShape();
      curveVertex(x[0], y[0]); // the first control point
      curveVertex(x[0], y[0]); // is also the start point of curve
      for (int i=1; i<59; i++) {
        stroke(0);
        strokeWeight(1);
        curveVertex(x[i], y[i]);
      }
      curveVertex(x[59], y[59]); // last control point
      curveVertex(x[59], y[59]); // is also the end point of curve
      endShape();
    }
    
Sign In or Register to comment.