80s Basic Graphics Ported to Processing

L2-XYX2

From Graphs and Charts on the BBC Micro Computer by Robert D. Harding (Acornsoft, 1982).

/*
500 REM L2-XYX2
520 REM
530 REM --- simple x,y plot ---
540 REM first DIM £X,£Y & set values
550 DIM £X(40),£Y(40)
560 N%=40
570 FOR I%=0 TO N%: th=I%*PI/N%
580 r = SIN(5*th)
590 £X(I%)= r *COS(th)
600 £Y(I%)= r *SIN(th)
610 NEXT
620 REM --- now call PROC£XY ---
630 MODE5:PROC£XY(5,N%)
640 END
650 REM --- that's all ---
*/

int res = 100;

float lastX = 0;
float lastY = 0;

void setup(){
  size(400, 400);
  stroke(255,255,0);
  noLoop();
}

void draw(){
  background(0);
  translate(width/2, height/2);

  for(int i = 0 ; i <= res; i++){  
    float th = i * (PI/res);
    float r = sin(5 * th);

    float x = r * cos(th) * 100;
    float y = r * sin(th) * 100;

    line(lastX, lastY, x, y);

    lastX = x;
    lastY = y;
  }
}

L2-XYZ2

/*
200 REM L2-XYZ2
240 REM
250 REM  dimension arrays
260 DIM £X(60),£Y(60),£Z(60)
270 REM
280 REM calculate data
290 N=60: dt=2*PI/N
300 FOR I=0 TO N
310 t=I*dt: r=4+COS(8*t)
320 £X(I)=r*COS(t)
330 £Y(I)=r*SIN(t)
340 £Z(I)=SIN(8*t)
350 NEXT
360 REM
370 REM --- now call L2-XYZ ---
380 MODE1:PROC£XYZ(1,N)
390 t=INKEY(300): MODE1
400  REM repeat, forcing axes ranges
410 £ZL=-5:£ZH=5:PROC£AX3(0)
420 GCOL0,2:PROC£XYZ(11,N)
430 END
*/

int res = 100;
float dt = TWO_PI/res;

float lastX = -1;
float lastY;
float lastZ;

void setup(){
  size(400, 400, P3D);
  stroke(255,255,0);
  noLoop();
}

void draw(){
  background(0);

  pushMatrix();
  translate(width/2, height/2, -1000);
  rotateX(45);
  for(int i = 0 ; i <= res+1; i++){
    float t = i * dt;
    float r = 4 + cos(8 * t);
    float x = r * cos(t) * 100;
    float y = r * sin(t) * 100;
    float z = sin(8 * t) * 100;

    if(lastX != -1){
      line(lastX, lastY, lastZ, x, y, z);
    }

    lastX = x;
    lastY = y;
    lastZ = z;
  }
  popMatrix();
}

Display of Sin

From Graphics on the BBC Microcomputer by Neil Cryer, Pat Cryer and Andrew Cryer (Acornsoft 1983).


/*
10 REM Display of SIN(X)/X
20 MODE4
25 VDU19,0,4;0;19,1,3;0;
30 point=69
40 VDU29,640;200; :REM Set origin
50 FOR X=-640.1 TO 640 STEP 2
60 PLOTpoint,X,800*32*SIN(X/32)/X
70 NEXT X
80 END
*/

void setup(){
  size(400, 400);
  stroke(255,255,0);
  noLoop();
}

void draw(){
  background(0);

  translate(width/2, height/2);

  for(float x = -width/2; x < width/2 ; x+=0.5){
    point(x,(sin(x/8) * 1200.0)/x);
  }
}

Three ways of drawing a circle

From Creative Graphics on the BBC Microcomputer by John Cownie (Acornsoft, 1982).



float x;
float y;

void setup() {
  size(400, 400);
  noLoop();
  stroke(255, 255, 0);
}

void draw() {
  background(0);
  translate(width/2, height/2);

  //Iterative method
  x = width/2;
  y = height/4;

  for (int i = 0; i < 800; i++) {
    point(x/4, y/4);
    x = x + (y/8);
    y = y - (x/8);
  }

  //Polar coordinate method
  for(float i = 0 ; i < TWO_PI ; i += PI/40){
    float x = 80*sin(i);
    float y = 80*cos(i);
    point(x, y);
  }

  //Quadratic method
  float s = 100;

  for(float x = -s ; x < s ; x+=0.5){
   float y = sqrt(s * s - x * x);
   point(x, y);
   point(x, -y);
  }
}

Lissajoux Figures


float x;
float y;
float a = 0;
float f = 0.2;

void setup() {
  size(400, 400);
  stroke(255, 255, 255);
  strokeWeight(2);
  background(0);
}

void draw() {
  translate(width/2, height/2);
  a+=0.025;
  float x = 100 * sin(a);
  float y = 100 * cos(a * f);
  point(x, y);
}

Ball of Wool


int radius = 200;

float lastX = 0;
float lastY = 0;

void setup(){
 size(600, 600);
 noLoop();
 noSmooth();
}

void draw(){
  background(0);
  stroke(255);
  translate(width/2, height/2);
  for(float angle = 0 ; angle < 125.7 ; angle += 0.1 ){
    float x = radius * sin(angle);
    float y = radius * cos(angle) * sin(angle * 0.95);

    line(lastX, lastY, x, y);

    lastX = x;
    lastY = y;
  }
}