Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
wasd12
wasd12's Profile
1
Posts
3
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
how to get collatz values into a graph
[9 Replies]
27-Apr-2013 05:24 AM
Forum:
Programming Questions
first tab
final int WIDTH = 300;
final int HEIGHT = 300;
void setup() {
strokeWeight(2);
textSize(8);
//BEGIN - DO NOT CHANGE
size(WIDTH, HEIGHT);
background(0);
print(collatzValue(2));
print(", ");
print(collatzValue(6));
print(", ");
print(collatzValue(10));
print(", ");
print(collatzValue(25));
print(", ");
print(collatzValue(32));
print(", ");
print(collatzValue(42));
//END - DO NOT CHANGE
}
second tab
int partitionLength =25;
void draw() {
//XandY axis
stroke(255);
line(partitionLength, partitionLength, partitionLength, height-partitionLength); //line going down
line(partitionLength, height-partitionLength, width-partitionLength, height-partitionLength); //line going horz
//lines on the lines on X and Y axis
float partitionLength= width/12;
stroke(255, 0, 0);
//lines on the Y axis
for (int n=1;n<12;n++) {
line(partitionLength, partitionLength*n, partitionLength-6, partitionLength*n);
}
//lines on the X axis
for (int n=1;n<12;n++) {
line(partitionLength*n, height-partitionLength, partitionLength*n, height-partitionLength+6);
}
//numbers on the Y axis
int Vvalue=200;
int averageV=Vvalue/10;
int[] x1 = new int[11];
for (int i=0; i<x1.length; i++) {
x1[i] = i*averageV;
}
for (int i=0; i<x1.length; i++) {
textAlign(RIGHT);
text(x1[i], partitionLength-10, height-partitionLength*(i+1)+4);
}
//numbers on the X axis
int Hvalue=1000;
int averageH=Hvalue/10;
for (int i=0; i<x1.length; i++) {
x1[i] = i*averageH;
}
for (int i=0; i<x1.length; i++) {
textAlign(CENTER);
text(x1[i], partitionLength*(i+1), height-10);
}
}
third tab
i have collatz values of
int collatzValue(int n) {
int total = 0;
for (int i = n; i>1 ; total ++) {
if (i%2==0)
i =(1/2);
else
i = i*3+1;
}
reture total;
}
the size is also 300,300
i want it to look like the the image
«Prev
Next »
Moderate user : wasd12
Forum