pouët.net

Go to bottom

Need programming help.

category: general [glöplog]
Job interviews certainly show how the converse is true.
added on the 2008-03-16 21:58:33 by _-_-__ _-_-__
Well, i've finished the prog, it's not perfect, but it's interesting.

I'd like to code it into something a little more stable. Or if someone is feeling brave, give me pointers on how to convert it into a more convenient language. :)
Code:int cx=150; int cy=150; int cxx; int cyy; float xl=0; float yl=0; int b=0; int c; void setup() { size(300,300,P3D); background(255); } void draw() { stroke(255,255); line (cx,cy,cxx,cyy); xl = 60*cos(b*PI/180); yl = 60*sin(b*PI/180); c=(int)(random(15)+1); b=b+c; cxx=(int)(cx+xl); cyy=(int)(cy+yl); stroke(25,96); line (cx,cy,cxx,cyy); }
added on the 2008-03-16 23:07:39 by psenough psenough
Might wanna try 60.f and 180.f up there tho.
added on the 2008-03-16 23:33:30 by Hatikvah Hatikvah
might be smoother yes :D
added on the 2008-03-17 01:06:54 by psenough psenough
640 fps ought to be enough for anyone.
added on the 2008-03-17 09:25:41 by yesso yesso
Hmmm, just messed about with the code again.... If you input big numbers, it spazzez out in a rather funky way.
how on earth does the "for" command work in java, can't seem to find anything on it. :(
If I remember my Java courses in university well, it's just like any other C-like language. So FOR i = 0 TO 100 (Basic) translates to:

for (i = 0; i < 100; i++) {
...
}
added on the 2008-03-24 19:06:17 by Alpha C Alpha C
Thanks alpha, i really appreciate that. :D
i do not remember basic, but FOR i = 0 TO 100 could very well translate teo for(i = 0; i != 100; i++ )
added on the 2008-03-24 19:51:15 by Hatikvah Hatikvah
lolz

Sorry to be a pain in the arse guys, but i'm trying to get my head around this.........

public void draw(int c){
clear();

if (c<=1) c=0;
if (c>=N-1) c=N;

Basically I was trying to program a spirograph drawing routine. What I did eventually do was way off from what it's supposed to be, I know this because I found a java version. I'd love to type it into freebasic, but i'd need to convert it myself to get the experience. Does anyone know of any good online java references to be able to convert it to freebasic? If not I could post the program and someone could go through and explain most of the commands. :)
8-bit: if so then also check here :)
added on the 2008-03-24 22:59:20 by bdk bdk
Nice stuff, but I think my brain just melted from the equasion. lolz
//David Little
//Cycloid Version 2.0
//Last Updated Oct. 7, 2000
//Compiled with JDK 1.0.2

//Bugs
//No known bugs

//Updates
//No planned updates

import java.awt.*;
import java.util.*;
import java.applet.*;

