project 0 by paul shen
implemented in oF
GDE Error: Unable to load profile settings
void testApp::drawNollSinusoids() { float amplitude = 30.0; float phase = PI; output.setColor(0x333333); output.setLineWidth(1.0); output.noFill(); for (int i = 0; i < 90; i++) { float period = 30 / PI; float offsetY = 15 + i * 5.8; output.beginShape(); for (int x = 0; x < windowWidth; x++) { float y = sin(x / period + phase); output.curveVertex(x, amplitude * y + amplitude + offsetY); period += 0.031; } output.endShape(); } } |
pong
link [ iframe code is removed on update ]
implemented in processing.js
int paddleWidth = 100; int ballSize = 20; // all the following deal with center of object int compPos, userPos; int ballX, ballY, ballDX, ballDY; float multiplier = 1.0; // speed up ball void setup() { size(400,400); frameRate(30); noStroke(); resetGame(); } void resetGame() { multiplier = 1.0; compPos = (height - paddleWidth) / 2; userPos = compPos; ballX = (width - ballSize) / 2; ballY = (height - ballSize) / 2; ballDX = 0; ballDY = 0; } void draw() { background(#333333); fill(#f0f0f0); // update ball position ballX += ballDX * multiplier; ballY += ballDY * multiplier; multiplier += 0.003; // check for collision // computer side if (ballX - ballSize / 2 < 10) { if (abs(ballY - compPos) width - 10) { if (abs(ballY - userPos) <= paddleWidth / 2) { ballDX = -ballDX; ballX = height - 10 - ballSize / 2; ballDY += (ballY - userPos) / 5; } else { resetGame(); } } // top if (ballY - ballSize / 2 height) { ballDY = -ballDY; ballY = height - ballSize / 2; } // update user position userPos = mouseY; if (userPos height - paddleWidth / 2) userPos = height - paddleWidth / 2; // update computer position float compDY = (ballY - compPos); if (compDY > 10) compDY = 10; compPos += compDY; if (compPos height - paddleWidth / 2) compPos = height - paddleWidth / 2; // draw computer paddle rect(0, compPos - paddleWidth / 2, 10, paddleWidth); // draw user paddle rect(width - 10, userPos - paddleWidth / 2, 10, paddleWidth); // draw ball ellipse(ballX, ballY, ballSize, ballSize); } void mousePressed() { if (ballDX == 0 && ballDY == 0) { ballDX = 5; ballDY = 2; } } |
Comments Off on project 0 by paul shen