Skip to content
← Back to Community
Link Pixel Art
Profile icon
VintageMind

Hello everyone, can someone please explain to me what is the problem with the code. My mind is going bonkers now! Please help! Thx!

Answered by potatojs [earned 5 cycles]
View Answer
Voters
Profile icon
vintagemind1945
Profile icon
VintageMind
Comments
hotnewtop
Profile icon
potatojs

ok, so first of all you are using node.js, wich is a runtime envirenment for js so.. it does not have the window object or the canvas, to do the thing you want to do in your code you need first to create an html5 project (wich is what you need to create a canvas and draw on it)
then i see in your code that you are trying to use p5.js wich is a js lib so you need to link it to your project to bee able to use it.
here is the link!

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/addons/p5.sound.min.js"></script>

put those before your script in the index.html file :)

and finally, your code still have some issues like in p5 the first thing you wanna do is create a canvas using the createCanvas function in setup, something like

function setup(){ createCanvas(theWidthOfTheCanvas,theHeight) } function draw(){ //and here you draw stuff }

sorry i can't explain everything in one comment but if you want to learn it check the reference!

and if you didn't understand anything.. it's fine you just need to read the reference ;)

Profile icon
VintageMind

@potatojs
Thx a lot! Well I don't usually use JS so I can say I am a newbie at it, hahahaha! Do you mind if I share that program with you so you can make the necessary changes so I can learn from it?

Profile icon
potatojs

@Bitkoshy
yeah np lol,
ok i'm gonna send you the new version with some comments explaining the stuff :)
but if you wanna learn js i may recommend the coding train p5 series wich is a great series to get started with js and p5!

Profile icon
VintageMind

@potatojs
yup got it thx a lot!

Profile icon
potatojs

@Bitkoshy
hi can you explain what are you trying to do exactly in your code?

Profile icon
VintageMind

@potatojs
I am just trying to run the code properly

Profile icon
VintageMind

@potatojs
It should come out like this:
image

Profile icon
potatojs
Profile icon
VintageMind

@potatojs
hehehe thx.

Profile icon
potatojs

wow ok i'm gonna try


@Bitkoshy

Profile icon
VintageMind

@potatojs
thx thx thx! You can share me that repl.

Profile icon
potatojs

yeeey https://repl.it/@potatojs/p5-gg#script.js
for some reason it's not excatly how you want it lol


@Bitkoshy

Profile icon
potatojs

lol

تنزيل - 2020-09-13T110209.583


@Bitkoshy

Profile icon
potatojs
Profile icon
VintageMind

@potatojs
Not bad for a start. But since I am new were did the colour all go?

Profile icon
potatojs
Profile icon
VintageMind

@potatojs
lmao!!!

Profile icon
VintageMind

@potatojs
so exciting!

Profile icon
potatojs
Profile icon
VintageMind

@potatojs
thx solved it!

Profile icon
potatojs

wow thx i got an achivement :D


@Bitkoshy

Profile icon
VintageMind

@potatojs
Hehehe you DESERVED IT!!!!

Profile icon
potatojs

thank you! :D


@Bitkoshy