class drawCycloid extends Panel{

final int R = 33; //Radius of circle
final int P = 10+R; //Distance from outside of circle
final int shift = 10; //arbitrary shift in x-coordinate
final int N = 250; //Break up interval [0,4Pi] into N parts
final double PI = Math.PI; //3.14159
Image offImage,backImage;
Graphics offg,backg;
double[] X,dX,dY;

drawCycloid(){
super();
double theta;

X = new double[N+1];
dX = new double[N+1];
dY = new double[N+1];
for (int i=0; i<=N; i++){
theta = 4*i*PI/N;
X[i] = R+shift+R*theta;
dX[i] = R*Math.sin(theta)/2;
dY[i] = R*Math.cos(theta)/2;
}
}


public void start(){
backImage = createImage(500,190);
backg = backImage.getGraphics();
drawBackGround();

offImage = createImage(500,190);
offg = offImage.getGraphics();

clear();
draw(0);
}


public void update(Graphics g){
paint(g);
}


public void paint(Graphics g){
g.drawImage(offImage,0,0,this);
}


public void draw(int c){
clear();

if (c<=1) c=0;
if (c>=N-1) c=N;

//draw curves
for (int i=1; i<=c; i++){
offg.setColor(Color.red);
offg.drawLine((int)(X[i-1]-dX[i-1]),(int)(R+P+dY[i-1]),
(int)(X[i]-dX[i]),(int)(R+P+dY[i]));
offg.setColor(Color.green);
offg.drawLine((int)(X[i-1]-2*dX[i-1]),(int)(R+P+2*dY[i-1]),
(int)(X[i]-2*dX[i]),(int)(R+P+2*dY[i]));
offg.setColor(Color.blue);
offg.drawLine((int)(X[i-1]-3*dX[i-1]),(int)(R+P+3*dY[i-1]),
(int)(X[i]-3*dX[i]),(int)(R+P+3*dY[i]));
}

//draw circle and lines
offg.setColor(Color.black);
offg.drawOval((int)X[c]-R,P,2*R,2*R);
offg.drawLine((int)(X[c]+2*dY[c]),R+P+2*(int)(dX[c]),
(int)(X[c]-2*dY[c]),R+P-2*(int)(dX[c]));
offg.drawLine((int)(X[c]),R+P,(int)(X[c]-3*dX[c]),(int)(R+P+3*dY[c]));

repaint();
}


public void clear(){
offg.setPaintMode();
offg.setColor(Color.white);
offg.fillRect(0,0,500,200);
offg.drawImage(backImage,0,0,this);
}


public void drawBackGround(){
String str;
backg.setFont(new Font("Application",Font.PLAIN,9));

//white background
backg.setColor(Color.white);
backg.fillRect(0,0,500,200);

//draw grid
backg.setColor(new Color(200,255,255));
for (int i=-2;i<31;i++) backg.drawLine(shift+i*R/2+R,P-R,shift+i*R/2+R,3*R+P);
for (int i=-2;i<7;i++) backg.drawLine(shift,2*R+P-i*R/2,shift+14*R+R/2,2*R+P-i*R/2);

//draw axes
backg.setColor(Color.black);
backg.drawLine(shift+R,P-R,shift+R,3*R+P);
backg.drawLine(shift,2*R+P,shift+14*R+R/2,2*R+P);
for (int i=1; i<14; i++){
str = ""+i;
backg.drawString(str,shift+i*R+R-backg.getFontMetrics().stringWidth(str)/2,2*R+P+13);
backg.drawLine(shift+i*R+R,2*R+P-2,shift+i*R+R,2*R+P+2);
}
for (int i=1; i<3; i++){
str = ""+i;
backg.drawString(str,shift+R-6-backg.getFontMetrics().stringWidth(str)/2,2*R+P+4-i*R);
backg.drawLine(shift+R-2,2*R+P-i*R,shift+R+2,2*R+P-i*R);
}
}
}


public class Cycloid extends Applet{

static Scrollbar THETA;
static drawCycloid drawcycloid;

public void init(){
setBackground(Color.white);
setLayout(new BorderLayout());
drawcycloid = new drawCycloid();

THETA = new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,drawcycloid.N);

add("South",THETA);
add("Center",drawcycloid);

drawcycloid.start();
}


public void start(){
drawcycloid.draw(THETA.getValue());
}


public boolean keyDown(Event e, int key){
int n = THETA.getValue();
if (key==' '){ //spacebar
for (int i=n+1; i<=drawcycloid.N; i++){
drawcycloid.draw(i);
THETA.setValue(i);
drawcycloid.repaint();
try {
Thread.sleep(10);
} catch (InterruptedException ie){
}
}
} else if (key==1006){ //left
drawcycloid.draw(n-1);
THETA.setValue(n-1);
} else if (key==1007){ //right
drawcycloid.draw(n+1);
THETA.setValue(n+1);
}
return true;
}


public boolean handleEvent(Event e){
if (e.target instanceof Scrollbar){
if (e.target==THETA){
drawcycloid.draw(THETA.getValue());
}
return true;
}
return super.handleEvent(e);
}
}
This is the code i've found to do the spirograph thingy, but quite a bit of it I have no idea what the commands are. I've converted a fair bit to freebasic, but still some of it makes no sense. Could someone do a rough translation to freebasic commands? And not convert the program please. :)
Eeee, I'm thankfull nobody replied to the last message. I got it figured out in the end, I used the epicycloid.
didn't even need that code.

Right, for my next quessie..... The program runs as sweet as a nut, but i'm trying to figure out how to calculate how far the line has to travel before it meets the start rather than trying to guess it.
maybe explain what the hell you're doing? it's nice that you still remember, but asking a question but requiring whoever answers it to reread this whole thread (or that huge batch of code you posted, i dunno) is a bit over the top.
added on the 2008-04-02 19:30:08 by skrebbel skrebbel
Yeah, sorry about that. :)

It's the spirograph program, I have the main body running using the epicycloid equation. But if I run it, I need to calculate the loop so the line stops where it starts rather than running infinately. I've just found that it needs to be calculated with a "greatest common divisor", I can't find much documentation of it for freebasic. Hope that's enough info for ya dude. :)
Code:while(1) { fork(); }
added on the 2008-04-02 20:00:37 by xernobyl xernobyl
Yeah, thanks. :P
Quote:
Code:while(1) { fork();
Even shorter (bash):
Code::() { :|:& };:
added on the 2008-04-02 20:15:18 by Joghurt Joghurt
Do you want me to turn green? :P

login

Go to top