programmering:hat1-code
var t;
var HALF_WIDTH;
var HALF_HEIGHT;
var OFFSET;
function keyPressed() {
if (key != ' ') return;
if (!fullscreen()) {
fullscreen(true);
background(0);
if (width!=displayWidth || height!=displayHeight) {
resizeCanvas(displayWidth,displayHeight);
}
HALF_WIDTH=min(width,height)/2;
HALF_HEIGHT=HALF_WIDTH;
if (width>height) OFFSET=(max(width,height)-min(width,height))/2;
t=1;
loop();
} else {
fullscreen(false);
}
}
function x1(k) {
return -sin(4*PI*k/1000);
}
function y1(k) {
return -cos(2*PI*k/1000);
}
function x2(k) {
return -0.5*sin(8*PI*k/1000);
}
function y2(k) {
return -0.5*cos(4*PI*k/1000);
}
function setup() {
createCanvas(displayWidth,displayHeight);
stroke(255);
background(0);
noCursor();
displayStartText();
}
function displayStartText() {
var start_text="Space to start/stop";
textFont("Courier");
textSize(32);
fill(255);
text(start_text,0.5*(width-textWidth(start_text)),0.5*(height-16))
}
function draw() {
if (!fullscreen) {
return;
}
if (t==999) noLoop();
translate(OFFSET+HALF_WIDTH,HALF_HEIGHT);
line(HALF_WIDTH*x1(t),-HALF_HEIGHT*y1(t),
HALF_WIDTH*x2(t),-HALF_HEIGHT*y2(t));
t++;
}
programmering/hat1-code.txt · Last modified: 2023/10/21 19:19 by 127.0.0.1