Add completed challenge
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>randomDot</title>
|
||||
<script src="libraries/p5.min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="libraries/p5.dom.js" type="text/javascript"></script>
|
||||
<script src="libraries/p5.sound.js" type="text/javascript"></script>
|
||||
|
||||
<script src="sketch.js" type="text/javascript"></script>
|
||||
|
||||
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
36
CM2030 Graphics Programming/Topic 6/6.1.3 Tickle walker/libraries/p5.min.js
vendored
Normal file
36
CM2030 Graphics Programming/Topic 6/6.1.3 Tickle walker/libraries/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,42 @@
|
||||
let x;
|
||||
let y;
|
||||
let size;
|
||||
|
||||
function setup() {
|
||||
createCanvas(900, 600);
|
||||
background(0);
|
||||
x = width/2;
|
||||
y = height/2;
|
||||
size = 30;
|
||||
}
|
||||
|
||||
function draw()
|
||||
{
|
||||
background(0);
|
||||
fill(255);
|
||||
ellipse(x, y, size, size);
|
||||
if(mouseIsPressed & dist(x, y, mouseX, mouseY) < size/2)
|
||||
randomIt();
|
||||
}
|
||||
|
||||
function randomIt()
|
||||
{
|
||||
let min = 1;
|
||||
let max = 2;
|
||||
if(random(1)>0.5)
|
||||
{
|
||||
x += random(min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
x -= random(min, max);
|
||||
}
|
||||
if(random(1)>0.5)
|
||||
{
|
||||
y += random(min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
y -= random(min, max);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user